From 51a0ffcc0a6bdd205e3979cc147adcf0e1186af4 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Wed, 17 Feb 2016 14:37:06 -0800 Subject: add wasm-printing.h --- test/example/find_div0s.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'test/example/find_div0s.cpp') diff --git a/test/example/find_div0s.cpp b/test/example/find_div0s.cpp index cb29043a7..e74d4781f 100644 --- a/test/example/find_div0s.cpp +++ b/test/example/find_div0s.cpp @@ -8,6 +8,7 @@ #include #include +#include #include using namespace wasm; @@ -34,7 +35,7 @@ int main() { SExpressionWasmBuilder builder(module, *root[0], [&]() { abort(); }); // Print it out - std::cout << module; + printWasm(&module, std::cout); // Search it for divisions by zero: Walk the module, looking for // that operation. @@ -45,7 +46,8 @@ int main() { // Check if the right operand is a constant, and if it is 0 auto right = curr->right->dyn_cast(); if (right && right->value.getInteger() == 0) { - std::cout << "We found that " << curr->left << " is divided by zero\n"; + std::cout << "We found that "; + printWasm(curr->left, std::cout) << " is divided by zero\n"; } } } -- cgit v1.2.3 From 10b929720a8701ef2a960f5b45e39d7a999cca41 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Wed, 17 Feb 2016 16:53:14 -0800 Subject: overload wasm printing in std namespace --- src/wasm-printing.h | 12 ++++++++++++ test/example/find_div0s.cpp | 3 +-- 2 files changed, 13 insertions(+), 2 deletions(-) (limited to 'test/example/find_div0s.cpp') diff --git a/src/wasm-printing.h b/src/wasm-printing.h index d7868d52c..6d8ed7c8a 100644 --- a/src/wasm-printing.h +++ b/src/wasm-printing.h @@ -33,5 +33,17 @@ extern std::ostream& printWasm(Expression* expression, std::ostream& o); } +namespace std { + +std::ostream& operator<<(std::ostream& o, wasm::Module* module) { + return wasm::printWasm(module, o); +} + +std::ostream& operator<<(std::ostream& o, wasm::Expression* expression) { + return wasm::printWasm(expression, o); +} + +} + #endif diff --git a/test/example/find_div0s.cpp b/test/example/find_div0s.cpp index e74d4781f..dc2872edc 100644 --- a/test/example/find_div0s.cpp +++ b/test/example/find_div0s.cpp @@ -46,8 +46,7 @@ int main() { // Check if the right operand is a constant, and if it is 0 auto right = curr->right->dyn_cast(); if (right && right->value.getInteger() == 0) { - std::cout << "We found that "; - printWasm(curr->left, std::cout) << " is divided by zero\n"; + std::cout << "We found that " << curr->left << " is divided by zero\n"; } } } -- cgit v1.2.3