diff options
author | Alon Zakai <alonzakai@gmail.com> | 2018-05-15 15:58:13 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-15 15:58:13 -0700 |
commit | d4aa0d30234ac9e553d743bd881a767d96554a4a (patch) | |
tree | fea2a16948b3d04db4c89e9c454daa2fccdf8716 /src/passes/Print.cpp | |
parent | 1354d20a1765c9132958c69661d613dc62eb3216 (diff) | |
download | binaryen-d4aa0d30234ac9e553d743bd881a767d96554a4a.tar.gz binaryen-d4aa0d30234ac9e553d743bd881a767d96554a4a.tar.bz2 binaryen-d4aa0d30234ac9e553d743bd881a767d96554a4a.zip |
Clean up printing code (#1548)
* make the iostream overrides receive a reference, not a pointer (i.e., like e.g. LLVM IR printing works, and avoiding overriding printing of pointer addresses which is sort of odd)
* move more code out of headers, especially unrelated headers.
Diffstat (limited to 'src/passes/Print.cpp')
-rw-r--r-- | src/passes/Print.cpp | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp index fc07b23b9..b1082dcc1 100644 --- a/src/passes/Print.cpp +++ b/src/passes/Print.cpp @@ -879,10 +879,20 @@ struct PrintSExpression : public Visitor<PrintSExpression> { } }; -void Printer::run(PassRunner* runner, Module* module) { - PrintSExpression print(o); - print.visitModule(module); -} +// Prints out a module +class Printer : public Pass { +protected: + std::ostream& o; + +public: + Printer() : o(std::cout) {} + Printer(std::ostream* o) : o(*o) {} + + void run(PassRunner* runner, Module* module) override { + PrintSExpression print(o); + print.visitModule(module); + } +}; Pass *createPrinterPass() { return new Printer(); @@ -926,6 +936,19 @@ Pass *createFullPrinterPass() { // Print individual expressions +std::ostream& WasmPrinter::printModule(Module* module, std::ostream& o) { + PassRunner passRunner(module); + passRunner.setFeatures(Feature::All); + passRunner.setIsNested(true); + passRunner.add<Printer>(&o); + passRunner.run(); + return o; +} + +std::ostream& WasmPrinter::printModule(Module* module) { + return printModule(module, std::cout); +} + std::ostream& WasmPrinter::printExpression(Expression* expression, std::ostream& o, bool minify, bool full) { if (!expression) { o << "(null expression)"; |