Skip to content

Commit a1ff274

Browse files
authored
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.
1 parent 70434ef commit a1ff274

2 files changed

Lines changed: 18 additions & 37 deletions

File tree

src/wasm-binary.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,8 +1068,10 @@ class WasmBinaryBuilder {
10681068
void readMemory();
10691069
void readSignatures();
10701070

1071-
// gets a name in the combined function import+defined function space
1072-
Name getFunctionIndexName(Index i);
1071+
// gets a name in the combined import+defined space
1072+
Name getFunctionName(Index index);
1073+
Name getGlobalName(Index index);
1074+
10731075
void getResizableLimits(Address& initial,
10741076
Address& max,
10751077
bool& shared,
@@ -1150,10 +1152,6 @@ class WasmBinaryBuilder {
11501152
Expression* popExpression();
11511153
Expression* popNonVoidExpression();
11521154

1153-
// index of the Global => name. first imported globals, then internal globals
1154-
std::map<Index, Name> mappedGlobals;
1155-
1156-
Name getGlobalName(Index index);
11571155
void validateBinary(); // validations that cannot be performed on the Module
11581156
void processFunctions();
11591157

src/wasm/wasm-binary.cpp

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -818,11 +818,6 @@ void WasmBinaryBuilder::read() {
818818
break;
819819
case BinaryConsts::Section::Global: {
820820
readGlobals();
821-
// imports can read global imports, so we run getGlobalName and create
822-
// the mapping but after we read globals, we need to add the internal
823-
// globals too, so do that here
824-
mappedGlobals.clear(); // wipe the mapping
825-
getGlobalName(-1); // force rebuild
826821
break;
827822
}
828823
case BinaryConsts::Section::Data:
@@ -1202,11 +1197,18 @@ void WasmBinaryBuilder::readSignatures() {
12021197
}
12031198
}
12041199

1205-
Name WasmBinaryBuilder::getFunctionIndexName(Index i) {
1206-
if (i >= wasm.functions.size()) {
1200+
Name WasmBinaryBuilder::getFunctionName(Index index) {
1201+
if (index >= wasm.functions.size()) {
12071202
throwError("invalid function index");
12081203
}
1209-
return wasm.functions[i]->name;
1204+
return wasm.functions[index]->name;
1205+
}
1206+
1207+
Name WasmBinaryBuilder::getGlobalName(Index index) {
1208+
if (index >= wasm.globals.size()) {
1209+
throwError("invalid global index");
1210+
}
1211+
return wasm.globals[index]->name;
12101212
}
12111213

12121214
void WasmBinaryBuilder::getResizableLimits(Address& initial,
@@ -1807,25 +1809,6 @@ Expression* WasmBinaryBuilder::popNonVoidExpression() {
18071809
return block;
18081810
}
18091811

1810-
Name WasmBinaryBuilder::getGlobalName(Index index) {
1811-
if (!mappedGlobals.size()) {
1812-
// Create name => index mapping.
1813-
auto add = [&](Global* curr) {
1814-
auto index = mappedGlobals.size();
1815-
mappedGlobals[index] = curr->name;
1816-
};
1817-
ModuleUtils::iterImportedGlobals(wasm, add);
1818-
ModuleUtils::iterDefinedGlobals(wasm, add);
1819-
}
1820-
if (index == Index(-1)) {
1821-
return Name("null"); // just a force-rebuild
1822-
}
1823-
if (mappedGlobals.count(index) == 0) {
1824-
throwError("bad global index");
1825-
}
1826-
return mappedGlobals[index];
1827-
}
1828-
18291812
void WasmBinaryBuilder::validateBinary() {
18301813
if (hasDataCount && wasm.memory.segments.size() != dataCount) {
18311814
throwError("Number of segments does not agree with DataCount section");
@@ -1840,14 +1823,14 @@ void WasmBinaryBuilder::processFunctions() {
18401823
// now that we have names for each function, apply things
18411824

18421825
if (startIndex != static_cast<Index>(-1)) {
1843-
wasm.start = getFunctionIndexName(startIndex);
1826+
wasm.start = getFunctionName(startIndex);
18441827
}
18451828

18461829
for (auto* curr : exportOrder) {
18471830
auto index = exportIndexes[curr];
18481831
switch (curr->kind) {
18491832
case ExternalKind::Function: {
1850-
curr->value = getFunctionIndexName(index);
1833+
curr->value = getFunctionName(index);
18511834
break;
18521835
}
18531836
case ExternalKind::Table:
@@ -1869,15 +1852,15 @@ void WasmBinaryBuilder::processFunctions() {
18691852
size_t index = iter.first;
18701853
auto& calls = iter.second;
18711854
for (auto* call : calls) {
1872-
call->target = getFunctionIndexName(index);
1855+
call->target = getFunctionName(index);
18731856
}
18741857
}
18751858

18761859
for (auto& pair : functionTable) {
18771860
auto i = pair.first;
18781861
auto& indexes = pair.second;
18791862
for (auto j : indexes) {
1880-
wasm.table.segments[i].data.push_back(getFunctionIndexName(j));
1863+
wasm.table.segments[i].data.push_back(getFunctionName(j));
18811864
}
18821865
}
18831866

0 commit comments

Comments
 (0)