summaryrefslogtreecommitdiff
path: root/src/ir/module-utils.h
diff options
context:
space:
mode:
authorMax Graey <maxgraey@gmail.com>2021-11-23 07:03:25 +0200
committerGitHub <noreply@github.com>2021-11-22 21:03:25 -0800
commit7f24fce21a92f2aed4a11745d27d5181798ba6cd (patch)
tree80655dc933e3c2ae3ae53b7960cd71a6a022c3da /src/ir/module-utils.h
parent37999167bb333dd0b12d744af8e633897e65cff8 (diff)
downloadbinaryen-7f24fce21a92f2aed4a11745d27d5181798ba6cd.tar.gz
binaryen-7f24fce21a92f2aed4a11745d27d5181798ba6cd.tar.bz2
binaryen-7f24fce21a92f2aed4a11745d27d5181798ba6cd.zip
Modernize code to C++17 (#3104)
Diffstat (limited to 'src/ir/module-utils.h')
-rw-r--r--src/ir/module-utils.h31
1 files changed, 12 insertions, 19 deletions
diff --git a/src/ir/module-utils.h b/src/ir/module-utils.h
index d37457e96..1d56c1a3e 100644
--- a/src/ir/module-utils.h
+++ b/src/ir/module-utils.h
@@ -26,9 +26,7 @@
#include "support/unique_deferring_queue.h"
#include "wasm.h"
-namespace wasm {
-
-namespace ModuleUtils {
+namespace wasm::ModuleUtils {
// Copies a function into a module. If newName is provided it is used as the
// name of the function (otherwise the original name is copied).
@@ -155,10 +153,10 @@ inline void clearModule(Module& wasm) {
// call this redirect all of its uses.
template<typename T> inline void renameFunctions(Module& wasm, T& map) {
// Update the function itself.
- for (auto& pair : map) {
- if (Function* F = wasm.getFunctionOrNull(pair.first)) {
- assert(!wasm.getFunctionOrNull(pair.second) || F->name == pair.second);
- F->name = pair.second;
+ for (auto& [oldName, newName] : map) {
+ if (Function* F = wasm.getFunctionOrNull(oldName)) {
+ assert(!wasm.getFunctionOrNull(newName) || F->name == newName);
+ F->name = newName;
}
}
wasm.updateMaps();
@@ -415,9 +413,7 @@ template<typename T> struct CallGraphPropertyAnalysis {
map.swap(analysis.map);
// Find what is called by what.
- for (auto& pair : map) {
- auto* func = pair.first;
- auto& info = pair.second;
+ for (auto& [func, info] : map) {
for (auto* target : info.callsTo) {
map[target].calledBy.insert(func);
}
@@ -568,10 +564,9 @@ inline void collectHeapTypes(Module& wasm,
});
// Combine the function info with the module info.
- for (const auto& pair : analysis.map) {
- const Counts& functionCounts = pair.second;
- for (const auto& innerPair : functionCounts) {
- counts[innerPair.first] += innerPair.second;
+ for (auto& [_, functionCounts] : analysis.map) {
+ for (auto& [sig, count] : functionCounts) {
+ counts[sig] += count;
}
}
@@ -582,8 +577,8 @@ inline void collectHeapTypes(Module& wasm,
// previous ones. Each such type will appear in the type section once, so
// we just need to visit it once.
InsertOrderedSet<HeapType> newTypes;
- for (auto& pair : counts) {
- newTypes.insert(pair.first);
+ for (auto& [type, _] : counts) {
+ newTypes.insert(type);
}
while (!newTypes.empty()) {
auto iter = newTypes.begin();
@@ -621,8 +616,6 @@ inline void collectHeapTypes(Module& wasm,
}
}
-} // namespace ModuleUtils
-
-} // namespace wasm
+} // namespace wasm::ModuleUtils
#endif // wasm_ir_module_h