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.h73
1 files changed, 68 insertions, 5 deletions
diff --git a/src/wasm-builder.h b/src/wasm-builder.h
index 918e6a4ab..38009cb8a 100644
--- a/src/wasm-builder.h
+++ b/src/wasm-builder.h
@@ -110,6 +110,12 @@ public:
ret->finalize();
return ret;
}
+ Block* makeBlock(const std::vector<Expression*>& items, Type type) {
+ auto* ret = allocator.alloc<Block>();
+ ret->list.set(items);
+ ret->finalize(type);
+ return ret;
+ }
Block* makeBlock(const ExpressionList& items) {
auto* ret = allocator.alloc<Block>();
ret->list.set(items);
@@ -164,6 +170,13 @@ public:
ret->finalize();
return ret;
}
+ Loop* makeLoop(Name name, Expression* body, Type type) {
+ auto* ret = allocator.alloc<Loop>();
+ ret->name = name;
+ ret->body = body;
+ ret->finalize(type);
+ return ret;
+ }
Break* makeBreak(Name name,
Expression* value = nullptr,
Expression* condition = nullptr) {
@@ -459,6 +472,7 @@ public:
return ret;
}
Const* makeConst(Literal value) {
+ assert(value.type.isNumber());
auto* ret = allocator.alloc<Const>();
ret->value = value;
ret->type = value.type;
@@ -488,6 +502,17 @@ public:
ret->finalize();
return ret;
}
+ Select* makeSelect(Expression* condition,
+ Expression* ifTrue,
+ Expression* ifFalse,
+ Type type) {
+ auto* ret = allocator.alloc<Select>();
+ ret->condition = condition;
+ ret->ifTrue = ifTrue;
+ ret->ifFalse = ifFalse;
+ ret->finalize(type);
+ return ret;
+ }
Return* makeReturn(Expression* value = nullptr) {
auto* ret = allocator.alloc<Return>();
ret->value = value;
@@ -502,6 +527,23 @@ public:
ret->finalize();
return ret;
}
+ RefNull* makeRefNull() {
+ auto* ret = allocator.alloc<RefNull>();
+ ret->finalize();
+ return ret;
+ }
+ RefIsNull* makeRefIsNull(Expression* value) {
+ auto* ret = allocator.alloc<RefIsNull>();
+ ret->value = value;
+ ret->finalize();
+ return ret;
+ }
+ RefFunc* makeRefFunc(Name func) {
+ auto* ret = allocator.alloc<RefFunc>();
+ ret->func = func;
+ ret->finalize();
+ return ret;
+ }
Try* makeTry(Expression* body, Expression* catchBody) {
auto* ret = allocator.alloc<Try>();
ret->body = body;
@@ -569,6 +611,21 @@ public:
return ret;
}
+ Expression* makeConstExpression(Literal value) {
+ switch (value.type) {
+ case Type::nullref:
+ return makeRefNull();
+ case Type::funcref:
+ if (value.getFunc()[0] != 0) {
+ return makeRefFunc(value.getFunc());
+ }
+ return makeRefNull();
+ default:
+ assert(value.type.isNumber());
+ return makeConst(value);
+ }
+ }
+
// Additional utility functions for building on top of nodes
// Convenient to have these on Builder, as it has allocation built in
@@ -663,6 +720,13 @@ public:
return block;
}
+ Block* makeSequence(Expression* left, Expression* right, Type type) {
+ auto* block = makeBlock(left);
+ block->list.push_back(right);
+ block->finalize(type);
+ return block;
+ }
+
// Grab a slice out of a block, replacing it with nops, and returning
// either another block with the contents (if more than 1) or a single
// expression
@@ -728,16 +792,15 @@ public:
value = Literal(bytes.data());
break;
}
+ case funcref:
case anyref:
- // TODO Implement and return nullref
- assert(false && "anyref not implemented yet");
+ case nullref:
case exnref:
- // TODO Implement and return nullref
- assert(false && "exnref not implemented yet");
+ return ExpressionManipulator::refNull(curr);
case none:
return ExpressionManipulator::nop(curr);
case unreachable:
- return ExpressionManipulator::convert<T, Unreachable>(curr);
+ return ExpressionManipulator::unreachable(curr);
}
return makeConst(value);
}