From 3ed93d00b8f7c0d1f4ab2086b386836f2914dc0e Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 10 Sep 2021 09:39:10 -0700 Subject: [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# --- src/wasm/wasm-s-parser.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/wasm/wasm-s-parser.cpp') diff --git a/src/wasm/wasm-s-parser.cpp b/src/wasm/wasm-s-parser.cpp index c9ca71a6d..28028c459 100644 --- a/src/wasm/wasm-s-parser.cpp +++ b/src/wasm/wasm-s-parser.cpp @@ -2680,6 +2680,18 @@ Expression* SExpressionWasmBuilder::makeArrayNew(Element& s, bool default_) { return Builder(wasm).makeArrayNew(rtt, size, init); } +Expression* SExpressionWasmBuilder::makeArrayInit(Element& s) { + auto heapType = parseHeapType(*s[1]); + size_t i = 2; + std::vector values; + while (i < s.size() - 1) { + values.push_back(parseExpression(*s[i++])); + } + auto* rtt = parseExpression(*s[i++]); + validateHeapTypeUsingChild(rtt, heapType, s); + return Builder(wasm).makeArrayInit(rtt, values); +} + Expression* SExpressionWasmBuilder::makeArrayGet(Element& s, bool signed_) { auto heapType = parseHeapType(*s[1]); auto ref = parseExpression(*s[2]); -- cgit v1.2.3