diff options
author | Alon Zakai <azakai@google.com> | 2019-09-01 17:51:10 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-01 17:51:10 -0700 |
commit | 6cec37ef2e38ae1844c61832566cfc22cb3e0ef6 (patch) | |
tree | def81c45c4d0cc7f9ba63b31774601993c6f01f3 /src | |
parent | b61f67c33daa45bab1fff1941c42ea41ee8e36a8 (diff) | |
download | binaryen-6cec37ef2e38ae1844c61832566cfc22cb3e0ef6.tar.gz binaryen-6cec37ef2e38ae1844c61832566cfc22cb3e0ef6.tar.bz2 binaryen-6cec37ef2e38ae1844c61832566cfc22cb3e0ef6.zip |
Minify wasi imports and exports, and not just "env" (#2323)
This makes the minification pass aware of "wasi_unstable" and "wasi" as well.
Diffstat (limited to 'src')
-rw-r--r-- | src/passes/MinifyImportsAndExports.cpp | 18 | ||||
-rw-r--r-- | src/shared-constants.h | 2 | ||||
-rw-r--r-- | src/wasm/wasm.cpp | 2 |
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 |