Skip to content

Commit 1c79a6b

Browse files
[WASM_x86] Add description to if and compare visitors
1 parent a7b33cd commit 1c79a6b

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/libasr/codegen/wasm_to_x86.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ class X86Visitor : public WASMDecoder<X86Visitor>,
131131

132132
void visit_If() {
133133
unique_id.push_back(std::to_string(offset));
134+
// `eax` contains the logical value (true = 1, false = 0)
135+
// of the if condition
134136
m_a.asm_pop_r32(X86Reg::eax);
135137
m_a.asm_cmp_r32_imm8(LFortran::X86Reg::eax, 1);
136138
m_a.asm_je_label(".then_" + unique_id.back());
@@ -225,6 +227,7 @@ class X86Visitor : public WASMDecoder<X86Visitor>,
225227
std::string label = std::to_string(offset);
226228
m_a.asm_pop_r32(X86Reg::ebx);
227229
m_a.asm_pop_r32(X86Reg::eax);
230+
// `eax` and `ebx` contain the left and right operands, respectively
228231
m_a.asm_cmp_r32_r32(X86Reg::eax, X86Reg::ebx);
229232
if (compare_op == "Eq") {
230233
m_a.asm_je_label(".compare_1" + label);
@@ -241,6 +244,8 @@ class X86Visitor : public WASMDecoder<X86Visitor>,
241244
} else {
242245
throw CodeGenError("Comparison operator not implemented");
243246
}
247+
// if the `compare` condition in `true`, jump to compare_1
248+
// and assign `1` else assign `0`
244249
m_a.asm_push_imm8(0);
245250
m_a.asm_jmp_label(".compare.end_" + label);
246251
m_a.add_label(".compare_1" + label);

0 commit comments

Comments
 (0)