diff options
author | Alon Zakai <azakai@google.com> | 2021-09-10 09:39:10 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-10 09:39:10 -0700 |
commit | 3ed93d00b8f7c0d1f4ab2086b386836f2914dc0e (patch) | |
tree | 0511118fad9439fe6995ff0fe1e67b3231b67c14 /src/wasm-interpreter.h | |
parent | 23e452a5c89cc520a1d08bb465785bcb79a43baa (diff) | |
download | binaryen-3ed93d00b8f7c0d1f4ab2086b386836f2914dc0e.tar.gz binaryen-3ed93d00b8f7c0d1f4ab2086b386836f2914dc0e.tar.bz2 binaryen-3ed93d00b8f7c0d1f4ab2086b386836f2914dc0e.zip |
[Wasm GC] ArrayInit support (#4138)
array.init is like array.new_with_rtt except that it takes
as arguments the values to initialize the array with (as opposed to
a size and an optional initial value).
Spec: https://docs.google.com/document/d/1afthjsL_B9UaMqCA5ekgVmOm75BVFu6duHNsN9-gnXw/edit#
Diffstat (limited to 'src/wasm-interpreter.h')
-rw-r--r-- | src/wasm-interpreter.h | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h index 77e432436..9fc11de76 100644 --- a/src/wasm-interpreter.h +++ b/src/wasm-interpreter.h @@ -1702,6 +1702,27 @@ public: return Flow(Literal(std::make_shared<GCData>(rtt.getSingleValue(), data), curr->type)); } + Flow visitArrayInit(ArrayInit* curr) { + NOTE_ENTER("ArrayInit"); + auto rtt = this->visit(curr->rtt); + if (rtt.breaking()) { + return rtt; + } + Index num = curr->values.size(); + if (num >= ArrayLimit) { + hostLimit("allocation failure"); + } + Literals data(num); + for (Index i = 0; i < num; i++) { + auto value = this->visit(curr->values[i]); + if (value.breaking()) { + return value; + } + data[i] = value.getSingleValue(); + } + return Flow(Literal(std::make_shared<GCData>(rtt.getSingleValue(), data), + curr->type)); + } Flow visitArrayGet(ArrayGet* curr) { NOTE_ENTER("ArrayGet"); Flow ref = this->visit(curr->ref); |