summaryrefslogtreecommitdiff
path: root/src/wasm/wasm-binary.cpp
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2020-12-11 08:27:43 -0800
committerGitHub <noreply@github.com>2020-12-11 08:27:43 -0800
commite16cf5818de5a6e37ffcbce0bcde320290d9f9f1 (patch)
tree84a8a0d0e1031409501a548e465a89380ce7da80 /src/wasm/wasm-binary.cpp
parente1978e0274de74aa9ce5c6bcfa71e03ddadeb685 (diff)
downloadbinaryen-e16cf5818de5a6e37ffcbce0bcde320290d9f9f1.tar.gz
binaryen-e16cf5818de5a6e37ffcbce0bcde320290d9f9f1.tar.bz2
binaryen-e16cf5818de5a6e37ffcbce0bcde320290d9f9f1.zip
[GC] Add ref.test and ref.cast (#3439)
This adds enough to read and write them and test that, but leaves interpreter support for later.
Diffstat (limited to 'src/wasm/wasm-binary.cpp')
-rw-r--r--src/wasm/wasm-binary.cpp22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp
index 0c68264a3..1b3d50a41 100644
--- a/src/wasm/wasm-binary.cpp
+++ b/src/wasm/wasm-binary.cpp
@@ -5599,10 +5599,13 @@ bool WasmBinaryBuilder::maybeVisitRefTest(Expression*& out, uint32_t code) {
if (code != BinaryConsts::RefTest) {
return false;
}
- auto* curr = allocator.alloc<RefTest>();
- WASM_UNREACHABLE("TODO (gc): ref.test");
- curr->finalize();
- out = curr;
+ auto heapType1 = getHeapType();
+ auto heapType2 = getHeapType();
+ auto* ref = popNonVoidExpression();
+ validateHeapTypeUsingChild(ref, heapType1);
+ auto* rtt = popNonVoidExpression();
+ validateHeapTypeUsingChild(rtt, heapType2);
+ out = Builder(wasm).makeRefTest(ref, rtt);
return true;
}
@@ -5610,10 +5613,13 @@ bool WasmBinaryBuilder::maybeVisitRefCast(Expression*& out, uint32_t code) {
if (code != BinaryConsts::RefCast) {
return false;
}
- auto* curr = allocator.alloc<RefCast>();
- WASM_UNREACHABLE("TODO (gc): ref.cast");
- curr->finalize();
- out = curr;
+ auto heapType1 = getHeapType();
+ auto heapType2 = getHeapType();
+ auto* ref = popNonVoidExpression();
+ validateHeapTypeUsingChild(ref, heapType1);
+ auto* rtt = popNonVoidExpression();
+ validateHeapTypeUsingChild(rtt, heapType2);
+ out = Builder(wasm).makeRefCast(ref, rtt);
return true;
}