summaryrefslogtreecommitdiff
path: root/src/literal.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/literal.h')
-rw-r--r--src/literal.h36
1 files changed, 26 insertions, 10 deletions
diff --git a/src/literal.h b/src/literal.h
index 1d19e6661..ef3e13d44 100644
--- a/src/literal.h
+++ b/src/literal.h
@@ -22,6 +22,7 @@
#include "compiler-support.h"
#include "support/hash.h"
+#include "support/name.h"
#include "support/utilities.h"
#include "wasm-type.h"
@@ -34,6 +35,7 @@ class Literal {
int32_t i32;
int64_t i64;
uint8_t v128[16];
+ Name func; // function name for funcref
};
public:
@@ -57,11 +59,12 @@ public:
explicit Literal(const std::array<Literal, 8>&);
explicit Literal(const std::array<Literal, 4>&);
explicit Literal(const std::array<Literal, 2>&);
+ explicit Literal(Name func) : func(func), type(Type::funcref) {}
- bool isConcrete() { return type != none; }
- bool isNull() { return type == none; }
+ bool isConcrete() { return type != Type::none; }
+ bool isNone() { return type == Type::none; }
- inline static Literal makeFromInt32(int32_t x, Type type) {
+ static Literal makeFromInt32(int32_t x, Type type) {
switch (type) {
case Type::i32:
return Literal(int32_t(x));
@@ -80,16 +83,26 @@ public:
Literal(int32_t(0)),
Literal(int32_t(0)),
Literal(int32_t(0))}});
- case Type::anyref: // there's no anyref literals
- case Type::exnref: // there's no exnref literals
- case none:
- case unreachable:
+ case Type::funcref:
+ case Type::anyref:
+ case Type::nullref:
+ case Type::exnref:
+ case Type::none:
+ case Type::unreachable:
WASM_UNREACHABLE("unexpected type");
}
WASM_UNREACHABLE("unexpected type");
}
- inline static Literal makeZero(Type type) { return makeFromInt32(0, type); }
+ static Literal makeZero(Type type) {
+ if (type.isRef()) {
+ return makeNullref();
+ }
+ return makeFromInt32(0, type);
+ }
+
+ static Literal makeNullref() { return Literal(Type(Type::nullref)); }
+ static Literal makeFuncref(Name func) { return Literal(func.c_str()); }
Literal castToF32();
Literal castToF64();
@@ -113,6 +126,7 @@ public:
return bit_cast<double>(i64);
}
std::array<uint8_t, 16> getv128() const;
+ Name getFunc() const { return func; }
// careful!
int32_t* geti32Ptr() {
@@ -464,8 +478,10 @@ template<> struct less<wasm::Literal> {
return a.reinterpreti64() < b.reinterpreti64();
case wasm::Type::v128:
return memcmp(a.getv128Ptr(), b.getv128Ptr(), 16) < 0;
- case wasm::Type::anyref: // anyref is an opaque value
- case wasm::Type::exnref: // exnref is an opaque value
+ case wasm::Type::funcref:
+ case wasm::Type::anyref:
+ case wasm::Type::nullref:
+ case wasm::Type::exnref:
case wasm::Type::none:
case wasm::Type::unreachable:
return false;