diff options
author | Alon Zakai <azakai@google.com> | 2023-05-03 14:53:24 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-03 14:53:24 -0700 |
commit | 070542f9f30cc262ac741fb3a620037900ac6381 (patch) | |
tree | 9cdfa3f78bf1cd72c5ce2830336c9c36a8954ee3 | |
parent | 345b2498b78cb14e9cb87a63f511ef6f55044e9c (diff) | |
download | binaryen-070542f9f30cc262ac741fb3a620037900ac6381.tar.gz binaryen-070542f9f30cc262ac741fb3a620037900ac6381.tar.bz2 binaryen-070542f9f30cc262ac741fb3a620037900ac6381.zip |
Emit memory segment index for data segments (#5699)
Before this fix we would flip all data segments to use the first memory.
-rw-r--r-- | src/wasm/wasm-binary.cpp | 9 | ||||
-rw-r--r-- | test/lit/multi-memories-basics.wast | 7 |
2 files changed, 14 insertions, 2 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index 28c22aed3..3975dd390 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -590,11 +590,20 @@ void WasmBinaryWriter::writeDataSegments() { o << U32LEB(wasm->dataSegments.size()); for (auto& segment : wasm->dataSegments) { uint32_t flags = 0; + Index memoryIndex = 0; if (segment->isPassive) { flags |= BinaryConsts::IsPassive; + } else { + memoryIndex = getMemoryIndex(segment->memory); + if (memoryIndex) { + flags |= BinaryConsts::HasIndex; + } } o << U32LEB(flags); if (!segment->isPassive) { + if (memoryIndex) { + o << U32LEB(memoryIndex); + } writeExpression(segment->offset); o << int8_t(BinaryConsts::End); } diff --git a/test/lit/multi-memories-basics.wast b/test/lit/multi-memories-basics.wast index daeff3b5d..b4d29f8b7 100644 --- a/test/lit/multi-memories-basics.wast +++ b/test/lit/multi-memories-basics.wast @@ -11,7 +11,10 @@ (memory $memory2 1 800) ;; CHECK: (memory $memory3 1 400) (memory $memory3 1 400) - (data (memory $memory1) (i32.const 0) "a" "" "bcd") + ;; CHECK: (data $data1 (memory $memory1) (i32.const 0) "abcd") + (data $data1 (memory $memory1) (i32.const 0) "a" "" "bcd") + ;; CHECK: (data $data2 (memory $memory2) (i32.const 9) "w") + (data $data2 (memory $memory2) (i32.const 9) "w") (import "env" "memory" (memory $importedMemory 1 1)) ;; CHECK: (func $memory.fill ;; CHECK-NEXT: (memory.fill $memory2 @@ -42,7 +45,7 @@ ) ) ;; CHECK: (func $memory.init - ;; CHECK-NEXT: (memory.init $memory1 $0 + ;; CHECK-NEXT: (memory.init $memory1 $data1 ;; CHECK-NEXT: (i32.const 0) ;; CHECK-NEXT: (i32.const 0) ;; CHECK-NEXT: (i32.const 45) |