diff options
author | Heejin Ahn <aheejin@gmail.com> | 2019-05-12 15:13:38 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-12 15:13:38 -0700 |
commit | a1ff274b6bca0ff8d1635c32a6d206863f0a2fc3 (patch) | |
tree | 457fb108ef62c0ceee8a055dbab829d313e9c858 /src | |
parent | 70434ef31994391ae28c4aaaffd0d4f470da7fdc (diff) | |
download | binaryen-a1ff274b6bca0ff8d1635c32a6d206863f0a2fc3.tar.gz binaryen-a1ff274b6bca0ff8d1635c32a6d206863f0a2fc3.tar.bz2 binaryen-a1ff274b6bca0ff8d1635c32a6d206863f0a2fc3.zip |
Delete WasmBinaryBuilder::mappedGlobals (NFC) (#2098)
It doesn't seem to be used anywhere and I don't know why the
implementation for `WasmBinaryBuilder::getGlobalName` and
`WasmBinaryBuilder::getFunctionIndexName` are different. Renamed
`getFunctionIndexName` to `getFunctionName` for consistency.
Diffstat (limited to 'src')
-rw-r--r-- | src/wasm-binary.h | 10 | ||||
-rw-r--r-- | src/wasm/wasm-binary.cpp | 45 |
2 files changed, 18 insertions, 37 deletions
diff --git a/src/wasm-binary.h b/src/wasm-binary.h index b4adcdcb4..fe1b5ddaf 100644 --- a/src/wasm-binary.h +++ b/src/wasm-binary.h @@ -1068,8 +1068,10 @@ public: void readMemory(); void readSignatures(); - // gets a name in the combined function import+defined function space - Name getFunctionIndexName(Index i); + // gets a name in the combined import+defined space + Name getFunctionName(Index index); + Name getGlobalName(Index index); + void getResizableLimits(Address& initial, Address& max, bool& shared, @@ -1150,10 +1152,6 @@ public: Expression* popExpression(); Expression* popNonVoidExpression(); - // index of the Global => name. first imported globals, then internal globals - std::map<Index, Name> mappedGlobals; - - Name getGlobalName(Index index); void validateBinary(); // validations that cannot be performed on the Module void processFunctions(); diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index 484bfb49c..7f43a22d9 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -818,11 +818,6 @@ void WasmBinaryBuilder::read() { break; case BinaryConsts::Section::Global: { readGlobals(); - // imports can read global imports, so we run getGlobalName and create - // the mapping but after we read globals, we need to add the internal - // globals too, so do that here - mappedGlobals.clear(); // wipe the mapping - getGlobalName(-1); // force rebuild break; } case BinaryConsts::Section::Data: @@ -1202,11 +1197,18 @@ void WasmBinaryBuilder::readSignatures() { } } -Name WasmBinaryBuilder::getFunctionIndexName(Index i) { - if (i >= wasm.functions.size()) { +Name WasmBinaryBuilder::getFunctionName(Index index) { + if (index >= wasm.functions.size()) { throwError("invalid function index"); } - return wasm.functions[i]->name; + return wasm.functions[index]->name; +} + +Name WasmBinaryBuilder::getGlobalName(Index index) { + if (index >= wasm.globals.size()) { + throwError("invalid global index"); + } + return wasm.globals[index]->name; } void WasmBinaryBuilder::getResizableLimits(Address& initial, @@ -1807,25 +1809,6 @@ Expression* WasmBinaryBuilder::popNonVoidExpression() { return block; } -Name WasmBinaryBuilder::getGlobalName(Index index) { - if (!mappedGlobals.size()) { - // Create name => index mapping. - auto add = [&](Global* curr) { - auto index = mappedGlobals.size(); - mappedGlobals[index] = curr->name; - }; - ModuleUtils::iterImportedGlobals(wasm, add); - ModuleUtils::iterDefinedGlobals(wasm, add); - } - if (index == Index(-1)) { - return Name("null"); // just a force-rebuild - } - if (mappedGlobals.count(index) == 0) { - throwError("bad global index"); - } - return mappedGlobals[index]; -} - void WasmBinaryBuilder::validateBinary() { if (hasDataCount && wasm.memory.segments.size() != dataCount) { throwError("Number of segments does not agree with DataCount section"); @@ -1840,14 +1823,14 @@ void WasmBinaryBuilder::processFunctions() { // now that we have names for each function, apply things if (startIndex != static_cast<Index>(-1)) { - wasm.start = getFunctionIndexName(startIndex); + wasm.start = getFunctionName(startIndex); } for (auto* curr : exportOrder) { auto index = exportIndexes[curr]; switch (curr->kind) { case ExternalKind::Function: { - curr->value = getFunctionIndexName(index); + curr->value = getFunctionName(index); break; } case ExternalKind::Table: @@ -1869,7 +1852,7 @@ void WasmBinaryBuilder::processFunctions() { size_t index = iter.first; auto& calls = iter.second; for (auto* call : calls) { - call->target = getFunctionIndexName(index); + call->target = getFunctionName(index); } } @@ -1877,7 +1860,7 @@ void WasmBinaryBuilder::processFunctions() { auto i = pair.first; auto& indexes = pair.second; for (auto j : indexes) { - wasm.table.segments[i].data.push_back(getFunctionIndexName(j)); + wasm.table.segments[i].data.push_back(getFunctionName(j)); } } |