summaryrefslogtreecommitdiff
path: root/src/literal.h
diff options
context:
space:
mode:
authorDaniel Wirtz <dcode@dcode.io>2020-09-09 03:40:09 +0200
committerGitHub <noreply@github.com>2020-09-09 03:40:09 +0200
commit916ce6f1a9f7c85102a8c69f593b301c8df5d19d (patch)
tree93b22be9f2c0718248528d140b05221cb6878600 /src/literal.h
parent0fdcf5b51a0c8c379b2d3ad8262aa22bb234f0e9 (diff)
downloadbinaryen-916ce6f1a9f7c85102a8c69f593b301c8df5d19d.tar.gz
binaryen-916ce6f1a9f7c85102a8c69f593b301c8df5d19d.tar.bz2
binaryen-916ce6f1a9f7c85102a8c69f593b301c8df5d19d.zip
Update reference types (#3084)
Align with the current state of the reference types proposal: * Remove `nullref` * Remove `externref` and `funcref` subtyping * A `Literal` of a nullable reference type can now represent `null` (previously was type `nullref`) * Update the tests and temporarily comment out those tests relying on subtyping
Diffstat (limited to 'src/literal.h')
-rw-r--r--src/literal.h45
1 files changed, 34 insertions, 11 deletions
diff --git a/src/literal.h b/src/literal.h
index 4cbc16786..1b3949d21 100644
--- a/src/literal.h
+++ b/src/literal.h
@@ -39,8 +39,14 @@ class Literal {
int32_t i32;
int64_t i64;
uint8_t v128[16];
- Name func; // function name for funcref
+ // funcref function name. `isNull()` indicates a `null` value.
+ Name func;
+ // exnref package. `nullptr` indicates a `null` value.
std::unique_ptr<ExceptionPackage> exn;
+ // TODO: Literals of type `externref` can only be `null` currently but we
+ // will need to represent extern values eventually, to
+ // 1) run the spec tests and fuzzer with reference types enabled and
+ // 2) avoid bailing out when seeing a reference typed value in precompute
};
public:
@@ -48,10 +54,7 @@ public:
const Type type;
Literal() : v128(), type(Type::none) {}
- explicit Literal(Type type) : v128(), type(type) {
- assert(type != Type::unreachable && type != Type::funcref &&
- type != Type::exnref);
- }
+ explicit Literal(Type type);
explicit Literal(Type::BasicID typeId) : Literal(Type(typeId)) {}
explicit Literal(int32_t init) : i32(init), type(Type::i32) {}
explicit Literal(uint32_t init) : i32(init), type(Type::i32) {}
@@ -74,13 +77,25 @@ public:
Literal(const Literal& other);
Literal& operator=(const Literal& other);
~Literal() {
- if (type == Type::exnref) {
+ if (type.isException()) {
exn.~unique_ptr();
}
}
bool isConcrete() const { return type != Type::none; }
bool isNone() const { return type == Type::none; }
+ bool isNull() const {
+ if (type.isNullable()) {
+ if (type.isFunction()) {
+ return func.isNull();
+ }
+ if (type.isException()) {
+ return !exn;
+ }
+ return true;
+ }
+ return false;
+ }
static Literal makeFromInt32(int32_t x, Type type) {
switch (type.getBasic()) {
@@ -105,9 +120,12 @@ public:
static Literals makeZero(Type type);
static Literal makeSingleZero(Type type);
- 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) {
+ static Literal makeNull(Type type) {
+ assert(type.isNullable());
+ return Literal(type);
+ }
+ static Literal makeFunc(Name func) { return Literal(func.c_str()); }
+ static Literal makeExn(std::unique_ptr<ExceptionPackage>&& exn) {
return Literal(std::move(exn));
}
@@ -134,7 +152,7 @@ public:
}
std::array<uint8_t, 16> getv128() const;
Name getFunc() const {
- assert(type == Type::funcref);
+ assert(type.isFunction() && !func.isNull());
return func;
}
ExceptionPackage getExceptionPackage() const;
@@ -502,6 +520,12 @@ public:
struct ExceptionPackage {
Name event;
Literals values;
+ bool operator==(const ExceptionPackage& other) const {
+ return event == other.event && values == other.values;
+ }
+ bool operator!=(const ExceptionPackage& other) const {
+ return !(*this == other);
+ }
};
std::ostream& operator<<(std::ostream& o, wasm::Literal literal);
@@ -554,7 +578,6 @@ template<> struct less<wasm::Literal> {
return memcmp(a.getv128Ptr(), b.getv128Ptr(), 16) < 0;
case wasm::Type::funcref:
case wasm::Type::externref:
- case wasm::Type::nullref:
case wasm::Type::exnref:
case wasm::Type::none:
case wasm::Type::unreachable: