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/PrintCallGraph.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/PrintCallGraph.cpp')
-rw-r--r-- | src/passes/PrintCallGraph.cpp | 35 |
1 files changed, 14 insertions, 21 deletions
diff --git a/src/passes/PrintCallGraph.cpp b/src/passes/PrintCallGraph.cpp index fa58e3859..2a82b7aa1 100644 --- a/src/passes/PrintCallGraph.cpp +++ b/src/passes/PrintCallGraph.cpp @@ -24,6 +24,7 @@ #include "wasm.h" #include "pass.h" +#include "ir/module-utils.h" #include "ir/utils.h" namespace wasm { @@ -46,19 +47,17 @@ struct PrintCallGraph : public Pass { " }\n\n" " node [shape=box, fontname=courier, fontsize=10];\n"; - // All Functions - for (auto& func : module->functions) { - std::cout << " \"" << func.get()->name << "\" [style=\"filled\", fillcolor=\"white\"];\n"; - } + // Defined functions + ModuleUtils::iterDefinedFunctions(*module, [&](Function* curr) { + std::cout << " \"" << curr->name << "\" [style=\"filled\", fillcolor=\"white\"];\n"; + }); - // Imports Nodes - for (auto& curr : module->imports) { - if (curr->kind == ExternalKind::Function) { - o << " \"" << curr->name << "\" [style=\"filled\", fillcolor=\"turquoise\"];\n"; - } - } + // Imported functions + ModuleUtils::iterImportedFunctions(*module, [&](Function* curr) { + o << " \"" << curr->name << "\" [style=\"filled\", fillcolor=\"turquoise\"];\n"; + }); - // Exports Nodes + // Exports for (auto& curr : module->exports) { if (curr->kind == ExternalKind::Function) { Function* func = module->getFunction(curr->value); @@ -73,11 +72,11 @@ struct PrintCallGraph : public Pass { std::vector<Function*> allIndirectTargets; CallPrinter(Module *module) : module(module) { // Walk function bodies. - for (auto& func : module->functions) { - currFunction = func.get(); + ModuleUtils::iterDefinedFunctions(*module, [&](Function* curr) { + currFunction = curr; visitedTargets.clear(); - walk(func.get()->body); - } + walk(curr->body); + }); } void visitCall(Call *curr) { auto* target = module->getFunction(curr->target); @@ -85,12 +84,6 @@ struct PrintCallGraph : public Pass { visitedTargets.insert(target->name); std::cout << " \"" << currFunction->name << "\" -> \"" << target->name << "\"; // call\n"; } - void visitCallImport(CallImport *curr) { - auto name = curr->target; - if (visitedTargets.count(name) > 0) return; - visitedTargets.insert(name); - std::cout << " \"" << currFunction->name << "\" -> \"" << name << "\"; // callImport\n"; - } }; CallPrinter printer(module); |