diff options
Diffstat (limited to 'src/wasm-builder.h')
-rw-r--r-- | src/wasm-builder.h | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/wasm-builder.h b/src/wasm-builder.h index 1acdc40c8..f77b0577c 100644 --- a/src/wasm-builder.h +++ b/src/wasm-builder.h @@ -601,7 +601,7 @@ public: ret->finalize(); return ret; } - TupleMake* makeTupleMake(std::vector<Expression*>&& operands) { + template<typename ListType> TupleMake* makeTupleMake(ListType&& operands) { auto* ret = allocator.alloc<TupleMake>(); ret->operands.set(operands); ret->finalize(); @@ -639,6 +639,19 @@ public: } } + Expression* makeConstExpression(Literals values) { + assert(values.size() > 0); + if (values.size() == 1) { + return makeConstExpression(values[0]); + } else { + std::vector<Expression*> consts; + for (auto value : values) { + consts.push_back(makeConstExpression(value)); + } + return makeTupleMake(consts); + } + } + // Additional utility functions for building on top of nodes // Convenient to have these on Builder, as it has allocation built in @@ -784,6 +797,9 @@ public: // minimal contents. as a replacement, this may reuse the // input node template<typename T> Expression* replaceWithIdenticalType(T* curr) { + if (curr->type.isMulti()) { + return makeConstExpression(Literal::makeZero(curr->type)); + } Literal value; // TODO: reuse node conditionally when possible for literals switch (curr->type.getSingle()) { |