diff options
author | Alon Zakai <alonzakai@gmail.com> | 2016-04-19 08:57:41 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2016-04-19 08:57:41 -0700 |
commit | 2553dbe4c01a0f7d04f230bebe3ba41825ede46e (patch) | |
tree | 35076cc5139f1a090bfcadd48e6cd9f2811fa501 /src | |
parent | eb50dce005ad4ca10aaad7d15aa7a518d39ae887 (diff) | |
download | binaryen-2553dbe4c01a0f7d04f230bebe3ba41825ede46e.tar.gz binaryen-2553dbe4c01a0f7d04f230bebe3ba41825ede46e.tar.bz2 binaryen-2553dbe4c01a0f7d04f230bebe3ba41825ede46e.zip |
save the module on Walker objects, so passes have an easy way to access the module (#366)
Diffstat (limited to 'src')
-rw-r--r-- | src/wasm-traversal.h | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/wasm-traversal.h b/src/wasm-traversal.h index 555243621..b8b625f09 100644 --- a/src/wasm-traversal.h +++ b/src/wasm-traversal.h @@ -161,6 +161,11 @@ struct Walker : public VisitorType { replace = expression; } + // Get the current module + Module* getModule() { + return currModule; + } + // Get the current function Function* getFunction() { return currFunction; @@ -169,6 +174,8 @@ struct Walker : public VisitorType { // Walk starting void startWalk(Module *module) { + setModule(module); + // Dispatch statically through the SubType. SubType* self = static_cast<SubType*>(this); for (auto curr : module->functionTypes) { @@ -204,6 +211,7 @@ struct Walker : public VisitorType { size_t numFunctions = module->functions.size(); for (size_t i = 0; i < num; i++) { auto* instance = new SubType(); + instance->setModule(getModule()); instances.push_back(std::unique_ptr<SubType>(instance)); doWorkers.push_back([instance, &nextFunction, numFunctions, &module, processFunction]() { auto index = nextFunction.fetch_add(1); @@ -293,6 +301,10 @@ struct Walker : public VisitorType { static void doVisitNop(SubType* self, Expression** currp) { self->visitNop((*currp)->cast<Nop>()); } static void doVisitUnreachable(SubType* self, Expression** currp) { self->visitUnreachable((*currp)->cast<Unreachable>()); } + void setModule(Module *module) { + currModule = module; + } + void setFunction(Function *func) { currFunction = func; } @@ -301,6 +313,7 @@ private: Expression *replace = nullptr; // a node to replace std::vector<Task> stack; // stack of tasks Function* currFunction = nullptr; // current function being processed + Module* currModule = nullptr; // current module being processed }; // Walks in post-order, i.e., children first. When there isn't an obvious |