summaryrefslogtreecommitdiff
path: root/src/ir/memory-utils.cpp
diff options
context:
space:
mode:
authorAshley Nelson <nashley@google.com>2022-06-21 20:57:43 -0700
committerGitHub <noreply@github.com>2022-06-21 20:57:43 -0700
commit3b9c2e85fa5d97ba08a95c0c7cce7d041e699cde (patch)
treec01eb86869401931006b6503e47d60b9a44511b0 /src/ir/memory-utils.cpp
parent7fa4c0841c31930759fbad2efb8ada3ef0e6f3ef (diff)
downloadbinaryen-3b9c2e85fa5d97ba08a95c0c7cce7d041e699cde.tar.gz
binaryen-3b9c2e85fa5d97ba08a95c0c7cce7d041e699cde.tar.bz2
binaryen-3b9c2e85fa5d97ba08a95c0c7cce7d041e699cde.zip
First class Data Segments (#4733)
* Updating wasm.h/cpp for DataSegments * Updating wasm-binary.h/cpp for DataSegments * Removed link from Memory to DataSegments and updated module-utils, Metrics and wasm-traversal * checking isPassive when copying data segments to know whether to construct the data segment with an offset or not * Removing memory member var from DataSegment class as there is only one memory rn. Updated wasm-validator.cpp * Updated wasm-interpreter * First look at updating Passes * Updated wasm-s-parser * Updated files in src/ir * Updating tools files * Last pass on src files before building * added visitDataSegment * Fixing build errors * Data segments need a name * fixing var name * ran clang-format * Ensuring a name on DataSegment * Ensuring more datasegments have names * Adding explicit name support * Fix fuzzing name * Outputting data name in wasm binary only if explicit * Checking temp dataSegments vector to validateBinary because it's the one with the segments before we processNames * Pass on when data segment names are explicitly set * Ran auto_update_tests.py and check.py, success all around * Removed an errant semi-colon and corrected a counter. Everything still passes * Linting * Fixing processing memory names after parsed from binary * Updating the test from the last fix * Correcting error comment * Impl kripken@ comments * Impl tlively@ comments * Updated tests that remove data print when == 0 * Ran clang format * Impl tlively@ comments * Ran clang-format
Diffstat (limited to 'src/ir/memory-utils.cpp')
-rw-r--r--src/ir/memory-utils.cpp26
1 files changed, 14 insertions, 12 deletions
diff --git a/src/ir/memory-utils.cpp b/src/ir/memory-utils.cpp
index b7c92fe9e..8dc3baeb9 100644
--- a/src/ir/memory-utils.cpp
+++ b/src/ir/memory-utils.cpp
@@ -37,34 +37,36 @@ bool flatten(Module& wasm) {
}
}
- auto& memory = wasm.memory;
+ auto& dataSegments = wasm.dataSegments;
- if (memory.segments.size() == 0) {
+ if (dataSegments.size() == 0) {
return true;
}
std::vector<char> data;
- for (auto& segment : memory.segments) {
- if (segment.isPassive) {
+ for (auto& segment : dataSegments) {
+ if (segment->isPassive) {
return false;
}
- auto* offset = segment.offset->dynCast<Const>();
+ auto* offset = segment->offset->dynCast<Const>();
if (!offset) {
return false;
}
}
- for (auto& segment : memory.segments) {
- auto* offset = segment.offset->dynCast<Const>();
+ for (auto& segment : dataSegments) {
+ auto* offset = segment->offset->dynCast<Const>();
Index start = offset->value.getInteger();
- Index end = start + segment.data.size();
+ Index end = start + segment->data.size();
if (end > data.size()) {
data.resize(end);
}
- std::copy(segment.data.begin(), segment.data.end(), data.begin() + start);
+ 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);
+ dataSegments.resize(1);
+ dataSegments[0]->offset->cast<Const>()->value = Literal(int32_t(0));
+ dataSegments[0]->data.swap(data);
+ wasm.removeDataSegments(
+ [&](DataSegment* curr) { return curr->name != dataSegments[0]->name; });
return true;
}