diff options
Diffstat (limited to 'src/wasm/wasm-binary.cpp')
-rw-r--r-- | src/wasm/wasm-binary.cpp | 34 |
1 files changed, 26 insertions, 8 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index 25c1eea8c..20edab3cf 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -982,6 +982,17 @@ void WasmBinaryWriter::writeType(Type type) { writeHeapType(type.getHeapType()); return; } + if (type.isRtt()) { + auto rtt = type.getRtt(); + if (rtt.hasDepth()) { + o << S32LEB(BinaryConsts::EncodedType::rtt_n); + o << U32LEB(rtt.depth); + } else { + o << S32LEB(BinaryConsts::EncodedType::rtt); + } + writeHeapType(rtt.heapType); + return; + } int ret = 0; TODO_SINGLE_COMPOUND(type); switch (type.getBasic()) { @@ -1382,6 +1393,14 @@ Type WasmBinaryBuilder::getType(int initial) { return Type(getHeapType(), /* nullable = */ true); case BinaryConsts::EncodedType::i31ref: return Type::i31ref; + case BinaryConsts::EncodedType::rtt_n: { + auto depth = getU32LEB(); + auto heapType = getHeapType(); + return Type(Rtt(depth, heapType)); + } + case BinaryConsts::EncodedType::rtt: { + return Type(Rtt(getHeapType())); + } default: throwError("invalid wasm type: " + std::to_string(initial)); } @@ -5575,10 +5594,8 @@ bool WasmBinaryBuilder::maybeVisitRttCanon(Expression*& out, uint32_t code) { if (code != BinaryConsts::RttCanon) { return false; } - auto* curr = allocator.alloc<RttCanon>(); - WASM_UNREACHABLE("TODO (gc): rtt.canon"); - curr->finalize(); - out = curr; + auto heapType = getHeapType(); + out = Builder(wasm).makeRttCanon(heapType); return true; } @@ -5586,10 +5603,11 @@ bool WasmBinaryBuilder::maybeVisitRttSub(Expression*& out, uint32_t code) { if (code != BinaryConsts::RttSub) { return false; } - auto* curr = allocator.alloc<RttSub>(); - WASM_UNREACHABLE("TODO (gc): rtt.sub"); - curr->finalize(); - out = curr; + // FIXME: the binary format may also have an extra heap type and index that + // are not needed + auto heapType = getHeapType(); + auto* parent = popNonVoidExpression(); + out = Builder(wasm).makeRttSub(heapType, parent); return true; } |