diff options
author | Heejin Ahn <aheejin@gmail.com> | 2019-12-30 17:55:20 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-12-30 17:55:20 -0800 |
commit | bcc76146fed433cbc8ba01a9f568d979c145110b (patch) | |
tree | ab70ad24afc257b73513c3e62f3aab9938d05944 /src/wasm/literal.cpp | |
parent | a30f1df5696ccb3490e2eaa3a9ed5e7e487c7b0e (diff) | |
download | binaryen-bcc76146fed433cbc8ba01a9f568d979c145110b.tar.gz binaryen-bcc76146fed433cbc8ba01a9f568d979c145110b.tar.bz2 binaryen-bcc76146fed433cbc8ba01a9f568d979c145110b.zip |
Add support for reference types proposal (#2451)
This adds support for the reference type proposal. This includes support
for all reference types (`anyref`, `funcref`(=`anyfunc`), and `nullref`)
and four new instructions: `ref.null`, `ref.is_null`, `ref.func`, and
new typed `select`. This also adds subtype relationship support between
reference types.
This does not include table instructions yet. This also does not include
wasm2js support.
Fixes #2444 and fixes #2447.
Diffstat (limited to 'src/wasm/literal.cpp')
-rw-r--r-- | src/wasm/literal.cpp | 45 |
1 files changed, 40 insertions, 5 deletions
diff --git a/src/wasm/literal.cpp b/src/wasm/literal.cpp index 82a150257..4f66b36e3 100644 --- a/src/wasm/literal.cpp +++ b/src/wasm/literal.cpp @@ -137,8 +137,11 @@ void Literal::getBits(uint8_t (&buf)[16]) const { case Type::v128: memcpy(buf, &v128, sizeof(v128)); break; - case Type::anyref: // anyref type is opaque - case Type::exnref: // exnref type is opaque + case Type::funcref: + case Type::nullref: + break; + case Type::anyref: + case Type::exnref: case Type::none: case Type::unreachable: WASM_UNREACHABLE("invalid type"); @@ -146,10 +149,20 @@ void Literal::getBits(uint8_t (&buf)[16]) const { } bool Literal::operator==(const Literal& other) const { + if (type.isRef() && other.type.isRef()) { + if (type == Type::nullref && other.type == Type::nullref) { + return true; + } + if (type == Type::funcref && other.type == Type::funcref && + func == other.func) { + return true; + } + return false; + } if (type != other.type) { return false; } - if (type == none) { + if (type == Type::none) { return true; } uint8_t bits[16], other_bits[16]; @@ -273,8 +286,14 @@ std::ostream& operator<<(std::ostream& o, Literal literal) { o << "i32x4 "; literal.printVec128(o, literal.getv128()); break; - case Type::anyref: // anyref type is opaque - case Type::exnref: // exnref type is opaque + case Type::funcref: + o << "funcref(" << literal.getFunc() << ")"; + break; + case Type::nullref: + o << "nullref"; + break; + case Type::anyref: + case Type::exnref: case Type::unreachable: WASM_UNREACHABLE("invalid type"); } @@ -477,7 +496,9 @@ Literal Literal::eqz() const { case Type::f64: return eq(Literal(double(0))); case Type::v128: + case Type::funcref: case Type::anyref: + case Type::nullref: case Type::exnref: case Type::none: case Type::unreachable: @@ -497,7 +518,9 @@ Literal Literal::neg() const { case Type::f64: return Literal(int64_t(i64 ^ 0x8000000000000000ULL)).castToF64(); case Type::v128: + case Type::funcref: case Type::anyref: + case Type::nullref: case Type::exnref: case Type::none: case Type::unreachable: @@ -517,7 +540,9 @@ Literal Literal::abs() const { case Type::f64: return Literal(int64_t(i64 & 0x7fffffffffffffffULL)).castToF64(); case Type::v128: + case Type::funcref: case Type::anyref: + case Type::nullref: case Type::exnref: case Type::none: case Type::unreachable: @@ -620,7 +645,9 @@ Literal Literal::add(const Literal& other) const { case Type::f64: return Literal(getf64() + other.getf64()); case Type::v128: + case Type::funcref: case Type::anyref: + case Type::nullref: case Type::exnref: case Type::none: case Type::unreachable: @@ -640,7 +667,9 @@ Literal Literal::sub(const Literal& other) const { case Type::f64: return Literal(getf64() - other.getf64()); case Type::v128: + case Type::funcref: case Type::anyref: + case Type::nullref: case Type::exnref: case Type::none: case Type::unreachable: @@ -731,7 +760,9 @@ Literal Literal::mul(const Literal& other) const { case Type::f64: return Literal(getf64() * other.getf64()); case Type::v128: + case Type::funcref: case Type::anyref: + case Type::nullref: case Type::exnref: case Type::none: case Type::unreachable: @@ -967,7 +998,9 @@ Literal Literal::eq(const Literal& other) const { case Type::f64: return Literal(getf64() == other.getf64()); case Type::v128: + case Type::funcref: case Type::anyref: + case Type::nullref: case Type::exnref: case Type::none: case Type::unreachable: @@ -987,7 +1020,9 @@ Literal Literal::ne(const Literal& other) const { case Type::f64: return Literal(getf64() != other.getf64()); case Type::v128: + case Type::funcref: case Type::anyref: + case Type::nullref: case Type::exnref: case Type::none: case Type::unreachable: |