summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2018-05-15 15:58:13 -0700
committerGitHub <noreply@github.com>2018-05-15 15:58:13 -0700
commitd4aa0d30234ac9e553d743bd881a767d96554a4a (patch)
treefea2a16948b3d04db4c89e9c454daa2fccdf8716 /src
parent1354d20a1765c9132958c69661d613dc62eb3216 (diff)
downloadbinaryen-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')
-rw-r--r--src/pass.h16
-rw-r--r--src/passes/Print.cpp31
-rw-r--r--src/wasm-printing.h23
3 files changed, 34 insertions, 36 deletions
diff --git a/src/pass.h b/src/pass.h
index b4db3e706..881fc4e00 100644
--- a/src/pass.h
+++ b/src/pass.h
@@ -263,22 +263,6 @@ public:
}
};
-// Standard passes. All passes in /passes/ are runnable from the shell,
-// but registering them here in addition allows them to communicate
-// e.g. through PassRunner::getLast
-
-// 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;
-};
-
} // namespace wasm
#endif // wasm_pass_h
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)";
diff --git a/src/wasm-printing.h b/src/wasm-printing.h
index 3b5b94cc2..936c118ee 100644
--- a/src/wasm-printing.h
+++ b/src/wasm-printing.h
@@ -25,18 +25,9 @@
namespace wasm {
struct WasmPrinter {
- static std::ostream& printModule(Module* module, std::ostream& o) {
- PassRunner passRunner(module);
- passRunner.setFeatures(Feature::All);
- passRunner.setIsNested(true);
- passRunner.add<Printer>(&o);
- passRunner.run();
- return o;
- }
-
- static std::ostream& printModule(Module* module) {
- return printModule(module, std::cout);
- }
+ static std::ostream& printModule(Module* module, std::ostream& o);
+
+ static std::ostream& printModule(Module* module);
static std::ostream& printExpression(Expression* expression, std::ostream& o, bool minify = false, bool full = false);
};
@@ -45,12 +36,12 @@ struct WasmPrinter {
namespace std {
-inline std::ostream& operator<<(std::ostream& o, wasm::Module* module) {
- return wasm::WasmPrinter::printModule(module, o);
+inline std::ostream& operator<<(std::ostream& o, wasm::Module& module) {
+ return wasm::WasmPrinter::printModule(&module, o);
}
-inline std::ostream& operator<<(std::ostream& o, wasm::Expression* expression) {
- return wasm::WasmPrinter::printExpression(expression, o);
+inline std::ostream& operator<<(std::ostream& o, wasm::Expression& expression) {
+ return wasm::WasmPrinter::printExpression(&expression, o);
}
}