diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ir/properties.h | 2 | ||||
-rw-r--r-- | src/literal.h | 1 | ||||
-rw-r--r-- | src/wasm-interpreter.h | 7 | ||||
-rw-r--r-- | src/wasm/literal.cpp | 10 |
4 files changed, 14 insertions, 6 deletions
diff --git a/src/ir/properties.h b/src/ir/properties.h index d47ee55a8..fb0065948 100644 --- a/src/ir/properties.h +++ b/src/ir/properties.h @@ -116,6 +116,8 @@ inline Literal getLiteral(const Expression* curr) { if (auto* c = i->value->dynCast<Const>()) { return Literal::makeI31(c->value.geti32()); } + } else if (auto* s = curr->dynCast<StringConst>()) { + return Literal(s->string.toString()); } WASM_UNREACHABLE("non-constant expression"); } diff --git a/src/literal.h b/src/literal.h index 5e449c576..317839b72 100644 --- a/src/literal.h +++ b/src/literal.h @@ -85,6 +85,7 @@ public: assert(type.isSignature()); } explicit Literal(std::shared_ptr<GCData> gcData, HeapType type); + explicit Literal(std::string string); Literal(const Literal& other); Literal& operator=(const Literal& other); ~Literal(); diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h index 851c4013c..87b0e0c67 100644 --- a/src/wasm-interpreter.h +++ b/src/wasm-interpreter.h @@ -1838,12 +1838,7 @@ public: } } Flow visitStringConst(StringConst* curr) { - Literals contents; - for (size_t i = 0; i < curr->string.size(); i++) { - contents.push_back(Literal(int32_t(curr->string[i]))); - } - auto heapType = curr->type.getHeapType(); - return Literal(std::make_shared<GCData>(heapType, contents), heapType); + return Literal(curr->string.toString()); } Flow visitStringMeasure(StringMeasure* curr) { WASM_UNREACHABLE("unimp"); } Flow visitStringEncode(StringEncode* curr) { WASM_UNREACHABLE("unimp"); } diff --git a/src/wasm/literal.cpp b/src/wasm/literal.cpp index 80ff47b17..016df2e18 100644 --- a/src/wasm/literal.cpp +++ b/src/wasm/literal.cpp @@ -76,6 +76,16 @@ Literal::Literal(std::shared_ptr<GCData> gcData, HeapType type) assert((isData() && gcData) || (type.isBottom() && !gcData)); } +Literal::Literal(std::string string) + : gcData(nullptr), type(Type(HeapType::string, NonNullable)) { + // TODO: we could in theory internalize strings + Literals contents; + for (auto c : string) { + contents.push_back(Literal(int32_t(c))); + } + gcData = std::make_shared<GCData>(HeapType::string, contents); +} + Literal::Literal(const Literal& other) : type(other.type) { if (type.isBasic()) { switch (type.getBasic()) { |