summaryrefslogtreecommitdiff
path: root/src/wasm
diff options
context:
space:
mode:
authorThomas Lively <tlively@google.com>2023-09-18 18:40:00 -0700
committerGitHub <noreply@github.com>2023-09-19 01:40:00 +0000
commit8c5bb9b8a0b150ebab0d0dec545206b055de9564 (patch)
tree9851b38ef65a1634f451697638728d6e36bd714a /src/wasm
parent452e50747ed397fe17c69dd428387b949feaa05d (diff)
downloadbinaryen-8c5bb9b8a0b150ebab0d0dec545206b055de9564.tar.gz
binaryen-8c5bb9b8a0b150ebab0d0dec545206b055de9564.tar.bz2
binaryen-8c5bb9b8a0b150ebab0d0dec545206b055de9564.zip
Fix visitBlock and add visitBlockStart in IRBuilder (#5959)
Visiting a block should push it onto the stack just like visiting any other expression, but we previously had a `visitBlock` that introduced a new scope instead. Fix `visitBlock` to behave as expected and introduce a new `visitBlockStart` method to introduce a new scope. Unfortunately this cannot be fully tested yet because the wat parser uses the `makeXYZ` API intead of the `visit` API, but at least I updated `makeBlock` to call `visitBlockStart`, so that is tested.
Diffstat (limited to 'src/wasm')
-rw-r--r--src/wasm/wasm-ir-builder.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/wasm/wasm-ir-builder.cpp b/src/wasm/wasm-ir-builder.cpp
index 6445cc3c9..bc3180423 100644
--- a/src/wasm/wasm-ir-builder.cpp
+++ b/src/wasm/wasm-ir-builder.cpp
@@ -233,7 +233,7 @@ Result<> IRBuilder::visitExpression(Expression* curr) {
}
Result<> IRBuilder::visitBlock(Block* curr) {
- scopeStack.push_back({{}, curr});
+ // No children; pushing and finalizing will be handled by `visit`.
return Ok{};
}
@@ -281,6 +281,11 @@ Result<> IRBuilder::visitArrayNew(ArrayNew* curr) {
return Ok{};
}
+Result<> IRBuilder::visitBlockStart(Block* curr) {
+ scopeStack.push_back({{}, curr});
+ return Ok{};
+}
+
Result<> IRBuilder::visitEnd() {
if (scopeStack.empty() || !scopeStack.back().block) {
return Err{"unexpected end"};
@@ -347,7 +352,7 @@ Result<> IRBuilder::makeBlock(Name label, Type type) {
auto* block = wasm.allocator.alloc<Block>();
block->name = label;
block->type = type;
- scopeStack.push_back({{}, block});
+ CHECK_ERR(visitBlockStart(block));
return Ok{};
}