From 6299471584ce74d365526e33ed0a662bd2ee3490 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Thu, 28 Jan 2021 22:09:31 +0000 Subject: [GC] Add br_on_func/data/i31 (#3525) This expands the existing BrOnCast into BrOn that can also handle the func/data/i31 variants. This is not as elegant as RefIs / RefAs in that BrOnCast has an extra rtt field, but I think it is still the best option. We already have optional fields on Break (the value and condition), so making rtt optional is not odd. And it allows us to share all the behavior of br_on_* which aside from the cast or the check itself, is identical - returning the value if the branch is not taken, etc. --- src/wasm/wasm-s-parser.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 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 9cf2f3be9..3075f70d7 100644 --- a/src/wasm/wasm-s-parser.cpp +++ b/src/wasm/wasm-s-parser.cpp @@ -2130,18 +2130,21 @@ Expression* SExpressionWasmBuilder::makeRefCast(Element& s) { return Builder(wasm).makeRefCast(ref, rtt); } -Expression* SExpressionWasmBuilder::makeBrOnCast(Element& s) { +Expression* SExpressionWasmBuilder::makeBrOn(Element& s, BrOnOp op) { auto name = getLabel(*s[1]); auto* ref = parseExpression(*s[2]); - auto* rtt = parseExpression(*s[3]); + Expression* rtt = nullptr; Builder builder(wasm); - if (rtt->type == Type::unreachable) { - // An unreachable rtt is not supported: the text format does not provide the - // type, so if it's unreachable we should not even create a br_on_cast in - // such a case, as we'd have no idea what it casts to. - return builder.makeSequence(builder.makeDrop(ref), rtt); + if (op == BrOnCast) { + rtt = parseExpression(*s[3]); + if (rtt->type == Type::unreachable) { + // An unreachable rtt is not supported: the text format does not provide + // the type, so if it's unreachable we should not even create a br_on_cast + // in such a case, as we'd have no idea what it casts to. + return builder.makeSequence(builder.makeDrop(ref), rtt); + } } - return builder.makeBrOnCast(name, ref, rtt); + return builder.makeBrOn(op, name, ref, rtt); } Expression* SExpressionWasmBuilder::makeRttCanon(Element& s) { -- cgit v1.2.3