@@ -131,6 +131,8 @@ class X86Visitor : public WASMDecoder<X86Visitor>,
131
131
132
132
void visit_If () {
133
133
unique_id.push_back (std::to_string (offset));
134
+ // `eax` contains the logical value (true = 1, false = 0)
135
+ // of the if condition
134
136
m_a.asm_pop_r32 (X86Reg::eax);
135
137
m_a.asm_cmp_r32_imm8 (LFortran::X86Reg::eax, 1 );
136
138
m_a.asm_je_label (" .then_" + unique_id.back ());
@@ -225,6 +227,7 @@ class X86Visitor : public WASMDecoder<X86Visitor>,
225
227
std::string label = std::to_string (offset);
226
228
m_a.asm_pop_r32 (X86Reg::ebx);
227
229
m_a.asm_pop_r32 (X86Reg::eax);
230
+ // `eax` and `ebx` contain the left and right operands, respectively
228
231
m_a.asm_cmp_r32_r32 (X86Reg::eax, X86Reg::ebx);
229
232
if (compare_op == " Eq" ) {
230
233
m_a.asm_je_label (" .compare_1" + label);
@@ -241,6 +244,8 @@ class X86Visitor : public WASMDecoder<X86Visitor>,
241
244
} else {
242
245
throw CodeGenError (" Comparison operator not implemented" );
243
246
}
247
+ // if the `compare` condition in `true`, jump to compare_1
248
+ // and assign `1` else assign `0`
244
249
m_a.asm_push_imm8 (0 );
245
250
m_a.asm_jmp_label (" .compare.end_" + label);
246
251
m_a.add_label (" .compare_1" + label);
0 commit comments