summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/passes/MinifyImportsAndExports.cpp18
-rw-r--r--src/shared-constants.h2
-rw-r--r--src/wasm/wasm.cpp2
3 files changed, 17 insertions, 5 deletions
diff --git a/src/passes/MinifyImportsAndExports.cpp b/src/passes/MinifyImportsAndExports.cpp
index d625f7543..0edc85dc7 100644
--- a/src/passes/MinifyImportsAndExports.cpp
+++ b/src/passes/MinifyImportsAndExports.cpp
@@ -143,17 +143,25 @@ private:
MinifiedNames names;
size_t soFar = 0;
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 newName = names.getName(soFar++);
- oldToNew[newName] = name;
- name = newName;
+ auto iter = oldToNew.find(name);
+ if (iter == oldToNew.end()) {
+ auto newName = names.getName(soFar++);
+ oldToNew[name] = newName;
+ newToOld[newName] = name;
+ name = newName;
+ } else {
+ name = iter->second;
+ }
};
auto processImport = [&](Importable* curr) {
- if (curr->module == ENV) {
+ if (curr->module == ENV || curr->module == WASI ||
+ curr->module == WASI_UNSTABLE) {
process(curr->base);
}
};
@@ -169,7 +177,7 @@ private:
}
module->updateMaps();
// Emit the mapping.
- for (auto& pair : oldToNew) {
+ for (auto& pair : newToOld) {
std::cout << pair.second.str << " => " << pair.first.str << '\n';
}
}
diff --git a/src/shared-constants.h b/src/shared-constants.h
index 4f64f1cf6..929b173cb 100644
--- a/src/shared-constants.h
+++ b/src/shared-constants.h
@@ -65,6 +65,8 @@ extern Name EXIT;
extern Name SHARED;
extern Name EVENT;
extern Name ATTR;
+extern Name WASI;
+extern Name WASI_UNSTABLE;
} // namespace wasm
diff --git a/src/wasm/wasm.cpp b/src/wasm/wasm.cpp
index b13797c89..1a47327c1 100644
--- a/src/wasm/wasm.cpp
+++ b/src/wasm/wasm.cpp
@@ -88,6 +88,8 @@ Name EXIT("exit");
Name SHARED("shared");
Name EVENT("event");
Name ATTR("attr");
+Name WASI("wasi");
+Name WASI_UNSTABLE("wasi_unstable");
// Expressions