diff options
Diffstat (limited to 'src/wasm')
-rw-r--r-- | src/wasm/wasm-binary.cpp | 80 | ||||
-rw-r--r-- | src/wasm/wasm-debug.cpp | 16 | ||||
-rw-r--r-- | src/wasm/wasm-emscripten.cpp | 4 | ||||
-rw-r--r-- | src/wasm/wasm-s-parser.cpp | 4 | ||||
-rw-r--r-- | src/wasm/wasm-stack.cpp | 4 | ||||
-rw-r--r-- | src/wasm/wasm-type.cpp | 4 | ||||
-rw-r--r-- | src/wasm/wasm-validator.cpp | 7 |
7 files changed, 46 insertions, 73 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index 74036d748..11346056a 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -165,17 +165,17 @@ void WasmBinaryWriter::finishSection(int32_t start) { // we are at the right absolute address. // We are relative to the section start. auto totalAdjustment = adjustmentForLEBShrinking + body; - for (auto& pair : binaryLocations.expressions) { - pair.second.start -= totalAdjustment; - pair.second.end -= totalAdjustment; + for (auto& [_, locations] : binaryLocations.expressions) { + locations.start -= totalAdjustment; + locations.end -= totalAdjustment; } - for (auto& pair : binaryLocations.functions) { - pair.second.start -= totalAdjustment; - pair.second.declarations -= totalAdjustment; - pair.second.end -= totalAdjustment; + for (auto& [_, locations] : binaryLocations.functions) { + locations.start -= totalAdjustment; + locations.declarations -= totalAdjustment; + locations.end -= totalAdjustment; } - for (auto& pair : binaryLocations.delimiters) { - for (auto& item : pair.second) { + for (auto& [_, locations] : binaryLocations.delimiters) { + for (auto& item : locations) { item -= totalAdjustment; } } @@ -734,9 +734,7 @@ void WasmBinaryWriter::writeNames() { startSubsection(BinaryConsts::UserSections::Subsection::NameLocal); o << U32LEB(functionsWithLocalNames.size()); Index emitted = 0; - for (auto& kv : functionsWithLocalNames) { - auto index = kv.first; - auto* func = kv.second; + for (auto& [index, func] : functionsWithLocalNames) { // Pairs of (local index in IR, name). std::vector<std::pair<Index, Name>> localsWithNames; auto numLocals = func->getNumLocals(); @@ -748,9 +746,7 @@ void WasmBinaryWriter::writeNames() { assert(localsWithNames.size()); o << U32LEB(index); o << U32LEB(localsWithNames.size()); - for (auto& indexedLocal : localsWithNames) { - auto indexInFunc = indexedLocal.first; - auto name = indexedLocal.second; + for (auto& [indexInFunc, name] : localsWithNames) { // TODO: handle multivalue auto indexInBinary = funcMappedLocals.at(func->name)[{indexInFunc, 0}]; @@ -767,8 +763,7 @@ void WasmBinaryWriter::writeNames() { // type names { std::vector<HeapType> namedTypes; - for (auto& kv : typeIndices) { - auto type = kv.first; + for (auto& [type, _] : typeIndices) { if (wasm->typeNames.count(type) && wasm->typeNames[type].name.is()) { namedTypes.push_back(type); } @@ -804,9 +799,9 @@ void WasmBinaryWriter::writeNames() { startSubsection(BinaryConsts::UserSections::Subsection::NameTable); o << U32LEB(tablesWithNames.size()); - for (auto& indexedTable : tablesWithNames) { - o << U32LEB(indexedTable.first); - writeEscapedName(indexedTable.second->name.str); + for (auto& [index, table] : tablesWithNames) { + o << U32LEB(index); + writeEscapedName(table->name.str); } finishSubsection(substart); @@ -839,9 +834,9 @@ void WasmBinaryWriter::writeNames() { auto substart = startSubsection(BinaryConsts::UserSections::Subsection::NameGlobal); o << U32LEB(globalsWithNames.size()); - for (auto& indexedGlobal : globalsWithNames) { - o << U32LEB(indexedGlobal.first); - writeEscapedName(indexedGlobal.second->name.str); + for (auto& [index, global] : globalsWithNames) { + o << U32LEB(index); + writeEscapedName(global->name.str); } finishSubsection(substart); } @@ -864,9 +859,9 @@ void WasmBinaryWriter::writeNames() { startSubsection(BinaryConsts::UserSections::Subsection::NameElem); o << U32LEB(elemsWithNames.size()); - for (auto& indexedElem : elemsWithNames) { - o << U32LEB(indexedElem.first); - writeEscapedName(indexedElem.second->name.str); + for (auto& [index, elem] : elemsWithNames) { + o << U32LEB(index); + writeEscapedName(elem->name.str); } finishSubsection(substart); @@ -919,9 +914,9 @@ void WasmBinaryWriter::writeNames() { std::unordered_map<Index, Name>& fieldNames = wasm->typeNames.at(type).fieldNames; o << U32LEB(fieldNames.size()); - for (auto& kv : fieldNames) { - o << U32LEB(kv.first); - writeEscapedName(kv.second.str); + for (auto& [index, name] : fieldNames) { + o << U32LEB(index); + writeEscapedName(name.str); } } finishSubsection(substart); @@ -987,18 +982,16 @@ void WasmBinaryWriter::writeSourceMapEpilog() { // write source map entries size_t lastOffset = 0; Function::DebugLocation lastLoc = {0, /* lineNumber = */ 1, 0}; - for (const auto& offsetAndlocPair : sourceMapLocations) { + for (const auto& [offset, loc] : sourceMapLocations) { if (lastOffset > 0) { *sourceMap << ","; } - size_t offset = offsetAndlocPair.first; - const Function::DebugLocation& loc = *offsetAndlocPair.second; writeBase64VLQ(*sourceMap, int32_t(offset - lastOffset)); - writeBase64VLQ(*sourceMap, int32_t(loc.fileIndex - lastLoc.fileIndex)); - writeBase64VLQ(*sourceMap, int32_t(loc.lineNumber - lastLoc.lineNumber)); + writeBase64VLQ(*sourceMap, int32_t(loc->fileIndex - lastLoc.fileIndex)); + writeBase64VLQ(*sourceMap, int32_t(loc->lineNumber - lastLoc.lineNumber)); writeBase64VLQ(*sourceMap, - int32_t(loc.columnNumber - lastLoc.columnNumber)); - lastLoc = loc; + int32_t(loc->columnNumber - lastLoc.columnNumber)); + lastLoc = *loc; lastOffset = offset; } *sourceMap << "\"}"; @@ -2308,10 +2301,9 @@ void WasmBinaryBuilder::readExports() { BYN_TRACE("read one\n"); auto curr = new Export; curr->name = getInlineString(); - if (names.count(curr->name) > 0) { + if (!names.emplace(curr->name).second) { throwError("duplicate export name"); } - names.insert(curr->name); curr->kind = (ExternalKind)getU32LEB(); auto index = getU32LEB(); exportIndices[curr] = index; @@ -2771,9 +2763,7 @@ void WasmBinaryBuilder::processNames() { wasm.addExport(curr); } - for (auto& iter : functionRefs) { - size_t index = iter.first; - auto& refs = iter.second; + for (auto& [index, refs] : functionRefs) { for (auto* ref : refs) { if (auto* call = ref->dynCast<Call>()) { call->target = getFunctionName(index); @@ -2785,9 +2775,7 @@ void WasmBinaryBuilder::processNames() { } } - for (auto& iter : tableRefs) { - size_t index = iter.first; - auto& refs = iter.second; + for (auto& [index, refs] : tableRefs) { for (auto* ref : refs) { if (auto* callIndirect = ref->dynCast<CallIndirect>()) { callIndirect->table = getTableName(index); @@ -2805,9 +2793,7 @@ void WasmBinaryBuilder::processNames() { } } - for (auto& iter : globalRefs) { - size_t index = iter.first; - auto& refs = iter.second; + for (auto& [index, refs] : globalRefs) { for (auto* ref : refs) { if (auto* get = ref->dynCast<GlobalGet>()) { get->name = getGlobalName(index); diff --git a/src/wasm/wasm-debug.cpp b/src/wasm/wasm-debug.cpp index 60e97a27e..23c2dc938 100644 --- a/src/wasm/wasm-debug.cpp +++ b/src/wasm/wasm-debug.cpp @@ -29,9 +29,7 @@ std::error_code dwarf2yaml(llvm::DWARFContext& DCtx, llvm::DWARFYAML::Data& Y); #include "wasm-debug.h" #include "wasm.h" -namespace wasm { - -namespace Debug { +namespace wasm::Debug { bool isDWARFSection(Name name) { return name.startsWith(".debug_"); } @@ -372,11 +370,11 @@ struct AddrExprMap { // Construct the map from the binaryLocations loaded from the wasm. AddrExprMap(const Module& wasm) { for (auto& func : wasm.functions) { - for (auto pair : func->expressionLocations) { - add(pair.first, pair.second); + for (auto& [expr, span] : func->expressionLocations) { + add(expr, span); } - for (auto pair : func->delimiterLocations) { - add(pair.first, pair.second); + for (auto& [expr, delim] : func->delimiterLocations) { + add(expr, delim); } } } @@ -1105,6 +1103,4 @@ bool shouldPreserveDWARF(PassOptions& options, Module& wasm) { return false; } #endif // BUILD_LLVM_DWARF -} // namespace Debug - -} // namespace wasm +} // namespace wasm::Debug diff --git a/src/wasm/wasm-emscripten.cpp b/src/wasm/wasm-emscripten.cpp index 7e56ef849..262787ac1 100644 --- a/src/wasm/wasm-emscripten.cpp +++ b/src/wasm/wasm-emscripten.cpp @@ -387,9 +387,7 @@ std::string EmscriptenGlueGenerator::generateEmscriptenMetadata() { if (!emJsWalker.codeByName.empty()) { meta << " \"emJsFuncs\": {"; commaFirst = true; - for (auto& pair : emJsWalker.codeByName) { - auto& name = pair.first; - auto& code = pair.second; + for (auto& [name, code] : emJsWalker.codeByName) { meta << nextElement(); meta << '"' << name << "\": \"" << escape(code) << '"'; } diff --git a/src/wasm/wasm-s-parser.cpp b/src/wasm/wasm-s-parser.cpp index d9c35d97c..9a537586e 100644 --- a/src/wasm/wasm-s-parser.cpp +++ b/src/wasm/wasm-s-parser.cpp @@ -908,9 +908,7 @@ void SExpressionWasmBuilder::preParseHeapTypes(Element& module) { types = builder.build(); - for (auto& pair : typeIndices) { - auto name = pair.first; - auto index = pair.second; + for (auto& [name, index] : typeIndices) { auto type = types[index]; // A type may appear in the type section more than once, but we canonicalize // types internally, so there will be a single name chosen for that type. Do diff --git a/src/wasm/wasm-stack.cpp b/src/wasm/wasm-stack.cpp index adb9341b0..616e0370b 100644 --- a/src/wasm/wasm-stack.cpp +++ b/src/wasm/wasm-stack.cpp @@ -2308,8 +2308,8 @@ void BinaryInstWriter::countScratchLocals() { scratchLocals[extract->type] = 0; } } - for (auto t : scratchLocals) { - noteLocalType(t.first); + for (auto& [type, _] : scratchLocals) { + noteLocalType(type); } } diff --git a/src/wasm/wasm-type.cpp b/src/wasm/wasm-type.cpp index 7dc336d87..f04ae5bc0 100644 --- a/src/wasm/wasm-type.cpp +++ b/src/wasm/wasm-type.cpp @@ -2975,9 +2975,7 @@ globallyCanonicalize(std::vector<std::unique_ptr<HeapTypeInfo>>& infos) { canonicalHeapTypes[original] = canonical; } } - for (auto& pair : canonicalHeapTypes) { - HeapType original = pair.first; - HeapType canonical = pair.second; + for (auto& [original, canonical] : canonicalHeapTypes) { for (HeapType* use : locations.heapTypes.at(original)) { *use = canonical; } diff --git a/src/wasm/wasm-validator.cpp b/src/wasm/wasm-validator.cpp index 8cf456409..e7e1d7fd5 100644 --- a/src/wasm/wasm-validator.cpp +++ b/src/wasm/wasm-validator.cpp @@ -493,8 +493,7 @@ void FunctionValidator::noteLabelName(Name name) { if (!name.is()) { return; } - bool inserted; - std::tie(std::ignore, inserted) = labelNames.insert(name); + auto [_, inserted] = labelNames.insert(name); shouldBeTrue( inserted, name, @@ -2870,9 +2869,7 @@ static void validateBinaryenIR(Module& wasm, ValidationInfo& info) { } // check if a node is a duplicate - expressions must not be seen more than // once - bool inserted; - std::tie(std::ignore, inserted) = seen.insert(curr); - if (!inserted) { + if (!seen.insert(curr).second) { std::ostringstream ss; ss << "expression seen more than once in the tree in " << scope << " on " << curr << '\n'; |