summaryrefslogtreecommitdiff
path: root/src/wasm/wasm-s-parser.cpp
diff options
context:
space:
mode:
authorThomas Lively <tlively@google.com>2022-12-07 16:06:53 -0600
committerGitHub <noreply@github.com>2022-12-07 14:06:53 -0800
commitc79548b93a81ccf7609413da1345a7570c51b9ba (patch)
tree7783fbf6610383fb76fe312fe3c125860428b779 /src/wasm/wasm-s-parser.cpp
parent5a8d09bfe725f321b022187e294991db3ffaa417 (diff)
downloadbinaryen-c79548b93a81ccf7609413da1345a7570c51b9ba.tar.gz
binaryen-c79548b93a81ccf7609413da1345a7570c51b9ba.tar.bz2
binaryen-c79548b93a81ccf7609413da1345a7570c51b9ba.zip
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.
Diffstat (limited to 'src/wasm/wasm-s-parser.cpp')
-rw-r--r--src/wasm/wasm-s-parser.cpp39
1 files changed, 20 insertions, 19 deletions
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;