From cae6b923c96655c1b81cbe821e9b838e87ae7313 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Thu, 21 Apr 2016 18:36:22 -0700 Subject: block helper utils --- src/wasm-builder.h | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'src/wasm-builder.h') 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(); + if (first) { + ret->list.push_back(first); + ret->finalize(); + } + return ret; + } If* makeIf(Expression* condition, Expression* ifTrue, Expression* ifFalse=nullptr) { auto* ret = allocator.alloc(); 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()) return any->cast(); + return makeBlock(any); + } }; } // namespace wasm -- cgit v1.2.3