diff options
author | Ashley Nelson <nashley@google.com> | 2023-06-30 11:45:03 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-30 11:45:03 -0700 |
commit | ef7f98e50662374b17d88c149a2ba1c11f918e5c (patch) | |
tree | 4d3579f61e7d57dda7de65f0d32da5a50cbbb22f /test/gtest | |
parent | 69da5f084fb6f624a9e731b122b53855fadd7d4a (diff) | |
download | binaryen-ef7f98e50662374b17d88c149a2ba1c11f918e5c.tar.gz binaryen-ef7f98e50662374b17d88c149a2ba1c11f918e5c.tar.bz2 binaryen-ef7f98e50662374b17d88c149a2ba1c11f918e5c.zip |
[Outlining] StringifyWalker (#5772)
StringifyWalker is a new Walker with UnifiedExpressionVisitor. This walker performs a shallow visit of control-flow (try, if, block, loop) expressions and their simple expression siblings before then visiting the children of each control-flow expression in postorder. As a result, this walker un-nests nested control flow structures, so the expression visit order does not correspond to a normal postorder traversal of the function.
Diffstat (limited to 'test/gtest')
-rw-r--r-- | test/gtest/CMakeLists.txt | 1 | ||||
-rw-r--r-- | test/gtest/stringify.cpp | 127 |
2 files changed, 128 insertions, 0 deletions
diff --git a/test/gtest/CMakeLists.txt b/test/gtest/CMakeLists.txt index 27b7be621..5523bcb00 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 + stringify.cpp type-builder.cpp wat-lexer.cpp ) diff --git a/test/gtest/stringify.cpp b/test/gtest/stringify.cpp new file mode 100644 index 000000000..b96235cb6 --- /dev/null +++ b/test/gtest/stringify.cpp @@ -0,0 +1,127 @@ +#include "ir/utils.h" +#include "passes/stringify-walker.h" +#include "print-test.h" +#include "wasm.h" +#include "gtest/gtest.h" + +using namespace wasm; + +using StringifyTest = PrintTest; + +TEST_F(StringifyTest, Print) { + auto moduleText = R"wasm( + (module + (tag $catch_a (param i32)) + (tag $catch_b (param i32)) + (tag $catch_c (param i32)) + (func $d + (block $block_a + (drop (i32.const 20)) + (drop (i32.const 10)) + ) + (block $block_b + (drop (if (i32.const 0) + (i32.const 40) + (i32.const 5) + )) + ) + (block $block_c + (drop (if (i32.const 1) + (i32.const 30) + )) + ) + (block $block_d + (try $try_a + (do + (nop) + ) + (catch $catch_a + (drop (i32.const 8)) + ) + (catch $catch_b + (drop (i32.const 15)) + ) + ) + ) + (block $block_e + (try $try_b + (do + (nop) + ) + (catch $catch_c + (drop (i32.const 33)) + ) + ) + ) + ) + ) + )wasm"; + + auto stringifyText = R"stringify(in visitExpression for block +adding unique symbol +in visitExpression for block $block_a +in visitExpression for block $block_b +in visitExpression for block $block_c +in visitExpression for block $block_d +in visitExpression for block $block_e +adding unique symbol +in visitExpression for i32.const 20 +in visitExpression for drop +in visitExpression for i32.const 10 +in visitExpression for drop +adding unique symbol +in visitExpression for i32.const 0 +in visitExpression for if +in visitExpression for drop +adding unique symbol +in visitExpression for i32.const 1 +in visitExpression for if +in visitExpression for drop +adding unique symbol +in visitExpression for try $try_a +adding unique symbol +in visitExpression for try $try_b +adding unique symbol +in visitExpression for i32.const 40 +adding unique symbol +in visitExpression for i32.const 5 +adding unique symbol +in visitExpression for i32.const 30 +adding unique symbol +in visitExpression for nop +adding unique symbol +in visitExpression for i32.const 8 +in visitExpression for drop +adding unique symbol +in visitExpression for i32.const 15 +in visitExpression for drop +adding unique symbol +in visitExpression for nop +adding unique symbol +in visitExpression for i32.const 33 +in visitExpression for drop +adding unique symbol +)stringify"; + + struct TestStringifyWalker : public StringifyWalker<TestStringifyWalker> { + std::ostream& os; + + TestStringifyWalker(std::ostream& os) : os(os){}; + + void addUniqueSymbol() { os << "adding unique symbol\n"; } + + void visitExpression(Expression* curr) { + os << "in visitExpression for " << ShallowExpression{curr, getModule()} + << std::endl; + } + }; + + Module wasm; + parseWast(wasm, moduleText); + + std::stringstream ss; + TestStringifyWalker stringify = TestStringifyWalker(ss); + stringify.walkModule(&wasm); + + EXPECT_EQ(ss.str(), stringifyText); +} |