summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2016-04-04 20:58:50 -0700
committerAlon Zakai <alonzakai@gmail.com>2016-04-04 21:01:11 -0700
commitc93cb496e9decf897f4a9b28d8be5c7afc94e577 (patch)
tree9fe21d424e36f73e51a1de109325b0f8fc635c44 /src
parent475a152951e5ca2a675640dfb6155ea4f1b9c137 (diff)
downloadbinaryen-c93cb496e9decf897f4a9b28d8be5c7afc94e577.tar.gz
binaryen-c93cb496e9decf897f4a9b28d8be5c7afc94e577.tar.bz2
binaryen-c93cb496e9decf897f4a9b28d8be5c7afc94e577.zip
refactor printing
Diffstat (limited to 'src')
-rw-r--r--src/asm2wasm-main.cpp2
-rw-r--r--src/passes/Print.cpp3
-rw-r--r--src/s2wasm-main.cpp2
-rw-r--r--src/s2wasm.h2
-rw-r--r--src/wasm-dis.cpp2
-rw-r--r--src/wasm-printing.h30
-rw-r--r--src/wasm-s-parser.h4
7 files changed, 29 insertions, 16 deletions
diff --git a/src/asm2wasm-main.cpp b/src/asm2wasm-main.cpp
index 12a06d0de..a9b1197ff 100644
--- a/src/asm2wasm-main.cpp
+++ b/src/asm2wasm-main.cpp
@@ -102,7 +102,7 @@ int main(int argc, const char *argv[]) {
if (options.debug) std::cerr << "printing..." << std::endl;
Output output(options.extra["output"], Flags::Text, options.debug ? Flags::Debug : Flags::Release);
- printWasm(&wasm, output.getStream());
+ WasmPrinter::printModule(&wasm, output.getStream());
if (mappedGlobals) {
if (options.debug)
diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp
index 77dcb6154..056b61939 100644
--- a/src/passes/Print.cpp
+++ b/src/passes/Print.cpp
@@ -19,6 +19,7 @@
//
#include <wasm.h>
+#include <wasm-printing.h>
#include <pass.h>
namespace wasm {
@@ -553,7 +554,7 @@ static RegisterPass<MinifiedPrinter> registerMinifyPass("print-minified", "print
// Print individual expressions
-std::ostream& printWasm(Expression* expression, std::ostream& o, bool minify = false) {
+std::ostream& WasmPrinter::printExpression(Expression* expression, std::ostream& o, bool minify) {
PrintSExpression print(o, minify);
print.visit(expression);
return o;
diff --git a/src/s2wasm-main.cpp b/src/s2wasm-main.cpp
index 8cbb7f5f5..80284975b 100644
--- a/src/s2wasm-main.cpp
+++ b/src/s2wasm-main.cpp
@@ -104,7 +104,7 @@ int main(int argc, const char *argv[]) {
if (options.debug) std::cerr << "Printing..." << std::endl;
Output output(options.extra["output"], Flags::Text, options.debug ? Flags::Debug : Flags::Release);
- printWasm(&wasm, output.getStream());
+ WasmPrinter::printModule(&wasm, output.getStream());
output << meta.str() << std::endl;
if (options.debug) std::cerr << "Done." << std::endl;
diff --git a/src/s2wasm.h b/src/s2wasm.h
index 4188003fd..f442de508 100644
--- a/src/s2wasm.h
+++ b/src/s2wasm.h
@@ -1330,7 +1330,7 @@ public:
// extra emscripten processing
void emscriptenGlue(std::ostream& o) {
if (debug) {
- printWasm(&wasm, std::cerr);
+ WasmPrinter::printModule(&wasm, std::cerr);
}
wasm.removeImport(EMSCRIPTEN_ASM_CONST); // we create _sig versions
diff --git a/src/wasm-dis.cpp b/src/wasm-dis.cpp
index c3197a1a2..5e1e61682 100644
--- a/src/wasm-dis.cpp
+++ b/src/wasm-dis.cpp
@@ -50,7 +50,7 @@ int main(int argc, const char *argv[]) {
if (options.debug) std::cerr << "Printing..." << std::endl;
Output output(options.extra["output"], Flags::Text, options.debug ? Flags::Debug : Flags::Release);
- printWasm(&wasm, output.getStream());
+ WasmPrinter::printModule(&wasm, output.getStream());
output << '\n';
if (options.debug) std::cerr << "Done." << std::endl;
diff --git a/src/wasm-printing.h b/src/wasm-printing.h
index 5b47a38bb..2fab99938 100644
--- a/src/wasm-printing.h
+++ b/src/wasm-printing.h
@@ -17,30 +17,38 @@
#ifndef __wasm_printing_h__
#define __wasm_printing_h__
+#include <ostream>
+
#include "wasm.h"
#include "pass.h"
namespace wasm {
-inline std::ostream& printWasm(Module* module, std::ostream& o) {
- PassRunner passRunner(nullptr);
- passRunner.add<Printer>(o);
- passRunner.run(module);
- return o;
-}
+struct WasmPrinter {
+ static std::ostream& printModule(Module* module, std::ostream& o) {
+ PassRunner passRunner(nullptr);
+ passRunner.add<Printer>(o);
+ passRunner.run(module);
+ return o;
+ }
+
+ static std::ostream& printModule(Module* module) {
+ return printModule(module, std::cout);
+ }
-extern std::ostream& printWasm(Expression* expression, std::ostream& o, bool minify = false);
+ static std::ostream& printExpression(Expression* expression, std::ostream& o, bool minify = false);
+};
}
namespace std {
-std::ostream& operator<<(std::ostream& o, wasm::Module* module) {
- return wasm::printWasm(module, o);
+inline std::ostream& operator<<(std::ostream& o, wasm::Module* module) {
+ return wasm::WasmPrinter::printModule(module, o);
}
-std::ostream& operator<<(std::ostream& o, wasm::Expression* expression) {
- return wasm::printWasm(expression, o);
+inline std::ostream& operator<<(std::ostream& o, wasm::Expression* expression) {
+ return wasm::WasmPrinter::printExpression(expression, o);
}
}
diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h
index fb3268877..0d2ecd570 100644
--- a/src/wasm-s-parser.h
+++ b/src/wasm-s-parser.h
@@ -111,6 +111,10 @@ public:
}
return o;
}
+
+ void dump() {
+ std::cout << "dumping " << this << " : " << *this << ".\n";
+ }
};
//