summaryrefslogtreecommitdiff
path: root/src/wasm-ir-builder.h
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-ir-builder.h
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-ir-builder.h')
-rw-r--r--src/wasm-ir-builder.h19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/wasm-ir-builder.h b/src/wasm-ir-builder.h
index 50c034897..1a19f62e8 100644
--- a/src/wasm-ir-builder.h
+++ b/src/wasm-ir-builder.h
@@ -45,15 +45,13 @@ public:
[[nodiscard]] Result<Expression*> build();
// Call visit() on an existing Expression with its non-child fields
- // initialized to initialize the child fields and refinalize it. The specific
- // visitors are internal implementation details.
+ // initialized to initialize the child fields and refinalize it.
[[nodiscard]] Result<> visit(Expression*);
- [[nodiscard]] Result<> visitExpression(Expression*);
- [[nodiscard]] Result<> visitBlock(Block*);
- [[nodiscard]] Result<> visitReturn(Return*);
- [[nodiscard]] Result<> visitStructNew(StructNew*);
- [[nodiscard]] Result<> visitArrayNew(ArrayNew*);
+ // Handle the boundaries of control flow structures. Users may choose to use
+ // the corresponding `makeXYZ` function below instead of `visitXYZStart`, but
+ // either way must call `visitEnd` and friends at the appropriate times.
+ [[nodiscard]] Result<> visitBlockStart(Block* block);
[[nodiscard]] Result<> visitEnd();
// Alternatively, call makeXYZ to have the IRBuilder allocate the nodes. This
@@ -171,6 +169,13 @@ public:
void setFunction(Function* func) { this->func = func; }
+ // Private functions that must be public for technical reasons.
+ [[nodiscard]] Result<> visitExpression(Expression*);
+ [[nodiscard]] Result<> visitBlock(Block*);
+ [[nodiscard]] Result<> visitReturn(Return*);
+ [[nodiscard]] Result<> visitStructNew(StructNew*);
+ [[nodiscard]] Result<> visitArrayNew(ArrayNew*);
+
private:
Module& wasm;
Function* func;