diff options
Diffstat (limited to 'src/wasm')
-rw-r--r-- | src/wasm/literal.cpp | 12 | ||||
-rw-r--r-- | src/wasm/wasm-type.cpp | 34 |
2 files changed, 32 insertions, 14 deletions
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; |