Skip to content

Commit bc64ef4

Browse files
[WASM_x86] Use different variable to store loop_unique_id
1 parent 580c1f3 commit bc64ef4

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

src/libasr/codegen/wasm_to_x86.cpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ class X86Visitor : public WASMDecoder<X86Visitor>,
3232
public:
3333
X86Assembler &m_a;
3434
uint32_t cur_func_idx;
35-
std::vector<std::string> unique_id;
35+
std::vector<std::string> if_unique_id;
36+
std::vector<std::string> loop_unique_id;
3637
int32_t last_vis_i32_const, last_last_vis_i32_const;
3738
std::unordered_map<int32_t, std::string> loc_to_str;
3839

@@ -135,7 +136,7 @@ class X86Visitor : public WASMDecoder<X86Visitor>,
135136
}
136137

137138
void visit_Loop() {
138-
unique_id.push_back(std::to_string(offset));
139+
loop_unique_id.push_back(std::to_string(offset));
139140
/*
140141
The loop statement starts with `loop.head`. The `loop.body` and
141142
`loop.branch` are enclosed within the `if.block`. If the condition
@@ -148,34 +149,34 @@ class X86Visitor : public WASMDecoder<X86Visitor>,
148149
.endIf
149150
.end
150151
*/
151-
m_a.add_label(".loop.head_" + unique_id.back());
152+
m_a.add_label(".loop.head_" + loop_unique_id.back());
152153
{
153154
decode_instructions();
154155
}
155156
// end
156-
m_a.add_label(".loop.end_" + unique_id.back());
157-
unique_id.pop_back();
157+
m_a.add_label(".loop.end_" + loop_unique_id.back());
158+
loop_unique_id.pop_back();
158159
}
159160

160161
void visit_If() {
161-
unique_id.push_back(std::to_string(offset));
162+
if_unique_id.push_back(std::to_string(offset));
162163
// `eax` contains the logical value (true = 1, false = 0)
163164
// of the if condition
164165
m_a.asm_pop_r32(X86Reg::eax);
165166
m_a.asm_cmp_r32_imm8(LFortran::X86Reg::eax, 1);
166-
m_a.asm_je_label(".then_" + unique_id.back());
167-
m_a.asm_jmp_label(".else_" + unique_id.back());
168-
m_a.add_label(".then_" + unique_id.back());
167+
m_a.asm_je_label(".then_" + if_unique_id.back());
168+
m_a.asm_jmp_label(".else_" + if_unique_id.back());
169+
m_a.add_label(".then_" + if_unique_id.back());
169170
{
170171
decode_instructions();
171172
}
172-
m_a.add_label(".endif_" + unique_id.back());
173-
unique_id.pop_back();
173+
m_a.add_label(".endif_" + if_unique_id.back());
174+
if_unique_id.pop_back();
174175
}
175176

176177
void visit_Else() {
177-
m_a.asm_jmp_label(".endif_" + unique_id.back());
178-
m_a.add_label(".else_" + unique_id.back());
178+
m_a.asm_jmp_label(".endif_" + if_unique_id.back());
179+
m_a.add_label(".else_" + if_unique_id.back());
179180
}
180181

181182
void visit_LocalGet(uint32_t localidx) {

0 commit comments

Comments
 (0)