diff options
Diffstat (limited to 'src/wasm')
-rw-r--r-- | src/wasm/literal.cpp | 19 | ||||
-rw-r--r-- | src/wasm/wasm.cpp | 14 |
2 files changed, 30 insertions, 3 deletions
diff --git a/src/wasm/literal.cpp b/src/wasm/literal.cpp index d5333847d..1cf867cdd 100644 --- a/src/wasm/literal.cpp +++ b/src/wasm/literal.cpp @@ -271,10 +271,10 @@ std::ostream& operator<<(std::ostream& o, Literal literal) { o << "?"; break; case Type::i32: - o << literal.i32; + o << literal.geti32(); break; case Type::i64: - o << literal.i64; + o << literal.geti64(); break; case Type::f32: literal.printFloat(o, literal.getf32()); @@ -301,6 +301,21 @@ std::ostream& operator<<(std::ostream& o, Literal literal) { return o; } +std::ostream& operator<<(std::ostream& o, wasm::Literals literals) { + if (literals.size() == 1) { + return o << literals[0]; + } else { + o << '('; + if (literals.size() > 0) { + o << literals[0]; + } + for (size_t i = 1; i < literals.size(); ++i) { + o << ", " << literals[i]; + } + return o << ')'; + } +} + Literal Literal::countLeadingZeroes() const { if (type == Type::i32) { return Literal((int32_t)CountLeadingZeroes(i32)); diff --git a/src/wasm/wasm.cpp b/src/wasm/wasm.cpp index 64bc5615f..4e4186d08 100644 --- a/src/wasm/wasm.cpp +++ b/src/wasm/wasm.cpp @@ -198,7 +198,7 @@ const char* getExpressionName(Expression* curr) { WASM_UNREACHABLE("invalid expr id"); } -Literal getLiteralFromConstExpression(Expression* curr) { +Literal getSingleLiteralFromConstExpression(Expression* curr) { if (auto* c = curr->dynCast<Const>()) { return c->value; } else if (curr->is<RefNull>()) { @@ -210,6 +210,18 @@ Literal getLiteralFromConstExpression(Expression* curr) { } } +Literals getLiteralsFromConstExpression(Expression* curr) { + if (auto* t = curr->dynCast<TupleMake>()) { + Literals values; + for (auto* operand : t->operands) { + values.push_back(getSingleLiteralFromConstExpression(operand)); + } + return values; + } else { + return {getSingleLiteralFromConstExpression(curr)}; + } +} + // core AST type checking struct TypeSeeker : public PostWalker<TypeSeeker> { |