diff options
Diffstat (limited to 'src/wasm')
-rw-r--r-- | src/wasm/wasm-binary.cpp | 20 | ||||
-rw-r--r-- | src/wasm/wasm-s-parser.cpp | 60 | ||||
-rw-r--r-- | src/wasm/wasm-stack.cpp | 17 | ||||
-rw-r--r-- | src/wasm/wasm.cpp | 2 | ||||
-rw-r--r-- | src/wasm/wat-parser.cpp | 5 |
5 files changed, 69 insertions, 35 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index 65734e68d..cd5763c12 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -7184,7 +7184,13 @@ bool WasmBinaryBuilder::maybeVisitStringNew(Expression*& out, uint32_t code) { Expression* length = nullptr; Expression* start = nullptr; Expression* end = nullptr; - if (code == BinaryConsts::StringNewWTF8) { + bool try_ = false; + if (code == BinaryConsts::StringNewWTF8 || + code == BinaryConsts::StringNewUTF8Try) { + if (code == BinaryConsts::StringNewUTF8Try) { + try_ = true; + } + // FIXME: the memory index should be an LEB like all other places if (getInt8() != 0) { throwError("Unexpected nonzero memory index"); } @@ -7209,7 +7215,11 @@ bool WasmBinaryBuilder::maybeVisitStringNew(Expression*& out, uint32_t code) { } op = StringNewWTF16; length = popNonVoidExpression(); - } else if (code == BinaryConsts::StringNewWTF8Array) { + } else if (code == BinaryConsts::StringNewWTF8Array || + code == BinaryConsts::StringNewUTF8ArrayTry) { + if (code == BinaryConsts::StringNewUTF8ArrayTry) { + try_ = true; + } auto policy = getU32LEB(); switch (policy) { case BinaryConsts::StringPolicy::UTF8: @@ -7230,14 +7240,16 @@ bool WasmBinaryBuilder::maybeVisitStringNew(Expression*& out, uint32_t code) { op = StringNewWTF16Array; end = popNonVoidExpression(); start = popNonVoidExpression(); + } else if (code == BinaryConsts::StringFromCodePoint) { + op = StringNewFromCodePoint; } else { return false; } auto* ptr = popNonVoidExpression(); if (length) { - out = Builder(wasm).makeStringNew(op, ptr, length); + out = Builder(wasm).makeStringNew(op, ptr, length, try_); } else { - out = Builder(wasm).makeStringNew(op, ptr, start, end); + out = Builder(wasm).makeStringNew(op, ptr, start, end, try_); } return true; } diff --git a/src/wasm/wasm-s-parser.cpp b/src/wasm/wasm-s-parser.cpp index 829025a2c..6bbd82476 100644 --- a/src/wasm/wasm-s-parser.cpp +++ b/src/wasm/wasm-s-parser.cpp @@ -2990,43 +2990,53 @@ Expression* SExpressionWasmBuilder::makeRefAs(Element& s, RefAsOp op) { return Builder(wasm).makeRefAs(op, value); } -Expression* SExpressionWasmBuilder::makeStringNew(Element& s, StringNewOp op) { +Expression* +SExpressionWasmBuilder::makeStringNew(Element& s, StringNewOp op, bool try_) { size_t i = 1; Expression* length = nullptr; - if (op == StringNewWTF8) { - std::string_view str = s[i++]->str().str; - if (str == "utf8") { - op = StringNewUTF8; - } else if (str == "wtf8") { - op = StringNewWTF8; - } else if (str == "replace") { - op = StringNewReplace; - } else { - throw ParseException("bad string.new op", s.line, s.col); + if (op == StringNewWTF8 || op == StringNewUTF8) { + if (!try_) { + std::string_view str = s[i++]->str().str; + if (str == "utf8") { + op = StringNewUTF8; + } else if (str == "wtf8") { + op = StringNewWTF8; + } else if (str == "replace") { + op = StringNewReplace; + } else { + throw ParseException("bad string.new op", s.line, s.col); + } } length = parseExpression(s[i + 1]); - return Builder(wasm).makeStringNew(op, parseExpression(s[i]), length); + return Builder(wasm).makeStringNew(op, parseExpression(s[i]), length, try_); } else if (op == StringNewWTF16) { length = parseExpression(s[i + 1]); - return Builder(wasm).makeStringNew(op, parseExpression(s[i]), length); - } else if (op == StringNewWTF8Array) { - std::string_view str = s[i++]->str().str; - if (str == "utf8") { - op = StringNewUTF8Array; - } else if (str == "wtf8") { - op = StringNewWTF8Array; - } else if (str == "replace") { - op = StringNewReplaceArray; - } else { - throw ParseException("bad string.new op", s.line, s.col); + return Builder(wasm).makeStringNew(op, parseExpression(s[i]), length, try_); + } else if (op == StringNewWTF8Array || op == StringNewUTF8Array) { + if (!try_) { + std::string_view str = s[i++]->str().str; + if (str == "utf8") { + op = StringNewUTF8Array; + } else if (str == "wtf8") { + op = StringNewWTF8Array; + } else if (str == "replace") { + op = StringNewReplaceArray; + } else { + throw ParseException("bad string.new op", s.line, s.col); + } } auto* start = parseExpression(s[i + 1]); auto* end = parseExpression(s[i + 2]); - return Builder(wasm).makeStringNew(op, parseExpression(s[i]), start, end); + return Builder(wasm).makeStringNew( + op, parseExpression(s[i]), start, end, try_); } else if (op == StringNewWTF16Array) { auto* start = parseExpression(s[i + 1]); auto* end = parseExpression(s[i + 2]); - return Builder(wasm).makeStringNew(op, parseExpression(s[i]), start, end); + return Builder(wasm).makeStringNew( + op, parseExpression(s[i]), start, end, try_); + } else if (op == StringNewFromCodePoint) { + return Builder(wasm).makeStringNew( + op, parseExpression(s[i]), nullptr, try_); } else { throw ParseException("bad string.new op", s.line, s.col); } diff --git a/src/wasm/wasm-stack.cpp b/src/wasm/wasm-stack.cpp index 1f5722b59..694ed4269 100644 --- a/src/wasm/wasm-stack.cpp +++ b/src/wasm/wasm-stack.cpp @@ -2264,7 +2264,11 @@ void BinaryInstWriter::visitStringNew(StringNew* curr) { o << int8_t(BinaryConsts::GCPrefix); switch (curr->op) { case StringNewUTF8: - o << U32LEB(BinaryConsts::StringNewWTF8); + if (!curr->try_) { + o << U32LEB(BinaryConsts::StringNewWTF8); + } else { + o << U32LEB(BinaryConsts::StringNewUTF8Try); + } o << int8_t(0); // Memory index. o << U32LEB(BinaryConsts::StringPolicy::UTF8); break; @@ -2283,8 +2287,12 @@ void BinaryInstWriter::visitStringNew(StringNew* curr) { o << int8_t(0); // Memory index. break; case StringNewUTF8Array: - o << U32LEB(BinaryConsts::StringNewWTF8Array) - << U32LEB(BinaryConsts::StringPolicy::UTF8); + if (!curr->try_) { + o << U32LEB(BinaryConsts::StringNewWTF8Array); + } else { + o << U32LEB(BinaryConsts::StringNewUTF8ArrayTry); + } + o << U32LEB(BinaryConsts::StringPolicy::UTF8); break; case StringNewWTF8Array: o << U32LEB(BinaryConsts::StringNewWTF8Array) @@ -2297,6 +2305,9 @@ void BinaryInstWriter::visitStringNew(StringNew* curr) { case StringNewWTF16Array: o << U32LEB(BinaryConsts::StringNewWTF16Array); break; + case StringNewFromCodePoint: + o << U32LEB(BinaryConsts::StringFromCodePoint); + break; default: WASM_UNREACHABLE("invalid string.new*"); } diff --git a/src/wasm/wasm.cpp b/src/wasm/wasm.cpp index fa1351541..f58aaf0da 100644 --- a/src/wasm/wasm.cpp +++ b/src/wasm/wasm.cpp @@ -1134,7 +1134,7 @@ void StringNew::finalize() { (length && length->type == Type::unreachable)) { type = Type::unreachable; } else { - type = Type(HeapType::string, NonNullable); + type = Type(HeapType::string, try_ ? Nullable : NonNullable); } } diff --git a/src/wasm/wat-parser.cpp b/src/wasm/wat-parser.cpp index dfc2190f3..1408ffe0d 100644 --- a/src/wasm/wat-parser.cpp +++ b/src/wasm/wat-parser.cpp @@ -2374,7 +2374,8 @@ template<typename Ctx> Result<typename Ctx::InstrT> makeArrayCopy(Ctx&, Index); template<typename Ctx> Result<typename Ctx::InstrT> makeRefAs(Ctx&, Index, RefAsOp op); template<typename Ctx> -Result<typename Ctx::InstrT> makeStringNew(Ctx&, Index, StringNewOp op); +Result<typename Ctx::InstrT> +makeStringNew(Ctx&, Index, StringNewOp op, bool try_); template<typename Ctx> Result<typename Ctx::InstrT> makeStringConst(Ctx&, Index); template<typename Ctx> @@ -3563,7 +3564,7 @@ Result<typename Ctx::InstrT> makeRefAs(Ctx& ctx, Index pos, RefAsOp op) { template<typename Ctx> Result<typename Ctx::InstrT> -makeStringNew(Ctx& ctx, Index pos, StringNewOp op) { +makeStringNew(Ctx& ctx, Index pos, StringNewOp op, bool try_) { return ctx.in.err("unimplemented instruction"); } |