diff options
Diffstat (limited to 'src/pass.h')
-rw-r--r-- | src/pass.h | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/src/pass.h b/src/pass.h index a95be9850..250ba59b2 100644 --- a/src/pass.h +++ b/src/pass.h @@ -71,10 +71,21 @@ struct PassRunner { PassRunner(MixedArena* allocator) : allocator(allocator) {} - void add(std::string passName); + void add(std::string passName) { + auto pass = PassRegistry::get()->createPass(passName); + assert(pass); + passes.push_back(pass); + } template<class P> - void add(); + void add() { + passes.push_back(new P()); + } + + template<class P, class Arg> + void add(Arg& arg){ + passes.push_back(new P(arg)); + } void run(Module* module); @@ -143,6 +154,25 @@ private: size_t counter = 0; }; +// Prints out a module +class Printer : public Pass { + std::ostream& o; + +public: + Printer() : o(std::cout) {} + Printer(std::ostream& o) : o(o) {} + + void run(PassRunner* runner, Module* module) override; +}; + +// Standard pass utilities + +inline void printWasm(Module* module, std::ostream& o) { + PassRunner passRunner(nullptr); + passRunner.add<Printer>(o); + passRunner.run(module); +} + } // namespace wasm #endif // wasm_pass_h |