summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ir/module-utils.h8
-rw-r--r--src/passes/MinifyImportsAndExports.cpp20
2 files changed, 12 insertions, 16 deletions
diff --git a/src/ir/module-utils.h b/src/ir/module-utils.h
index 375d9e245..62a9dd921 100644
--- a/src/ir/module-utils.h
+++ b/src/ir/module-utils.h
@@ -229,6 +229,14 @@ template<typename T> inline void iterDefinedEvents(Module& wasm, T visitor) {
}
}
+template<typename T> inline void iterImports(Module& wasm, T visitor) {
+ iterImportedMemories(wasm, visitor);
+ iterImportedTables(wasm, visitor);
+ iterImportedGlobals(wasm, visitor);
+ iterImportedFunctions(wasm, visitor);
+ iterImportedEvents(wasm, visitor);
+}
+
// Helper class for performing an operation on all the functions in the module,
// in parallel, with an Info object for each one that can contain results of
// some computation that the operation performs.
diff --git a/src/passes/MinifyImportsAndExports.cpp b/src/passes/MinifyImportsAndExports.cpp
index 3a4dd8f80..ca8426e8a 100644
--- a/src/passes/MinifyImportsAndExports.cpp
+++ b/src/passes/MinifyImportsAndExports.cpp
@@ -148,10 +148,6 @@ private:
std::map<Name, Name> oldToNew;
std::map<Name, Name> newToOld;
auto process = [&](Name& name) {
- // do not minifiy special imports, they must always exist
- if (name == MEMORY_BASE || name == TABLE_BASE || name == STACK_POINTER) {
- return;
- }
auto iter = oldToNew.find(name);
if (iter == oldToNew.end()) {
auto newName = names.getName(soFar++);
@@ -162,7 +158,7 @@ private:
name = iter->second;
}
};
- auto processImport = [&](Importable* curr) {
+ ModuleUtils::iterImports(*module, [&](Importable* curr) {
// Minify all import base names if we are importing modules (which means
// we will minify all modules names, so we are not being careful).
// Otherwise, assume we just want to minify "normal" imports like env
@@ -171,10 +167,7 @@ private:
curr->module.startsWith("wasi_")) {
process(curr->base);
}
- };
- ModuleUtils::iterImportedGlobals(*module, processImport);
- ModuleUtils::iterImportedFunctions(*module, processImport);
- ModuleUtils::iterImportedEvents(*module, processImport);
+ });
if (minifyExports) {
// Minify the exported names.
@@ -201,18 +194,13 @@ private:
#ifndef NDEBUG
std::set<Name> seenImports;
#endif
- auto processImport = [&](Importable* curr) {
+ ModuleUtils::iterImports(*module, [&](Importable* curr) {
curr->module = SINGLETON_MODULE_NAME;
#ifndef NDEBUG
assert(seenImports.count(curr->base) == 0);
seenImports.insert(curr->base);
#endif
- };
- ModuleUtils::iterImportedGlobals(*module, processImport);
- ModuleUtils::iterImportedFunctions(*module, processImport);
- ModuleUtils::iterImportedEvents(*module, processImport);
- ModuleUtils::iterImportedMemories(*module, processImport);
- ModuleUtils::iterImportedTables(*module, processImport);
+ });
}
};