summaryrefslogtreecommitdiff
path: root/src/wasm/wasm-s-parser.cpp
diff options
context:
space:
mode:
authorThomas Lively <tlively@google.com>2023-01-06 15:47:19 -0600
committerGitHub <noreply@github.com>2023-01-06 13:47:19 -0800
commitf719c3527512377657f72f16ee4ac5581843614f (patch)
treeb082f8d5e80bb53a9d69e7c8197f6b7ada2939b6 /src/wasm/wasm-s-parser.cpp
parent73a1cfcacd028ed7aefe304c2e140cda4068dcb0 (diff)
downloadbinaryen-f719c3527512377657f72f16ee4ac5581843614f.tar.gz
binaryen-f719c3527512377657f72f16ee4ac5581843614f.tar.bz2
binaryen-f719c3527512377657f72f16ee4ac5581843614f.zip
Consolidate br_on* operations (#5399)
The `br_on{_non}_{data,i31,func}` operations are deprecated and directly representable in terms of the new `br_on_cast` and `br_on_cast_fail` instructions, so remove their dedicated IR opcodes in favor of representing them as casts. `br_on_null` and `br_on_non_null` cannot be consolidated the same way because their behavior is not directly representable in terms of `br_on_cast` and `br_on_cast_fail`; when the cast to null bottom type succeeds, the null check instructions implicitly drop the null value whereas the cast instructions would propagate it. Add special logic to the binary writer and printer to continue emitting the deprecated instructions for now. This will allow us to update the test suite in a separate future PR with no additional functional changes. Some tests are updated because the validator no longer allows passing non-func data to `br_on_func`. Doing so has not made sense since we separated the three reference type hierarchies.
Diffstat (limited to 'src/wasm/wasm-s-parser.cpp')
-rw-r--r--src/wasm/wasm-s-parser.cpp18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/wasm/wasm-s-parser.cpp b/src/wasm/wasm-s-parser.cpp
index fd3cbcc23..638dfbebf 100644
--- a/src/wasm/wasm-s-parser.cpp
+++ b/src/wasm/wasm-s-parser.cpp
@@ -2818,11 +2818,20 @@ Expression* SExpressionWasmBuilder::makeRefCastNop(Element& s) {
return Builder(wasm).makeRefCast(ref, type, RefCast::Unsafe);
}
-Expression* SExpressionWasmBuilder::makeBrOn(Element& s, BrOnOp op) {
+Expression* SExpressionWasmBuilder::makeBrOnNull(Element& s, bool onFail) {
int i = 1;
auto name = getLabel(*s[i++]);
- Type castType = Type::none;
- if (op == BrOnCast || op == BrOnCastFail) {
+ auto* ref = parseExpression(*s[i]);
+ auto op = onFail ? BrOnNonNull : BrOnNull;
+ return Builder(wasm).makeBrOn(op, name, ref);
+}
+
+Expression* SExpressionWasmBuilder::makeBrOnCast(Element& s,
+ std::optional<Type> castType,
+ bool onFail) {
+ int i = 1;
+ auto name = getLabel(*s[i++]);
+ if (!castType) {
auto nullability = NonNullable;
if (s[i]->str().str == "null") {
nullability = Nullable;
@@ -2832,7 +2841,8 @@ Expression* SExpressionWasmBuilder::makeBrOn(Element& s, BrOnOp op) {
castType = Type(type, nullability);
}
auto* ref = parseExpression(*s[i]);
- return Builder(wasm).makeBrOn(op, name, ref, castType);
+ auto op = onFail ? BrOnCastFail : BrOnCast;
+ return Builder(wasm).makeBrOn(op, name, ref, *castType);
}
Expression* SExpressionWasmBuilder::makeStructNew(Element& s, bool default_) {