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/pass.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/pass.cpp')
-rw-r--r-- | src/passes/pass.cpp | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/src/passes/pass.cpp b/src/passes/pass.cpp index 9215341e3..66ffb9b30 100644 --- a/src/passes/pass.cpp +++ b/src/passes/pass.cpp @@ -17,12 +17,13 @@ #include <chrono> #include <sstream> -#include <support/colors.h> -#include <passes/passes.h> -#include <pass.h> -#include <wasm-validator.h> -#include <wasm-io.h> +#include "support/colors.h" +#include "passes/passes.h" +#include "pass.h" +#include "wasm-validator.h" +#include "wasm-io.h" #include "ir/hashed.h" +#include "ir/module-utils.h" namespace wasm { @@ -267,9 +268,9 @@ void PassRunner::run() { auto before = std::chrono::steady_clock::now(); if (pass->isFunctionParallel()) { // function-parallel passes should get a new instance per function - for (auto& func : wasm->functions) { - runPassOnFunction(pass, func.get()); - } + ModuleUtils::iterDefinedFunctions(*wasm, [&](Function* func) { + runPassOnFunction(pass, func); + }); } else { runPass(pass); } @@ -320,9 +321,11 @@ void PassRunner::run() { return ThreadWorkState::Finished; // nothing left } Function* func = this->wasm->functions[index].get(); - // do the current task: run all passes on this function - for (auto* pass : stack) { - runPassOnFunction(pass, func); + if (!func->imported()) { + // do the current task: run all passes on this function + for (auto* pass : stack) { + runPassOnFunction(pass, func); + } } if (index + 1 == numFunctions) { return ThreadWorkState::Finished; // we did the last one |