summaryrefslogtreecommitdiff
path: root/src/literal.h
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/literal.h
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/literal.h')
-rw-r--r--src/literal.h31
1 files changed, 30 insertions, 1 deletions
diff --git a/src/literal.h b/src/literal.h
index 652f80bdc..b21f08995 100644
--- a/src/literal.h
+++ b/src/literal.h
@@ -30,6 +30,7 @@
namespace wasm {
class Literals;
+struct ExceptionPackage;
class Literal {
// store only integers, whose bits are deterministic. floats
@@ -39,6 +40,7 @@ class Literal {
int64_t i64;
uint8_t v128[16];
Name func; // function name for funcref
+ std::unique_ptr<ExceptionPackage> exn;
};
public:
@@ -65,6 +67,15 @@ public:
explicit Literal(const std::array<Literal, 4>&);
explicit Literal(const std::array<Literal, 2>&);
explicit Literal(Name func) : func(func), type(Type::funcref) {}
+ explicit Literal(std::unique_ptr<ExceptionPackage> exn)
+ : exn(std::move(exn)), type(Type::exnref) {}
+ Literal(const Literal& other);
+ Literal& operator=(const Literal& other);
+ ~Literal() {
+ if (type == Type::exnref) {
+ exn.~unique_ptr();
+ }
+ }
bool isConcrete() const { return type != Type::none; }
bool isNone() const { return type == Type::none; }
@@ -104,6 +115,9 @@ public:
static Literal makeNullref() { return Literal(Type(Type::nullref)); }
static Literal makeFuncref(Name func) { return Literal(func.c_str()); }
+ static Literal makeExnref(std::unique_ptr<ExceptionPackage> exn) {
+ return Literal(std::move(exn));
+ }
Literal castToF32();
Literal castToF64();
@@ -127,7 +141,14 @@ public:
return bit_cast<double>(i64);
}
std::array<uint8_t, 16> getv128() const;
- Name getFunc() const { return func; }
+ Name getFunc() const {
+ assert(type == Type::funcref);
+ return func;
+ }
+ const ExceptionPackage& getExceptionPackage() const {
+ assert(type == Type::exnref);
+ return *exn.get();
+ }
// careful!
int32_t* geti32Ptr() {
@@ -472,8 +493,16 @@ public:
bool isConcrete() { return size() != 0; }
};
+// A struct for a thrown exception, which includes a tag (event) and thrown
+// values
+struct ExceptionPackage {
+ Name event;
+ Literals values;
+};
+
std::ostream& operator<<(std::ostream& o, wasm::Literal literal);
std::ostream& operator<<(std::ostream& o, wasm::Literals literals);
+std::ostream& operator<<(std::ostream& o, const ExceptionPackage& exn);
} // namespace wasm