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.h50
1 files changed, 22 insertions, 28 deletions
diff --git a/src/wasm-builder.h b/src/wasm-builder.h
index 8d4235357..cbdd7abf7 100644
--- a/src/wasm-builder.h
+++ b/src/wasm-builder.h
@@ -167,7 +167,6 @@ public:
}
// IR nodes
-
Nop* makeNop() { return wasm.allocator.alloc<Nop>(); }
Block* makeBlock(Expression* first = nullptr) {
auto* ret = wasm.allocator.alloc<Block>();
@@ -183,52 +182,47 @@ public:
ret->finalize();
return ret;
}
- Block* makeBlock(const std::vector<Expression*>& items) {
+
+ template<typename T>
+ using bool_if_not_expr_t =
+ std::enable_if_t<std::negation_v<std::is_convertible<T, Expression*>>,
+ bool>;
+
+ template<typename T, bool_if_not_expr_t<T> = true>
+ Block* makeBlock(const T& items) {
auto* ret = wasm.allocator.alloc<Block>();
ret->list.set(items);
ret->finalize();
return ret;
}
- Block* makeBlock(const std::vector<Expression*>& items, Type type) {
+
+ template<typename T, bool_if_not_expr_t<T> = true>
+ Block* makeBlock(const T& items, Type type) {
auto* ret = wasm.allocator.alloc<Block>();
ret->list.set(items);
ret->finalize(type);
return ret;
}
- Block*
- makeBlock(Name name, const std::vector<Expression*>& items, Type type) {
+
+ template<typename T, bool_if_not_expr_t<T> = true>
+ Block* makeBlock(Name name, const T& items, Type type) {
auto* ret = wasm.allocator.alloc<Block>();
ret->name = name;
ret->list.set(items);
ret->finalize(type);
return ret;
}
- Block* makeBlock(const ExpressionList& items) {
- auto* ret = wasm.allocator.alloc<Block>();
- ret->list.set(items);
- ret->finalize();
- return ret;
- }
- Block* makeBlock(const ExpressionList& items, Type type) {
- auto* ret = wasm.allocator.alloc<Block>();
- ret->list.set(items);
- ret->finalize(type);
- return ret;
+ Block* makeBlock(std::initializer_list<Expression*>&& items) {
+ return makeBlock(items);
}
- Block* makeBlock(Name name, const ExpressionList& items) {
- auto* ret = wasm.allocator.alloc<Block>();
- ret->name = name;
- ret->list.set(items);
- ret->finalize();
- return ret;
+ Block* makeBlock(std::initializer_list<Expression*>&& items, Type type) {
+ return makeBlock(items, type);
}
- Block* makeBlock(Name name, const ExpressionList& items, Type type) {
- auto* ret = wasm.allocator.alloc<Block>();
- ret->name = name;
- ret->list.set(items);
- ret->finalize(type);
- return ret;
+ Block*
+ makeBlock(Name name, std::initializer_list<Expression*>&& items, Type type) {
+ return makeBlock(name, items, type);
}
+
If* makeIf(Expression* condition,
Expression* ifTrue,
Expression* ifFalse = nullptr) {