diff options
Diffstat (limited to 'src/wasm/wasm-binary.cpp')
-rw-r--r-- | src/wasm/wasm-binary.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index d81aa0ca4..429ff7bae 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -3927,6 +3927,9 @@ BinaryConsts::ASTNodes WasmBinaryBuilder::readExpression(Expression*& curr) { if (maybeVisitStringMeasure(curr, opcode)) { break; } + if (maybeVisitStringEncode(curr, opcode)) { + break; + } if (opcode == BinaryConsts::RefIsFunc || opcode == BinaryConsts::RefIsData || opcode == BinaryConsts::RefIsI31) { @@ -7190,6 +7193,33 @@ bool WasmBinaryBuilder::maybeVisitStringMeasure(Expression*& out, return true; } +bool WasmBinaryBuilder::maybeVisitStringEncode(Expression*& out, + uint32_t code) { + StringEncodeOp op; + // TODO: share this code with string.measure? + if (code == BinaryConsts::StringEncodeWTF8) { + auto policy = getU32LEB(); + switch (policy) { + case BinaryConsts::StringPolicy::UTF8: + op = StringEncodeUTF8; + break; + case BinaryConsts::StringPolicy::WTF8: + op = StringEncodeWTF8; + break; + default: + throwError("bad policy for string.encode"); + } + } else if (code == BinaryConsts::StringEncodeWTF16) { + op = StringEncodeWTF16; + } else { + return false; + } + auto* ptr = popNonVoidExpression(); + auto* ref = popNonVoidExpression(); + out = Builder(wasm).makeStringEncode(op, ref, ptr); + return true; +} + void WasmBinaryBuilder::visitRefAs(RefAs* curr, uint8_t code) { BYN_TRACE("zz node: RefAs\n"); switch (code) { |