diff options
Diffstat (limited to 'src/wasm')
-rw-r--r-- | src/wasm/wasm-binary.cpp | 14 | ||||
-rw-r--r-- | src/wasm/wasm-s-parser.cpp | 5 | ||||
-rw-r--r-- | src/wasm/wasm-stack.cpp | 4 | ||||
-rw-r--r-- | src/wasm/wasm.cpp | 8 |
4 files changed, 31 insertions, 0 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index 429ff7bae..5aa5948fe 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -3930,6 +3930,9 @@ BinaryConsts::ASTNodes WasmBinaryBuilder::readExpression(Expression*& curr) { if (maybeVisitStringEncode(curr, opcode)) { break; } + if (maybeVisitStringConcat(curr, opcode)) { + break; + } if (opcode == BinaryConsts::RefIsFunc || opcode == BinaryConsts::RefIsData || opcode == BinaryConsts::RefIsI31) { @@ -7220,6 +7223,17 @@ bool WasmBinaryBuilder::maybeVisitStringEncode(Expression*& out, return true; } +bool WasmBinaryBuilder::maybeVisitStringConcat(Expression*& out, + uint32_t code) { + if (code != BinaryConsts::StringConcat) { + return false; + } + auto* right = popNonVoidExpression(); + auto* left = popNonVoidExpression(); + out = Builder(wasm).makeStringConcat(left, right); + return true; +} + void WasmBinaryBuilder::visitRefAs(RefAs* curr, uint8_t code) { BYN_TRACE("zz node: RefAs\n"); switch (code) { diff --git a/src/wasm/wasm-s-parser.cpp b/src/wasm/wasm-s-parser.cpp index 68bd69104..fe52864d8 100644 --- a/src/wasm/wasm-s-parser.cpp +++ b/src/wasm/wasm-s-parser.cpp @@ -2990,6 +2990,11 @@ Expression* SExpressionWasmBuilder::makeStringEncode(Element& s, op, parseExpression(s[i]), parseExpression(s[i + 1])); } +Expression* SExpressionWasmBuilder::makeStringConcat(Element& s) { + return Builder(wasm).makeStringConcat(parseExpression(s[1]), + parseExpression(s[2])); +} + // converts an s-expression string representing binary data into an output // sequence of raw bytes this appends to data, which may already contain // content. diff --git a/src/wasm/wasm-stack.cpp b/src/wasm/wasm-stack.cpp index 38c8f1661..6596cccc7 100644 --- a/src/wasm/wasm-stack.cpp +++ b/src/wasm/wasm-stack.cpp @@ -2300,6 +2300,10 @@ void BinaryInstWriter::visitStringEncode(StringEncode* curr) { } } +void BinaryInstWriter::visitStringConcat(StringConcat* curr) { + o << int8_t(BinaryConsts::GCPrefix) << U32LEB(BinaryConsts::StringConcat); +} + void BinaryInstWriter::emitScopeEnd(Expression* curr) { assert(!breakStack.empty()); breakStack.pop_back(); diff --git a/src/wasm/wasm.cpp b/src/wasm/wasm.cpp index d4337a87d..d3b1c2151 100644 --- a/src/wasm/wasm.cpp +++ b/src/wasm/wasm.cpp @@ -1200,6 +1200,14 @@ void StringEncode::finalize() { } } +void StringConcat::finalize() { + if (left->type == Type::unreachable || right->type == Type::unreachable) { + type = Type::unreachable; + } else { + type = Type(HeapType::string, NonNullable); + } +} + size_t Function::getNumParams() { return getParams().size(); } size_t Function::getNumVars() { return vars.size(); } |