diff options
Diffstat (limited to 'src/wasm')
-rw-r--r-- | src/wasm/wasm-ir-builder.cpp | 11 | ||||
-rw-r--r-- | src/wasm/wasm-s-parser.cpp | 4 |
2 files changed, 11 insertions, 4 deletions
diff --git a/src/wasm/wasm-ir-builder.cpp b/src/wasm/wasm-ir-builder.cpp index 43a989c6e..e8a2a2386 100644 --- a/src/wasm/wasm-ir-builder.cpp +++ b/src/wasm/wasm-ir-builder.cpp @@ -430,6 +430,11 @@ Result<Expression*> IRBuilder::getBranchValue(Name labelName, } Result<> IRBuilder::visitBreak(Break* curr, std::optional<Index> label) { + if (curr->condition) { + auto cond = pop(); + CHECK_ERR(cond); + curr->condition = *cond; + } auto value = getBranchValue(curr->name, label); CHECK_ERR(value); curr->value = *value; @@ -961,13 +966,15 @@ Result<> IRBuilder::makeLoop(Name label, Type type) { return visitLoopStart(loop); } -Result<> IRBuilder::makeBreak(Index label) { +Result<> IRBuilder::makeBreak(Index label, bool isConditional) { auto name = getLabelName(label); CHECK_ERR(name); Break curr; curr.name = *name; + // Use a dummy condition value if we need to pop a condition. + curr.condition = isConditional ? &curr : nullptr; CHECK_ERR(visitBreak(&curr, label)); - push(builder.makeBreak(curr.name, curr.value)); + push(builder.makeBreak(curr.name, curr.value, curr.condition)); return Ok{}; } diff --git a/src/wasm/wasm-s-parser.cpp b/src/wasm/wasm-s-parser.cpp index 9270a19b0..9dbfc88c2 100644 --- a/src/wasm/wasm-s-parser.cpp +++ b/src/wasm/wasm-s-parser.cpp @@ -2580,7 +2580,7 @@ Name SExpressionWasmBuilder::getLabel(Element& s, LabelType labelType) { } } -Expression* SExpressionWasmBuilder::makeBreak(Element& s) { +Expression* SExpressionWasmBuilder::makeBreak(Element& s, bool isConditional) { auto ret = allocator.alloc<Break>(); size_t i = 1; ret->name = getLabel(*s[i]); @@ -2588,7 +2588,7 @@ Expression* SExpressionWasmBuilder::makeBreak(Element& s) { if (i == s.size()) { return ret; } - if (elementStartsWith(s, BR_IF)) { + if (isConditional) { if (i + 1 < s.size()) { ret->value = parseExpression(s[i]); i++; |