blob: b96235cb6cae56cdac2ad5f49a325c0c2ffdb7fe (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
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);
}
|