diff options
Diffstat (limited to 'src/wasm')
-rw-r--r-- | src/wasm/literal.cpp | 18 | ||||
-rw-r--r-- | src/wasm/wasm-type.cpp | 13 |
2 files changed, 26 insertions, 5 deletions
diff --git a/src/wasm/literal.cpp b/src/wasm/literal.cpp index 34f3d250d..80ff47b17 100644 --- a/src/wasm/literal.cpp +++ b/src/wasm/literal.cpp @@ -71,7 +71,8 @@ Literal::Literal(const uint8_t init[16]) : type(Type::v128) { Literal::Literal(std::shared_ptr<GCData> gcData, HeapType type) : gcData(gcData), type(type, NonNullable) { - // The type must be a proper type for GC data. + // The type must be a proper type for GC data: either a struct, array, or + // string; or a null. assert((isData() && gcData) || (type.isBottom() && !gcData)); } @@ -577,7 +578,20 @@ std::ostream& operator<<(std::ostream& o, Literal literal) { case HeapType::struct_: case HeapType::array: WASM_UNREACHABLE("invalid type"); - case HeapType::string: + case HeapType::string: { + auto data = literal.getGCData(); + if (!data) { + o << "nullstring"; + } else { + o << "string(\""; + for (auto c : data->values) { + // TODO: more than ascii + o << char(c.getInteger()); + } + o << "\")"; + } + break; + } case HeapType::stringview_wtf8: case HeapType::stringview_wtf16: case HeapType::stringview_iter: diff --git a/src/wasm/wasm-type.cpp b/src/wasm/wasm-type.cpp index 2c26f0e21..cebb1b489 100644 --- a/src/wasm/wasm-type.cpp +++ b/src/wasm/wasm-type.cpp @@ -897,7 +897,8 @@ bool Type::isFunction() const { bool Type::isData() const { if (isBasic()) { - return false; + // The only basic type that is considered data is a string. + return isString(); } else { auto* info = getTypeInfo(*this); return info->isRef() && info->ref.heapType.isData(); @@ -924,6 +925,8 @@ bool Type::isStruct() const { return isRef() && getHeapType().isStruct(); } bool Type::isArray() const { return isRef() && getHeapType().isArray(); } +bool Type::isString() const { return isRef() && getHeapType().isString(); } + bool Type::isDefaultable() const { // A variable can get a default value if its type is concrete (unreachable // and none have no values, hence no default), and if it's a reference, it @@ -1267,7 +1270,7 @@ bool HeapType::isFunction() const { bool HeapType::isData() const { if (isBasic()) { - return id == struct_ || id == array; + return id == struct_ || id == array || id == string; } else { return getHeapTypeInfo(*this)->isData(); } @@ -1297,6 +1300,8 @@ bool HeapType::isArray() const { } } +bool HeapType::isString() const { return *this == HeapType::string; } + bool HeapType::isBottom() const { if (isBasic()) { switch (getBasic()) { @@ -1672,7 +1677,9 @@ bool SubTyper::isSubType(HeapType a, HeapType b) { case HeapType::any: return a.getBottom() == HeapType::none; case HeapType::eq: - return a == HeapType::i31 || a == HeapType::none || a.isData(); + return a == HeapType::i31 || a == HeapType::none || + a == HeapType::struct_ || a == HeapType::array || a.isStruct() || + a.isArray(); case HeapType::i31: return a == HeapType::none; case HeapType::struct_: |