summaryrefslogtreecommitdiff
path: root/src/wasm-builder.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/wasm-builder.h')
-rw-r--r--src/wasm-builder.h15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/wasm-builder.h b/src/wasm-builder.h
index 336a90e0d..6e342771b 100644
--- a/src/wasm-builder.h
+++ b/src/wasm-builder.h
@@ -65,7 +65,14 @@ public:
}
// Nop TODO: add all the rest
- // Block
+ Block* makeBlock(Expression* first = nullptr) {
+ auto* ret = allocator.alloc<Block>();
+ if (first) {
+ ret->list.push_back(first);
+ ret->finalize();
+ }
+ return ret;
+ }
If* makeIf(Expression* condition, Expression* ifTrue, Expression* ifFalse=nullptr) {
auto* ret = allocator.alloc<If>();
ret->condition = condition; ret->ifTrue = ifTrue; ret->ifFalse = ifFalse;
@@ -192,6 +199,12 @@ public:
func->localNames.clear();
func->localIndices.clear();
}
+
+ // ensure a node is a block, if it isn't already
+ Block* blockify(Expression* any) {
+ if (any->is<Block>()) return any->cast<Block>();
+ return makeBlock(any);
+ }
};
} // namespace wasm