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-type.h | |
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-type.h')
-rw-r--r-- | src/wasm-type.h | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/wasm-type.h b/src/wasm-type.h index 53ef39ef8..668ac3e4d 100644 --- a/src/wasm-type.h +++ b/src/wasm-type.h @@ -36,7 +36,9 @@ public: f32, f64, v128, + funcref, anyref, + nullref, exnref, _last_value_type, }; @@ -64,7 +66,8 @@ public: bool isInteger() const { return id == i32 || id == i64; } bool isFloat() const { return id == f32 || id == f64; } bool isVector() const { return id == v128; }; - bool isRef() const { return id == anyref || id == exnref; } + bool isNumber() const { return id >= i32 && id <= v128; } + bool isRef() const { return id >= funcref && id <= exnref; } // (In)equality must be defined for both Type and ValueType because it is // otherwise ambiguous whether to convert both this and other to int or @@ -94,6 +97,23 @@ public: // type. static Type get(unsigned byteSize, bool float_); + // Returns true if left is a subtype of right. Subtype includes itself. + static bool isSubType(Type left, Type right); + + // Computes the least upper bound from the type lattice. + // If one of the type is unreachable, the other type becomes the result. If + // the common supertype does not exist, returns none, a poison value. + static Type getLeastUpperBound(Type a, Type b); + + // Computes the least upper bound for all types in the given list. + template<typename T> static Type mergeTypes(const T& types) { + Type type = Type::unreachable; + for (auto other : types) { + type = Type::getLeastUpperBound(type, other); + } + return type; + } + std::string toString() const; }; @@ -134,7 +154,9 @@ constexpr Type i64 = Type::i64; constexpr Type f32 = Type::f32; constexpr Type f64 = Type::f64; constexpr Type v128 = Type::v128; +constexpr Type funcref = Type::funcref; constexpr Type anyref = Type::anyref; +constexpr Type nullref = Type::nullref; constexpr Type exnref = Type::exnref; constexpr Type unreachable = Type::unreachable; |