@@ -34,6 +34,7 @@ class X86Visitor : public WASMDecoder<X86Visitor>,
34
34
uint32_t cur_func_idx;
35
35
std::vector<std::string> if_unique_id;
36
36
std::vector<std::string> loop_unique_id;
37
+ uint32_t cur_nesting_length;
37
38
int32_t last_vis_i32_const, last_last_vis_i32_const;
38
39
std::unordered_map<int32_t , std::string> loc_to_str;
39
40
@@ -43,6 +44,7 @@ class X86Visitor : public WASMDecoder<X86Visitor>,
43
44
BaseWASMVisitor (code, 0U /* temporary offset */ ),
44
45
m_a(m_a) {
45
46
wasm_bytes.from_pointer_n (code.data (), code.size ());
47
+ cur_nesting_length = 0 ;
46
48
}
47
49
48
50
void visit_Unreachable () {}
@@ -132,7 +134,8 @@ class X86Visitor : public WASMDecoder<X86Visitor>,
132
134
133
135
void visit_Br (uint32_t label_index) {
134
136
// Branch is used to jump to the `loop.head` or `loop.end`.
135
- if (if_unique_id.size () - loop_unique_id.size () == label_index - 1 ) {
137
+ if (loop_unique_id.size () + if_unique_id.size () - cur_nesting_length
138
+ == label_index + 1 ) {
136
139
// cycle/continue or loop.end
137
140
m_a.asm_jmp_label (" .loop.head_" + loop_unique_id.back ());
138
141
} else {
@@ -142,6 +145,8 @@ class X86Visitor : public WASMDecoder<X86Visitor>,
142
145
}
143
146
144
147
void visit_Loop () {
148
+ uint32_t prev_nesting_length = cur_nesting_length;
149
+ cur_nesting_length = loop_unique_id.size () + if_unique_id.size ();
145
150
loop_unique_id.push_back (std::to_string (offset));
146
151
/*
147
152
The loop statement starts with `loop.head`. The `loop.body` and
@@ -162,6 +167,7 @@ class X86Visitor : public WASMDecoder<X86Visitor>,
162
167
// end
163
168
m_a.add_label (" .loop.end_" + loop_unique_id.back ());
164
169
loop_unique_id.pop_back ();
170
+ cur_nesting_length = prev_nesting_length;
165
171
}
166
172
167
173
void visit_If () {
0 commit comments