@@ -2529,17 +2529,15 @@ getOrMakeName(const std::unordered_map<Index, Name>& nameMap,
2529
2529
void WasmBinaryReader::readMemories () {
2530
2530
auto num = getU32LEB ();
2531
2531
auto numImports = wasm.memories .size ();
2532
- std::unordered_set<Name> usedNames;
2533
2532
for (auto & [index, name] : memoryNames) {
2534
2533
if (index >= num + numImports) {
2535
2534
std::cerr << " warning: memory index out of bounds in name section: "
2536
2535
<< name << " at index " << index << ' \n ' ;
2537
2536
}
2538
- usedNames.insert (name);
2539
2537
}
2540
2538
for (size_t i = 0 ; i < num; i++) {
2541
2539
auto [name, isExplicit] =
2542
- getOrMakeName (memoryNames, numImports + i, makeName (" " , i), usedNames );
2540
+ getOrMakeName (memoryNames, numImports + i, makeName (" " , i), usedMemoryNames );
2543
2541
auto memory = Builder::makeMemory (name);
2544
2542
memory->hasExplicitName = isExplicit;
2545
2543
getResizableLimits (memory->initial ,
@@ -2871,8 +2869,6 @@ void WasmBinaryReader::getResizableLimits(Address& initial,
2871
2869
void WasmBinaryReader::readImports () {
2872
2870
size_t num = getU32LEB ();
2873
2871
Builder builder (wasm);
2874
- std::unordered_set<Name> usedFunctionNames, usedTableNames, usedMemoryNames,
2875
- usedGlobalNames, usedTagNames;
2876
2872
for (size_t i = 0 ; i < num; i++) {
2877
2873
auto module = getInlineString ();
2878
2874
auto base = getInlineString ();
@@ -3007,13 +3003,14 @@ void WasmBinaryReader::setLocalNames(Function& func, Index i) {
3007
3003
void WasmBinaryReader::readFunctionSignatures () {
3008
3004
size_t num = getU32LEB ();
3009
3005
auto numImports = wasm.functions .size ();
3010
- std::unordered_set<Name> usedNames ;
3006
+ std::cout << " adding existing \n " ;
3011
3007
for (auto & [index, name] : functionNames) {
3012
3008
if (index >= num + numImports) {
3013
3009
std::cerr << " warning: function index out of bounds in name section: "
3014
3010
<< name << " at index " << index << ' \n ' ;
3015
3011
}
3016
- usedNames.insert (name);
3012
+ usedFunctionNames.insert (name);
3013
+ std::cout << " adding: " << name << " \n " ;
3017
3014
}
3018
3015
// Also check that the function indices in the local names subsection are
3019
3016
// in-bounds, even though we don't use them here.
@@ -3026,7 +3023,7 @@ void WasmBinaryReader::readFunctionSignatures() {
3026
3023
}
3027
3024
for (size_t i = 0 ; i < num; i++) {
3028
3025
auto [name, isExplicit] =
3029
- getOrMakeName (functionNames, numImports + i, makeName (" " , i), usedNames );
3026
+ getOrMakeName (functionNames, numImports + i, makeName (" " , i), usedFunctionNames );
3030
3027
auto index = getU32LEB ();
3031
3028
HeapType type = getTypeByIndex (index);
3032
3029
functionTypes.push_back (type);
@@ -4761,17 +4758,15 @@ Name WasmBinaryReader::getIndexedString() {
4761
4758
void WasmBinaryReader::readGlobals () {
4762
4759
size_t num = getU32LEB ();
4763
4760
auto numImports = wasm.globals .size ();
4764
- std::unordered_set<Name> usedNames;
4765
4761
for (auto & [index, name] : globalNames) {
4766
4762
if (index >= num + numImports) {
4767
4763
std::cerr << " warning: global index out of bounds in name section: "
4768
4764
<< name << " at index " << index << ' \n ' ;
4769
4765
}
4770
- usedNames.insert (name);
4771
4766
}
4772
4767
for (size_t i = 0 ; i < num; i++) {
4773
4768
auto [name, isExplicit] = getOrMakeName (
4774
- globalNames, numImports + i, makeName (" global$" , i), usedNames );
4769
+ globalNames, numImports + i, makeName (" global$" , i), usedGlobalNames );
4775
4770
auto type = getConcreteType ();
4776
4771
auto mutable_ = getU32LEB ();
4777
4772
if (mutable_ & ~1 ) {
@@ -4860,17 +4855,15 @@ void WasmBinaryReader::readDataSegments() {
4860
4855
void WasmBinaryReader::readTableDeclarations () {
4861
4856
auto num = getU32LEB ();
4862
4857
auto numImports = wasm.tables .size ();
4863
- std::unordered_set<Name> usedNames;
4864
4858
for (auto & [index, name] : tableNames) {
4865
4859
if (index >= num + numImports) {
4866
4860
std::cerr << " warning: table index out of bounds in name section: "
4867
4861
<< name << " at index " << index << ' \n ' ;
4868
4862
}
4869
- usedNames.insert (name);
4870
4863
}
4871
4864
for (size_t i = 0 ; i < num; i++) {
4872
4865
auto [name, isExplicit] =
4873
- getOrMakeName (tableNames, numImports + i, makeName (" " , i), usedNames );
4866
+ getOrMakeName (tableNames, numImports + i, makeName (" " , i), usedTableNames );
4874
4867
auto elemType = getType ();
4875
4868
if (!elemType.isRef ()) {
4876
4869
throwError (" Table type must be a reference type" );
@@ -4977,18 +4970,16 @@ void WasmBinaryReader::readElementSegments() {
4977
4970
void WasmBinaryReader::readTags () {
4978
4971
size_t num = getU32LEB ();
4979
4972
auto numImports = wasm.tags .size ();
4980
- std::unordered_set<Name> usedNames;
4981
4973
for (auto & [index, name] : tagNames) {
4982
4974
if (index >= num + numImports) {
4983
4975
std::cerr << " warning: tag index out of bounds in name section: " << name
4984
4976
<< " at index " << index << ' \n ' ;
4985
4977
}
4986
- usedNames.insert (name);
4987
4978
}
4988
4979
for (size_t i = 0 ; i < num; i++) {
4989
4980
getInt8 (); // Reserved 'attribute' field
4990
4981
auto [name, isExplicit] =
4991
- getOrMakeName (tagNames, numImports + i, makeName (" tag$" , i), usedNames );
4982
+ getOrMakeName (tagNames, numImports + i, makeName (" tag$" , i), usedTagNames );
4992
4983
auto typeIndex = getU32LEB ();
4993
4984
auto tag = Builder::makeTag (name, getSignatureByTypeIndex (typeIndex));
4994
4985
tag->hasExplicitName = isExplicit;
@@ -5081,6 +5072,7 @@ void WasmBinaryReader::readNames(size_t sectionPos, size_t payloadLen) {
5081
5072
auto rawName = getInlineString ();
5082
5073
auto name = processor.process (rawName);
5083
5074
functionNames[index] = name;
5075
+ usedFunctionNames.insert (name);
5084
5076
}
5085
5077
} else if (nameType == Subsection::NameLocal) {
5086
5078
auto numFuncs = getU32LEB ();
@@ -5112,6 +5104,7 @@ void WasmBinaryReader::readNames(size_t sectionPos, size_t payloadLen) {
5112
5104
auto rawName = getInlineString ();
5113
5105
auto name = processor.process (rawName);
5114
5106
tableNames[index] = name;
5107
+ usedTableNames.insert (name);
5115
5108
}
5116
5109
} else if (nameType == Subsection::NameElem) {
5117
5110
auto num = getU32LEB ();
@@ -5130,6 +5123,7 @@ void WasmBinaryReader::readNames(size_t sectionPos, size_t payloadLen) {
5130
5123
auto rawName = getInlineString ();
5131
5124
auto name = processor.process (rawName);
5132
5125
memoryNames[index] = name;
5126
+ usedMemoryNames.insert (name);
5133
5127
}
5134
5128
} else if (nameType == Subsection::NameData) {
5135
5129
auto num = getU32LEB ();
@@ -5148,6 +5142,7 @@ void WasmBinaryReader::readNames(size_t sectionPos, size_t payloadLen) {
5148
5142
auto rawName = getInlineString ();
5149
5143
auto name = processor.process (rawName);
5150
5144
globalNames[index] = name;
5145
+ usedGlobalNames.insert (name);
5151
5146
}
5152
5147
} else if (nameType == Subsection::NameField) {
5153
5148
auto numTypes = getU32LEB ();
@@ -5170,6 +5165,7 @@ void WasmBinaryReader::readNames(size_t sectionPos, size_t payloadLen) {
5170
5165
auto rawName = getInlineString ();
5171
5166
auto name = processor.process (rawName);
5172
5167
tagNames[index] = name;
5168
+ usedTagNames.insert (name);
5173
5169
}
5174
5170
} else {
5175
5171
std::cerr << " warning: unknown name subsection with id "
0 commit comments