@@ -34,6 +34,7 @@ class X86Visitor : public WASMDecoder<X86Visitor>,
3434    uint32_t  cur_func_idx;
3535    std::vector<std::string> if_unique_id;
3636    std::vector<std::string> loop_unique_id;
37+     uint32_t  cur_nesting_length;
3738    int32_t  last_vis_i32_const, last_last_vis_i32_const;
3839    std::unordered_map<int32_t , std::string> loc_to_str;
3940
@@ -43,6 +44,7 @@ class X86Visitor : public WASMDecoder<X86Visitor>,
4344          BaseWASMVisitor (code, 0U  /*  temporary offset */ 
4445          m_a(m_a) {
4546        wasm_bytes.from_pointer_n (code.data (), code.size ());
47+         cur_nesting_length = 0 ;
4648    }
4749
4850    void  visit_Unreachable () {}
@@ -132,7 +134,8 @@ class X86Visitor : public WASMDecoder<X86Visitor>,
132134
133135    void  visit_Br (uint32_t  label_index) {
134136        //  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 ) {
136139            //  cycle/continue or loop.end
137140            m_a.asm_jmp_label (" .loop.head_" back ());
138141        } else  {
@@ -142,6 +145,8 @@ class X86Visitor : public WASMDecoder<X86Visitor>,
142145    }
143146
144147    void  visit_Loop () {
148+         uint32_t  prev_nesting_length = cur_nesting_length;
149+         cur_nesting_length = loop_unique_id.size () + if_unique_id.size ();
145150        loop_unique_id.push_back (std::to_string (offset));
146151        /* 
147152        The loop statement starts with `loop.head`. The `loop.body` and 
@@ -162,6 +167,7 @@ class X86Visitor : public WASMDecoder<X86Visitor>,
162167        //  end
163168        m_a.add_label (" .loop.end_" back ());
164169        loop_unique_id.pop_back ();
170+         cur_nesting_length = prev_nesting_length;
165171    }
166172
167173    void  visit_If () {
0 commit comments