diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ir/memory-utils.cpp | 9 | ||||
-rw-r--r-- | src/tools/wasm-ctor-eval.cpp | 8 |
2 files changed, 12 insertions, 5 deletions
diff --git a/src/ir/memory-utils.cpp b/src/ir/memory-utils.cpp index 0f6b77602..552e4ff9a 100644 --- a/src/ir/memory-utils.cpp +++ b/src/ir/memory-utils.cpp @@ -21,8 +21,12 @@ namespace wasm::MemoryUtils { bool flatten(Module& wasm) { + // If there are no memories then they are already flat, in the empty sense. + if (wasm.memories.empty()) { + return true; + } // Flatten does not currently have support for multimemory - if (wasm.memories.size() > 1) { + if (wasm.memories.size() != 1) { return false; } // The presence of any instruction that cares about segment identity is a @@ -105,7 +109,8 @@ bool flatten(Module& wasm) { } std::copy(segment->data.begin(), segment->data.end(), data.begin() + start); } - dataSegments[0]->offset->cast<Const>()->value = Literal(int32_t(0)); + dataSegments[0]->offset->cast<Const>()->value = + Literal::makeFromInt32(0, wasm.memories[0]->indexType); dataSegments[0]->data.swap(data); wasm.removeDataSegments( [&](DataSegment* curr) { return curr->name != dataSegments[0]->name; }); diff --git a/src/tools/wasm-ctor-eval.cpp b/src/tools/wasm-ctor-eval.cpp index 72ad459d3..499c1bf6c 100644 --- a/src/tools/wasm-ctor-eval.cpp +++ b/src/tools/wasm-ctor-eval.cpp @@ -508,12 +508,14 @@ private: void applyMemoryToModule() { // Memory must have already been flattened into the standard form: one // segment at offset 0, or none. + auto& memory = wasm->memories[0]; if (wasm->dataSegments.empty()) { Builder builder(*wasm); auto curr = builder.makeDataSegment(); - curr->offset = builder.makeConst(int32_t(0)); + curr->offset = + builder.makeConst(Literal::makeFromInt32(0, memory->indexType)); curr->setName(Name::fromInt(0), false); - curr->memory = wasm->memories[0]->name; + curr->memory = memory->name; wasm->addDataSegment(std::move(curr)); } auto& segment = wasm->dataSegments[0]; @@ -521,7 +523,7 @@ private: // Copy the current memory contents after execution into the Module's // memory. - segment->data = memories[wasm->memories[0]->name]; + segment->data = memories[memory->name]; } // Serializing GC data requires more work than linear memory, because |