summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2016-02-17 14:37:06 -0800
committerAlon Zakai <alonzakai@gmail.com>2016-02-17 14:50:00 -0800
commit51a0ffcc0a6bdd205e3979cc147adcf0e1186af4 (patch)
tree6d7e11b355c6f417ed567d0c9349d0cee25f7e3c /src
parentdbb5f32bafcf3c8f51eefb95e6c298ce6b9ac8cc (diff)
downloadbinaryen-51a0ffcc0a6bdd205e3979cc147adcf0e1186af4.tar.gz
binaryen-51a0ffcc0a6bdd205e3979cc147adcf0e1186af4.tar.bz2
binaryen-51a0ffcc0a6bdd205e3979cc147adcf0e1186af4.zip
add wasm-printing.h
Diffstat (limited to 'src')
-rw-r--r--src/asm2wasm-main.cpp1
-rw-r--r--src/binaryen-shell.cpp1
-rw-r--r--src/pass.h8
-rw-r--r--src/passes/Print.cpp10
-rw-r--r--src/s2wasm-main.cpp1
-rw-r--r--src/s2wasm.h1
-rw-r--r--src/wasm-dis.cpp2
-rw-r--r--src/wasm-printing.h37
8 files changed, 51 insertions, 10 deletions
diff --git a/src/asm2wasm-main.cpp b/src/asm2wasm-main.cpp
index 3c1377c08..aa914c168 100644
--- a/src/asm2wasm-main.cpp
+++ b/src/asm2wasm-main.cpp
@@ -21,6 +21,7 @@
#include "support/colors.h"
#include "support/command-line.h"
#include "support/file.h"
+#include "wasm-printing.h"
#include "asm2wasm.h"
diff --git a/src/binaryen-shell.cpp b/src/binaryen-shell.cpp
index 1b0bf8f78..a9a9ea1da 100644
--- a/src/binaryen-shell.cpp
+++ b/src/binaryen-shell.cpp
@@ -26,6 +26,7 @@
#include "support/command-line.h"
#include "support/file.h"
#include "wasm-interpreter.h"
+#include "wasm-printing.h"
#include "wasm-s-parser.h"
#include "wasm-validator.h"
diff --git a/src/pass.h b/src/pass.h
index 250ba59b2..53b486e41 100644
--- a/src/pass.h
+++ b/src/pass.h
@@ -165,14 +165,6 @@ public:
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
diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp
index 14cb929c5..a5014d034 100644
--- a/src/passes/Print.cpp
+++ b/src/passes/Print.cpp
@@ -470,7 +470,7 @@ struct PrintSExpression : public WasmVisitor<PrintSExpression, void> {
}
};
-// Main entry point. Eventually this will direct printing to one of various options.
+// Pass entry point. Eventually this will direct printing to one of various options.
void Printer::run(PassRunner* runner, Module* module) {
PrintSExpression print(o);
@@ -479,4 +479,12 @@ void Printer::run(PassRunner* runner, Module* module) {
static RegisterPass<Printer> registerPass("print", "print in s-expression format");
+// Print individual expressions
+
+std::ostream& printWasm(Expression* expression, std::ostream& o) {
+ PrintSExpression print(o);
+ print.visit(expression);
+ return o;
+}
+
} // namespace wasm
diff --git a/src/s2wasm-main.cpp b/src/s2wasm-main.cpp
index 377d44c52..d7a18f547 100644
--- a/src/s2wasm-main.cpp
+++ b/src/s2wasm-main.cpp
@@ -22,6 +22,7 @@
#include "support/command-line.h"
#include "support/file.h"
#include "s2wasm.h"
+#include "wasm-printing.h"
using namespace cashew;
using namespace wasm;
diff --git a/src/s2wasm.h b/src/s2wasm.h
index 9c875ea9e..0520d5c3b 100644
--- a/src/s2wasm.h
+++ b/src/s2wasm.h
@@ -27,6 +27,7 @@
#include "parsing.h"
#include "pass.h"
#include "asm_v_wasm.h"
+#include "wasm-printing.h"
namespace wasm {
diff --git a/src/wasm-dis.cpp b/src/wasm-dis.cpp
index c7ebf8861..7486e0bbd 100644
--- a/src/wasm-dis.cpp
+++ b/src/wasm-dis.cpp
@@ -18,11 +18,11 @@
// wasm2asm console tool
//
-#include "pass.h"
#include "support/colors.h"
#include "support/command-line.h"
#include "support/file.h"
#include "wasm-binary.h"
+#include "wasm-printing.h"
using namespace cashew;
using namespace wasm;
diff --git a/src/wasm-printing.h b/src/wasm-printing.h
new file mode 100644
index 000000000..d7868d52c
--- /dev/null
+++ b/src/wasm-printing.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2016 WebAssembly Community Group participants
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __wasm_printing_h__
+#define __wasm_printing_h__
+
+#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;
+}
+
+extern std::ostream& printWasm(Expression* expression, std::ostream& o);
+
+}
+
+#endif
+