summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2016-04-21 18:36:22 -0700
committerAlon Zakai <alonzakai@gmail.com>2016-04-21 18:36:40 -0700
commitcae6b923c96655c1b81cbe821e9b838e87ae7313 (patch)
tree532c52ef5d6afe865d1b3256ab948b78266f3bfc /src
parent523cfa206c06fd900cafbe75213e362aaccb4ef0 (diff)
downloadbinaryen-cae6b923c96655c1b81cbe821e9b838e87ae7313.tar.gz
binaryen-cae6b923c96655c1b81cbe821e9b838e87ae7313.tar.bz2
binaryen-cae6b923c96655c1b81cbe821e9b838e87ae7313.zip
block helper utils
Diffstat (limited to 'src')
-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