diff options
author | Alon Zakai <alonzakai@gmail.com> | 2018-09-19 15:50:30 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-19 15:50:30 -0700 |
commit | fe88b47749115009da0447e340cbdc86edf30984 (patch) | |
tree | 7dfd9aba7086c8aa6dff4877ac1ee3b9d78bc5ce /src/passes/RemoveImports.cpp | |
parent | a53356ab155a7d8c2f334dc9a3c1432bacbc78fe (diff) | |
download | binaryen-fe88b47749115009da0447e340cbdc86edf30984.tar.gz binaryen-fe88b47749115009da0447e340cbdc86edf30984.tar.bz2 binaryen-fe88b47749115009da0447e340cbdc86edf30984.zip |
Unify imported and non-imported things (#1678)
Fixes #1649
This moves us to a single object for functions, which can be imported or nor, and likewise for globals (as a result, GetGlobals do not need to check if the global is imported or not, etc.). All imported things now inherit from Importable, which has the module and base of the import, and if they are set then it is an import.
For convenient iteration, there are a few helpers like
ModuleUtils::iterDefinedGlobals(wasm, [&](Global* global) {
.. use global ..
});
as often iteration only cares about imported or defined (non-imported) things.
Diffstat (limited to 'src/passes/RemoveImports.cpp')
-rw-r--r-- | src/passes/RemoveImports.cpp | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/src/passes/RemoveImports.cpp b/src/passes/RemoveImports.cpp index 116cd3296..e70cbb3ac 100644 --- a/src/passes/RemoveImports.cpp +++ b/src/passes/RemoveImports.cpp @@ -22,14 +22,19 @@ // look at all the rest of the code). // -#include <wasm.h> -#include <pass.h> +#include "wasm.h" +#include "pass.h" +#include "ir/module-utils.h" namespace wasm { struct RemoveImports : public WalkerPass<PostWalker<RemoveImports>> { - void visitCallImport(CallImport *curr) { - Type type = getModule()->getFunctionType(getModule()->getImport(curr->target)->functionType)->result; + void visitCall(Call *curr) { + auto* func = getModule()->getFunction(curr->target); + if (!func->imported()) { + return; + } + Type type = getModule()->getFunctionType(func->type)->result; if (type == none) { replaceCurrent(getModule()->allocator.alloc<Nop>()); } else { @@ -41,13 +46,11 @@ struct RemoveImports : public WalkerPass<PostWalker<RemoveImports>> { void visitModule(Module *curr) { std::vector<Name> names; - for (auto& import : curr->imports) { - if (import->kind == ExternalKind::Function) { - names.push_back(import->name); - } - } + ModuleUtils::iterImportedFunctions(*curr, [&](Function* func) { + names.push_back(func->name); + }); for (auto& name : names) { - curr->removeImport(name); + curr->removeFunction(name); } } }; |