diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/literal.h | 8 | ||||
-rw-r--r-- | src/wasm-interpreter.h | 8 | ||||
-rw-r--r-- | src/wasm-type.h | 2 | ||||
-rw-r--r-- | src/wasm/literal.cpp | 12 | ||||
-rw-r--r-- | src/wasm/wasm-type.cpp | 34 |
5 files changed, 43 insertions, 21 deletions
diff --git a/src/literal.h b/src/literal.h index e49946814..06719cd32 100644 --- a/src/literal.h +++ b/src/literal.h @@ -97,14 +97,17 @@ public: Literal& operator=(const Literal& other); ~Literal(); - bool isConcrete() const { return type != Type::none; } + bool isConcrete() const { return type.isConcrete(); } bool isNone() const { return type == Type::none; } + bool isFunction() const { return type.isFunction(); } + bool isData() const { return type.isData(); } + bool isNull() const { if (type.isNullable()) { if (type.isFunction()) { return func.isNull(); } - if (isGCData()) { + if (isData()) { return !gcData; } return true; @@ -171,7 +174,6 @@ public: WASM_UNREACHABLE("unexpected type"); } } - bool isGCData() const { return type.isStruct() || type.isArray(); } static Literals makeZeros(Type type); static Literals makeOnes(Type type); diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h index ac64a30c0..c01b56ec7 100644 --- a/src/wasm-interpreter.h +++ b/src/wasm-interpreter.h @@ -1320,7 +1320,7 @@ public: case RefIsFunc: return Literal(!value.isNull() && value.type.isFunction()); case RefIsData: - return Literal(!value.isNull() && value.isGCData()); + return Literal(!value.isNull() && value.isData()); case RefIsI31: return Literal(!value.isNull() && value.type.getHeapType() == HeapType::i31); @@ -1429,7 +1429,7 @@ public: // anyref of null (already handled above) or anything else (handled here, // but this is for future use as atm the binaryen interpreter cannot // represent external references). - if (!cast.originalRef.isGCData()) { + if (!cast.originalRef.isData()) { cast.outcome = cast.Failure; return cast; } @@ -1509,7 +1509,7 @@ public: } break; case BrOnData: - if (!value.isGCData()) { + if (!value.isData()) { return {value}; } break; @@ -1699,7 +1699,7 @@ public: } break; case RefAsData: - if (value.isGCData()) { + if (value.isData()) { trap("not a data"); } break; diff --git a/src/wasm-type.h b/src/wasm-type.h index bf3dd69de..f5c2fb273 100644 --- a/src/wasm-type.h +++ b/src/wasm-type.h @@ -136,6 +136,7 @@ public: bool isSingle() const { return isConcrete() && !isTuple(); } bool isRef() const; bool isFunction() const; + bool isData() const; bool isException() const; bool isNullable() const; bool isRtt() const; @@ -314,6 +315,7 @@ public: constexpr bool isBasic() const { return id <= _last_basic_type; } constexpr bool isCompound() const { return id > _last_basic_type; } bool isFunction() const; + bool isData() const; bool isSignature() const; bool isStruct() const; bool isArray() const; diff --git a/src/wasm/literal.cpp b/src/wasm/literal.cpp index dc6d90ef9..54e817189 100644 --- a/src/wasm/literal.cpp +++ b/src/wasm/literal.cpp @@ -35,7 +35,7 @@ Literal::Literal(Type type) : type(type) { i32 = 0; } else { assert(type != Type::unreachable && (!type.isRef() || type.isNullable())); - if (isGCData()) { + if (isData()) { new (&gcData) std::shared_ptr<GCData>(); } else if (type.isRtt()) { // Allocate a new RttSupers (with no data). @@ -55,7 +55,7 @@ Literal::Literal(std::shared_ptr<GCData> gcData, Type type) // Null data is only allowed if nullable. assert(gcData || type.isNullable()); // The type must be a proper type for GC data. - assert(isGCData()); + assert(isData()); } Literal::Literal(std::unique_ptr<RttSupers>&& rttSupers, Type type) @@ -64,7 +64,7 @@ Literal::Literal(std::unique_ptr<RttSupers>&& rttSupers, Type type) } Literal::Literal(const Literal& other) : type(other.type) { - if (other.isGCData()) { + if (other.isData()) { new (&gcData) std::shared_ptr<GCData>(other.gcData); return; } @@ -121,7 +121,7 @@ Literal::Literal(const Literal& other) : type(other.type) { } Literal::~Literal() { - if (isGCData()) { + if (isData()) { gcData.~shared_ptr(); } else if (type.isRtt()) { rttSupers.~unique_ptr(); @@ -241,7 +241,7 @@ std::array<uint8_t, 16> Literal::getv128() const { } std::shared_ptr<GCData> Literal::getGCData() const { - assert(isGCData()); + assert(isData()); return gcData; } @@ -486,7 +486,7 @@ std::ostream& operator<<(std::ostream& o, Literal literal) { o << "funcref(" << literal.getFunc() << ")"; } } else if (literal.type.isRef()) { - if (literal.isGCData()) { + if (literal.isData()) { auto data = literal.getGCData(); if (data) { o << "[ref " << data->rtt << ' ' << data->values << ']'; diff --git a/src/wasm/wasm-type.cpp b/src/wasm/wasm-type.cpp index b433c050c..11f6cfbaf 100644 --- a/src/wasm/wasm-type.cpp +++ b/src/wasm/wasm-type.cpp @@ -90,6 +90,7 @@ struct HeapTypeInfo { constexpr bool isSignature() const { return kind == SignatureKind; } constexpr bool isStruct() const { return kind == StructKind; } constexpr bool isArray() const { return kind == ArrayKind; } + constexpr bool isData() const { return isStruct() || isArray(); } HeapTypeInfo& operator=(const HeapTypeInfo& other); bool operator==(const HeapTypeInfo& other) const; @@ -384,6 +385,15 @@ bool Type::isFunction() const { } } +bool Type::isData() const { + if (isBasic()) { + return id == dataref; + } else { + auto* info = getTypeInfo(*this); + return info->isRef() && info->ref.heapType.isData(); + } +} + bool Type::isNullable() const { if (isBasic()) { return id >= funcref && id <= eqref; // except i31ref @@ -737,6 +747,14 @@ bool HeapType::isFunction() const { } } +bool HeapType::isData() const { + if (isBasic()) { + return id == data; + } else { + return getHeapTypeInfo(*this)->isData(); + } +} + bool HeapType::isSignature() const { if (isBasic()) { return false; @@ -753,6 +771,14 @@ bool HeapType::isStruct() const { } } +bool HeapType::isArray() const { + if (isBasic()) { + return false; + } else { + return getHeapTypeInfo(*this)->isArray(); + } +} + bool HeapType::operator<(const HeapType& other) const { if (*this == other) { return false; @@ -769,14 +795,6 @@ bool HeapType::operator<(const HeapType& other) const { return *getHeapTypeInfo(*this) < *getHeapTypeInfo(other); } -bool HeapType::isArray() const { - if (isBasic()) { - return false; - } else { - return getHeapTypeInfo(*this)->isArray(); - } -} - Signature HeapType::getSignature() const { assert(isSignature()); return getHeapTypeInfo(*this)->signature; |