summaryrefslogtreecommitdiff
path: root/src/wasm/wasm.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/wasm/wasm.cpp')
-rw-r--r--src/wasm/wasm.cpp29
1 files changed, 26 insertions, 3 deletions
diff --git a/src/wasm/wasm.cpp b/src/wasm/wasm.cpp
index 90120233d..436eedb2b 100644
--- a/src/wasm/wasm.cpp
+++ b/src/wasm/wasm.cpp
@@ -1023,16 +1023,39 @@ void RefTest::finalize() {
}
}
+// Helper to get the cast type for a cast instruction. They all look at the rtt
+// operand's type.
+template<typename T> static Type doGetCastType(T* curr) {
+ if (curr->rtt->type == Type::unreachable) {
+ // We don't have the RTT type, so just return unreachable. The type in this
+ // case should not matter in practice, but it may be seen while debugging.
+ return Type::unreachable;
+ }
+ // TODO: make non-nullable when we support that
+ return Type(curr->rtt->type.getHeapType(), Nullable);
+}
+
+Type RefTest::getCastType() { return doGetCastType(this); }
+
void RefCast::finalize() {
if (ref->type == Type::unreachable || rtt->type == Type::unreachable) {
type = Type::unreachable;
} else {
- // TODO: make non-nullable when we support that
- type = Type(rtt->type.getHeapType(), Nullable);
+ type = getCastType();
+ }
+}
+
+Type RefCast::getCastType() { return doGetCastType(this); }
+
+void BrOnCast::finalize() {
+ if (ref->type == Type::unreachable || rtt->type == Type::unreachable) {
+ type = Type::unreachable;
+ } else {
+ type = ref->type;
}
}
-// TODO (gc): br_on_cast
+Type BrOnCast::getCastType() { return castType; }
void RttCanon::finalize() {
// Nothing to do - the type must have been set already during construction.