diff options
Diffstat (limited to 'src/wasm/literal.cpp')
-rw-r--r-- | src/wasm/literal.cpp | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/src/wasm/literal.cpp b/src/wasm/literal.cpp index b740ae520..33e53ca48 100644 --- a/src/wasm/literal.cpp +++ b/src/wasm/literal.cpp @@ -33,6 +33,39 @@ Literal::Literal(const uint8_t init[16]) : type(Type::v128) { memcpy(&v128, init, 16); } +Literal::Literal(const Literal& other) { *this = other; } + +Literal& Literal::operator=(const Literal& other) { + type = other.type; + assert(!type.isMulti()); + switch (type.getSingle()) { + case Type::i32: + case Type::f32: + i32 = other.i32; + break; + case Type::i64: + case Type::f64: + i64 = other.i64; + break; + case Type::v128: + memcpy(&v128, other.v128, 16); + break; + case Type::funcref: + func = other.func; + break; + case Type::exnref: + new (&exn) auto(std::make_unique<ExceptionPackage>(*other.exn)); + break; + case Type::none: + case Type::nullref: + break; + case Type::anyref: + case Type::unreachable: + WASM_UNREACHABLE("unexpected type"); + } + return *this; +} + template<typename LaneT, int Lanes> static void extractBytes(uint8_t (&dest)[16], const LaneArray<Lanes>& lanes) { std::array<uint8_t, 16> bytes; @@ -310,8 +343,10 @@ std::ostream& operator<<(std::ostream& o, Literal literal) { case Type::nullref: o << "nullref"; break; - case Type::anyref: case Type::exnref: + o << "exnref(" << literal.getExceptionPackage() << ")"; + break; + case Type::anyref: case Type::unreachable: WASM_UNREACHABLE("invalid type"); } @@ -334,6 +369,10 @@ std::ostream& operator<<(std::ostream& o, wasm::Literals literals) { } } +std::ostream& operator<<(std::ostream& o, const ExceptionPackage& exn) { + return o << exn.event << " " << exn.values; +} + Literal Literal::countLeadingZeroes() const { if (type == Type::i32) { return Literal((int32_t)CountLeadingZeroes(i32)); |