From c79548b93a81ccf7609413da1345a7570c51b9ba Mon Sep 17 00:00:00 2001 From: Thomas Lively Date: Wed, 7 Dec 2022 16:06:53 -0600 Subject: Add standard versions of WasmGC casts (#5331) We previously supported only the non-standard cast instructions introduced when we were experimenting with nominal types. Parse the names and opcodes of their standard counterparts and switch to emitting the standard names and opcodes. Port all of the tests to use the standard instructions, but add additional tests showing that the non-standard versions are still parsed correctly. --- src/wasm/wasm-s-parser.cpp | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) (limited to 'src/wasm/wasm-s-parser.cpp') diff --git a/src/wasm/wasm-s-parser.cpp b/src/wasm/wasm-s-parser.cpp index 7bdbc69c6..ee9fdde72 100644 --- a/src/wasm/wasm-s-parser.cpp +++ b/src/wasm/wasm-s-parser.cpp @@ -2775,40 +2775,42 @@ Expression* SExpressionWasmBuilder::makeI31Get(Element& s, bool signed_) { return ret; } -Expression* SExpressionWasmBuilder::makeRefTestStatic(Element& s) { +Expression* SExpressionWasmBuilder::makeRefTest(Element& s) { auto heapType = parseHeapType(*s[1]); auto* ref = parseExpression(*s[2]); return Builder(wasm).makeRefTest(ref, heapType); } -Expression* SExpressionWasmBuilder::makeRefCastStatic(Element& s) { - auto heapType = parseHeapType(*s[1]); - auto* ref = parseExpression(*s[2]); +Expression* SExpressionWasmBuilder::makeRefCast(Element& s) { + int i = 1; + if (s[0]->str().str != "ref.cast_static") { + if (s[i++]->str().str != "null") { + throw ParseException("ref.cast not yet supported. Use ref.cast null."); + } + } + auto heapType = parseHeapType(*s[i++]); + auto* ref = parseExpression(*s[i++]); return Builder(wasm).makeRefCast(ref, heapType, RefCast::Safe); } -Expression* SExpressionWasmBuilder::makeRefCastNopStatic(Element& s) { +Expression* SExpressionWasmBuilder::makeRefCastNop(Element& s) { auto heapType = parseHeapType(*s[1]); auto* ref = parseExpression(*s[2]); return Builder(wasm).makeRefCast(ref, heapType, RefCast::Unsafe); } Expression* SExpressionWasmBuilder::makeBrOn(Element& s, BrOnOp op) { - auto name = getLabel(*s[1]); - auto* ref = parseExpression(*s[2]); - return ValidatingBuilder(wasm, s.line, s.col) - .validateAndMakeBrOn(op, name, ref); -} - -Expression* SExpressionWasmBuilder::makeBrOnStatic(Element& s, BrOnOp op) { - auto name = getLabel(*s[1]); - auto heapType = parseHeapType(*s[2]); - auto* ref = parseExpression(*s[3]); + int i = 1; + auto name = getLabel(*s[i++]); + HeapType heapType; + if (op == BrOnCast || op == BrOnCastFail) { + heapType = parseHeapType(*s[i++]); + } + auto* ref = parseExpression(*s[i]); return Builder(wasm).makeBrOn(op, name, ref, heapType); } -Expression* SExpressionWasmBuilder::makeStructNewStatic(Element& s, - bool default_) { +Expression* SExpressionWasmBuilder::makeStructNew(Element& s, bool default_) { auto heapType = parseHeapType(*s[1]); auto numOperands = s.size() - 2; if (default_ && numOperands > 0) { @@ -2865,8 +2867,7 @@ Expression* SExpressionWasmBuilder::makeStructSet(Element& s) { return Builder(wasm).makeStructSet(index, ref, value); } -Expression* SExpressionWasmBuilder::makeArrayNewStatic(Element& s, - bool default_) { +Expression* SExpressionWasmBuilder::makeArrayNew(Element& s, bool default_) { auto heapType = parseHeapType(*s[1]); Expression* init = nullptr; size_t i = 2; -- cgit v1.2.3