Skip to content

Commit 5f38adc

Browse files
[WASM_x86] Implement Break and Continue statements
1 parent bc64ef4 commit 5f38adc

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/libasr/codegen/wasm_to_x86.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,15 @@ class X86Visitor : public WASMDecoder<X86Visitor>,
130130

131131
void visit_EmtpyBlockType() {}
132132

133-
void visit_Br(uint32_t /*label_index*/) {
134-
// Branch is used to jump to the `loop.head`.
135-
m_a.asm_jmp_label(".loop.head_" + unique_id.rbegin()[1]);
133+
void visit_Br(uint32_t label_index) {
134+
// 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) {
136+
// cycle/continue or loop.end
137+
m_a.asm_jmp_label(".loop.head_" + loop_unique_id.back());
138+
} else {
139+
// exit/break
140+
m_a.asm_jmp_label(".loop.end_" + loop_unique_id.back());
141+
}
136142
}
137143

138144
void visit_Loop() {

0 commit comments

Comments
 (0)