diff options
author | Alon Zakai <azakai@google.com> | 2023-07-20 15:39:51 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-20 15:39:51 -0700 |
commit | 0d79590340237214bccfca6a73ad11b3728f26fc (patch) | |
tree | 330e7f5bdf6c4c05a7cf8ba0aba2f6ec3a973976 | |
parent | 01f5eb8cf7d280e12985e628041ba57f9f8402d1 (diff) | |
download | binaryen-0d79590340237214bccfca6a73ad11b3728f26fc.tar.gz binaryen-0d79590340237214bccfca6a73ad11b3728f26fc.tar.bz2 binaryen-0d79590340237214bccfca6a73ad11b3728f26fc.zip |
Add support for debug printing of functions (#5828)
-rw-r--r-- | src/passes/Print.cpp | 8 | ||||
-rw-r--r-- | src/wasm.h | 1 | ||||
-rw-r--r-- | test/gtest/CMakeLists.txt | 1 | ||||
-rw-r--r-- | test/gtest/printing.cpp | 44 |
4 files changed, 54 insertions, 0 deletions
diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp index 67d0dbdcc..e9facd5a9 100644 --- a/src/passes/Print.cpp +++ b/src/passes/Print.cpp @@ -3763,6 +3763,14 @@ std::ostream& operator<<(std::ostream& o, wasm::Module& module) { return o; } +std::ostream& operator<<(std::ostream& o, wasm::Function& func) { + wasm::PrintSExpression print(o); + print.setMinify(false); + print.setDebugInfo(false); + print.visitFunction(&func); + return o; +} + std::ostream& operator<<(std::ostream& o, wasm::Expression& expression) { return wasm::printExpression(&expression, o); } diff --git a/src/wasm.h b/src/wasm.h index afb824bdd..c059009b6 100644 --- a/src/wasm.h +++ b/src/wasm.h @@ -2330,6 +2330,7 @@ template<> struct hash<wasm::Address> { }; std::ostream& operator<<(std::ostream& o, wasm::Module& module); +std::ostream& operator<<(std::ostream& o, wasm::Function& func); std::ostream& operator<<(std::ostream& o, wasm::Expression& expression); std::ostream& operator<<(std::ostream& o, wasm::ModuleExpression pair); std::ostream& operator<<(std::ostream& o, wasm::ShallowExpression expression); diff --git a/test/gtest/CMakeLists.txt b/test/gtest/CMakeLists.txt index d3663bf63..f7824834a 100644 --- a/test/gtest/CMakeLists.txt +++ b/test/gtest/CMakeLists.txt @@ -5,6 +5,7 @@ set(unittest_SOURCES cfg.cpp dfa_minimization.cpp possible-contents.cpp + printing.cpp stringify.cpp suffix_tree.cpp type-builder.cpp diff --git a/test/gtest/printing.cpp b/test/gtest/printing.cpp new file mode 100644 index 000000000..312597886 --- /dev/null +++ b/test/gtest/printing.cpp @@ -0,0 +1,44 @@ +#include "print-test.h" + +#include "wasm.h" + +using namespace wasm; + +using PrintingTest = PrintTest; + +TEST_F(PrintingTest, Print) { + auto moduleText = R"wasm( + (module + (func $a (result i32) + (i32.const 10) + ) + (func $b + (drop + (i32.const 20) + ) + ) + ) + )wasm"; + + Module wasm; + parseWast(wasm, moduleText); + + { + std::stringstream ss; + ss << *wasm.getFunction("a"); + EXPECT_EQ(ss.str(), R"print((func $a (result i32) + (i32.const 10) +) +)print"); + } + { + std::stringstream ss; + ss << *wasm.getFunction("b"); + EXPECT_EQ(ss.str(), R"print((func $b + (drop + (i32.const 20) + ) +) +)print"); + } +} |