summaryrefslogtreecommitdiff
path: root/src/wasm/wasm-stack.cpp
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2020-12-10 15:25:23 -0800
committerGitHub <noreply@github.com>2020-12-10 15:25:23 -0800
commitc93da3de39a4592abc6cddbed30b5c7074069a24 (patch)
tree265bcd421a97a21d58493f65eb29f252bf3a6001 /src/wasm/wasm-stack.cpp
parent57a9e77add02dc1d874fdbfee2c61cae8c0eefa1 (diff)
downloadbinaryen-c93da3de39a4592abc6cddbed30b5c7074069a24.tar.gz
binaryen-c93da3de39a4592abc6cddbed30b5c7074069a24.tar.bz2
binaryen-c93da3de39a4592abc6cddbed30b5c7074069a24.zip
[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.
Diffstat (limited to 'src/wasm/wasm-stack.cpp')
-rw-r--r--src/wasm/wasm-stack.cpp29
1 files changed, 23 insertions, 6 deletions
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) {