From c93da3de39a4592abc6cddbed30b5c7074069a24 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Thu, 10 Dec 2020 15:25:23 -0800 Subject: [GC] Add Array operations (#3436) array.new/get/set/len - pretty straightforward after structs and all the infrastructure for them. Also fixes validation of the unnecessary heapType param in the text and binary formats in structs as well as arrays. Fixes printing of packed types in type names, which emitted i32 for them. That broke when we emitted the same name for an array of i8 and i32 as in the new testing here. Also fix a bug in Field::operator< which was wrong for packed types; again, this was easy to notice with the new testing. --- src/wasm/wasm-stack.cpp | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) (limited to 'src/wasm/wasm-stack.cpp') diff --git a/src/wasm/wasm-stack.cpp b/src/wasm/wasm-stack.cpp index 2e4e9d332..60c352c5d 100644 --- a/src/wasm/wasm-stack.cpp +++ b/src/wasm/wasm-stack.cpp @@ -1928,33 +1928,50 @@ void BinaryInstWriter::visitStructGet(StructGet* curr) { } else { op = BinaryConsts::StructGetU; } - o << int8_t(BinaryConsts::GCPrefix) << int8_t(op); + o << int8_t(BinaryConsts::GCPrefix) << U32LEB(op); parent.writeHeapType(heapType); o << U32LEB(curr->index); } void BinaryInstWriter::visitStructSet(StructSet* curr) { - o << int8_t(BinaryConsts::GCPrefix) << int8_t(BinaryConsts::StructSet); + o << int8_t(BinaryConsts::GCPrefix) << U32LEB(BinaryConsts::StructSet); parent.writeHeapType(curr->ref->type.getHeapType()); o << U32LEB(curr->index); } void BinaryInstWriter::visitArrayNew(ArrayNew* curr) { - WASM_UNREACHABLE("TODO (gc): array.new"); + o << int8_t(BinaryConsts::GCPrefix); + if (curr->isWithDefault()) { + o << U32LEB(BinaryConsts::ArrayNewDefaultWithRtt); + } else { + o << U32LEB(BinaryConsts::ArrayNewWithRtt); + } + parent.writeHeapType(curr->rtt->type.getHeapType()); } void BinaryInstWriter::visitArrayGet(ArrayGet* curr) { - WASM_UNREACHABLE("TODO (gc): array.get"); + auto heapType = curr->ref->type.getHeapType(); + const auto& field = heapType.getArray().element; + int8_t op; + if (field.type != Type::i32 || field.packedType == Field::not_packed) { + op = BinaryConsts::ArrayGet; + } else if (curr->signed_) { + op = BinaryConsts::ArrayGetS; + } else { + op = BinaryConsts::ArrayGetU; + } + o << int8_t(BinaryConsts::GCPrefix) << U32LEB(op); + parent.writeHeapType(heapType); } void BinaryInstWriter::visitArraySet(ArraySet* curr) { o << int8_t(BinaryConsts::GCPrefix) << U32LEB(BinaryConsts::ArraySet); - WASM_UNREACHABLE("TODO (gc): array.set"); + parent.writeHeapType(curr->ref->type.getHeapType()); } void BinaryInstWriter::visitArrayLen(ArrayLen* curr) { o << int8_t(BinaryConsts::GCPrefix) << U32LEB(BinaryConsts::ArrayLen); - WASM_UNREACHABLE("TODO (gc): array.len"); + parent.writeHeapType(curr->ref->type.getHeapType()); } void BinaryInstWriter::emitScopeEnd(Expression* curr) { -- cgit v1.2.3