summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2022-08-31 09:10:22 -0700
committerGitHub <noreply@github.com>2022-08-31 16:10:22 +0000
commit972cc6f39cb903834be6066c33356f77fc41bc26 (patch)
treec144536cfbd5fe5e962566bea3545223fbd3685b
parent8e1abd1eff79fa25f0dda7ccb529f672f0d90388 (diff)
downloadbinaryen-972cc6f39cb903834be6066c33356f77fc41bc26.tar.gz
binaryen-972cc6f39cb903834be6066c33356f77fc41bc26.tar.bz2
binaryen-972cc6f39cb903834be6066c33356f77fc41bc26.zip
[NFC] Simplify binary reading logic for data segments (#4990)
Similar to #4969 but for data segments.
-rw-r--r--src/wasm-binary.h3
-rw-r--r--src/wasm/wasm-binary.cpp11
2 files changed, 4 insertions, 10 deletions
diff --git a/src/wasm-binary.h b/src/wasm-binary.h
index 2359d53bf..ab55b6f50 100644
--- a/src/wasm-binary.h
+++ b/src/wasm-binary.h
@@ -1529,9 +1529,6 @@ public:
// at index i we have all references to the memory i
std::map<Index, std::vector<wasm::Name*>> memoryRefs;
- // we store data here after being read from binary, before we know their names
- std::vector<std::unique_ptr<DataSegment>> dataSegments;
-
// at index i we have all refs to the global i
std::map<Index, std::vector<Name*>> globalRefs;
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp
index baff0d83f..03ae5ce5a 100644
--- a/src/wasm/wasm-binary.cpp
+++ b/src/wasm/wasm-binary.cpp
@@ -2971,15 +2971,12 @@ Expression* WasmBinaryBuilder::popTypedExpression(Type type) {
}
void WasmBinaryBuilder::validateBinary() {
- if (hasDataCount && dataSegments.size() != dataCount) {
+ if (hasDataCount && wasm.dataSegments.size() != dataCount) {
throwError("Number of segments does not agree with DataCount section");
}
}
void WasmBinaryBuilder::processNames() {
- for (auto& segment : dataSegments) {
- wasm.addDataSegment(std::move(segment));
- }
// now that we have names, apply things
if (startIndex != static_cast<Index>(-1)) {
@@ -3072,7 +3069,7 @@ void WasmBinaryBuilder::readDataSegments() {
auto size = getU32LEB();
auto data = getByteView(size);
curr->data = {data.first, data.second};
- dataSegments.push_back(std::move(curr));
+ wasm.addDataSegment(std::move(curr));
}
}
@@ -3398,8 +3395,8 @@ void WasmBinaryBuilder::readNames(size_t payloadLen) {
auto index = getU32LEB();
auto rawName = getInlineString();
auto name = processor.process(rawName);
- if (index < dataSegments.size()) {
- dataSegments[i]->setExplicitName(name);
+ if (index < wasm.dataSegments.size()) {
+ wasm.dataSegments[i]->setExplicitName(name);
} else {
std::cerr << "warning: data index out of bounds in name section, "
"data subsection: "