diff options
author | Alon Zakai <azakai@google.com> | 2022-01-11 14:16:34 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-11 14:16:34 -0800 |
commit | b63fea1feefce42be49fa28fd85d01d4a52603a2 (patch) | |
tree | 541a37da001dda677bdd9288897587a0de908ac1 /src/ir/memory-utils.h | |
parent | cc36ffd13f6794cc5212a1f0ba7f58e816e8a0de (diff) | |
download | binaryen-b63fea1feefce42be49fa28fd85d01d4a52603a2.tar.gz binaryen-b63fea1feefce42be49fa28fd85d01d4a52603a2.tar.bz2 binaryen-b63fea1feefce42be49fa28fd85d01d4a52603a2.zip |
[ctor-eval] Stop if there are any memory.init instructions (#4442)
This tool depends (atm) on flattening memory segments. That is not compatible
with memory.init which cares about segment identities.
This changes flatten() only by adding the check for MemoryInit. The rest is
unchanged, although I saw the other two params are not needed and I removed
them while I was there.
Diffstat (limited to 'src/ir/memory-utils.h')
-rw-r--r-- | src/ir/memory-utils.h | 40 |
1 files changed, 1 insertions, 39 deletions
diff --git a/src/ir/memory-utils.h b/src/ir/memory-utils.h index 3a0862cd7..9b3325329 100644 --- a/src/ir/memory-utils.h +++ b/src/ir/memory-utils.h @@ -29,46 +29,8 @@ namespace wasm::MemoryUtils { // Flattens memory into a single data segment, or no segment. If there is // a segment, it starts at 0. -// If ensuredSegmentSize is provided, then a segment is always emitted, -// and of at least that size. // Returns true if successful (e.g. relocatable segments cannot be flattened). -inline bool flatten(Memory& memory, - Index ensuredSegmentSize = 0, - Module* module = nullptr) { - if (memory.segments.size() == 0) { - if (ensuredSegmentSize > 0) { - assert(module); // must provide a module if ensuring a size. - Builder builder(*module); - memory.segments.emplace_back(builder.makeConst(int32_t(0))); - memory.segments[0].data.resize(ensuredSegmentSize); - } - return true; - } - std::vector<char> data; - data.resize(ensuredSegmentSize); - for (auto& segment : memory.segments) { - if (segment.isPassive) { - return false; - } - auto* offset = segment.offset->dynCast<Const>(); - if (!offset) { - return false; - } - } - for (auto& segment : memory.segments) { - auto* offset = segment.offset->dynCast<Const>(); - Index start = offset->value.getInteger(); - Index end = start + segment.data.size(); - if (end > data.size()) { - data.resize(end); - } - std::copy(segment.data.begin(), segment.data.end(), data.begin() + start); - } - memory.segments.resize(1); - memory.segments[0].offset->cast<Const>()->value = Literal(int32_t(0)); - memory.segments[0].data.swap(data); - return true; -} +bool flatten(Module& wasm); // Ensures that the memory exists (of minimal size). inline void ensureExists(Memory& memory) { |