summaryrefslogtreecommitdiff
path: root/src/wasm-type.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/wasm-type.h')
-rw-r--r--src/wasm-type.h24
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;