summaryrefslogtreecommitdiff
path: root/src/wasm/wasm-stack.cpp
diff options
context:
space:
mode:
authorThomas Lively <tlively@google.com>2023-04-06 13:35:12 -0700
committerGitHub <noreply@github.com>2023-04-06 20:35:12 +0000
commit4f91c6a569614275d906a825d3f495541aa8802d (patch)
tree26b438a2aeec65e93a219da792b928b7c9c0eece /src/wasm/wasm-stack.cpp
parent6afbc200b57acd1b9111de7729d47fea1d04c5f6 (diff)
downloadbinaryen-4f91c6a569614275d906a825d3f495541aa8802d.tar.gz
binaryen-4f91c6a569614275d906a825d3f495541aa8802d.tar.bz2
binaryen-4f91c6a569614275d906a825d3f495541aa8802d.zip
Implement array.fill, array.init_data, and array.init_elem (#5637)
These complement array.copy, which we already supported, as an initial complete set of bulk array operations. Replace the WIP spec tests with the upstream spec tests, lightly edited for compatibility with Binaryen.
Diffstat (limited to 'src/wasm/wasm-stack.cpp')
-rw-r--r--src/wasm/wasm-stack.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/wasm/wasm-stack.cpp b/src/wasm/wasm-stack.cpp
index 9e22efc0c..286b049aa 100644
--- a/src/wasm/wasm-stack.cpp
+++ b/src/wasm/wasm-stack.cpp
@@ -2185,6 +2185,37 @@ void BinaryInstWriter::visitArrayCopy(ArrayCopy* curr) {
parent.writeIndexedHeapType(curr->srcRef->type.getHeapType());
}
+void BinaryInstWriter::visitArrayFill(ArrayFill* curr) {
+ if (curr->ref->type.isNull()) {
+ emitUnreachable();
+ return;
+ }
+ o << int8_t(BinaryConsts::GCPrefix) << U32LEB(BinaryConsts::ArrayFill);
+ parent.writeIndexedHeapType(curr->ref->type.getHeapType());
+}
+
+void BinaryInstWriter::visitArrayInit(ArrayInit* curr) {
+ if (curr->ref->type.isNull()) {
+ emitUnreachable();
+ return;
+ }
+ o << int8_t(BinaryConsts::GCPrefix);
+ switch (curr->op) {
+ case InitData:
+ o << U32LEB(BinaryConsts::ArrayInitData);
+ parent.writeIndexedHeapType(curr->ref->type.getHeapType());
+ o << U32LEB(parent.getDataSegmentIndex(curr->segment));
+ break;
+ case InitElem:
+ o << U32LEB(BinaryConsts::ArrayInitElem);
+ parent.writeIndexedHeapType(curr->ref->type.getHeapType());
+ o << U32LEB(parent.getElementSegmentIndex(curr->segment));
+ break;
+ default:
+ WASM_UNREACHABLE("unexpected op");
+ }
+}
+
void BinaryInstWriter::visitRefAs(RefAs* curr) {
switch (curr->op) {
case RefAsNonNull: