summaryrefslogtreecommitdiff
path: root/src/wasm/literal.cpp
diff options
context:
space:
mode:
authorHeejin Ahn <aheejin@gmail.com>2020-05-06 16:38:37 -0700
committerGitHub <noreply@github.com>2020-05-06 16:38:37 -0700
commit5585d3a46f2b1daf74d4a7cf7b1d9a17b102b05c (patch)
tree19718aa2c531542e67165b5062aa97ddcf2e9037 /src/wasm/literal.cpp
parent33ee4ccd4985ab134bf48dac4088131105290fee (diff)
downloadbinaryen-5585d3a46f2b1daf74d4a7cf7b1d9a17b102b05c.tar.gz
binaryen-5585d3a46f2b1daf74d4a7cf7b1d9a17b102b05c.tar.bz2
binaryen-5585d3a46f2b1daf74d4a7cf7b1d9a17b102b05c.zip
Add interpreter support for EH (#2780)
This adds interpreter support for EH instructions. This adds `ExceptionPackage` struct, which contains info of a thrown exception (an event tag and thrown values), and the union in `Literal` can take a `unique_ptr` to `ExceptionPackage`. We need a destructor, a copy constructor, and an assignment operator for `Literal`, because the union in `Literal` now has a member that cannot be trivially copied or deleted.
Diffstat (limited to 'src/wasm/literal.cpp')
-rw-r--r--src/wasm/literal.cpp41
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));