Skip to content

Commit

Permalink
Update asr_to_x86.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
namannimmo10 committed Jun 24, 2022
1 parent 4f4bb3a commit 3fb8922
Showing 1 changed file with 33 additions and 39 deletions.
72 changes: 33 additions & 39 deletions src/libasr/codegen/asr_to_x86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ class ASRToX86Visitor : public ASR::BaseVisitor<ASRToX86Visitor>
m_a.asm_neg_r32(X86Reg::eax);
}

void visit_Compare(const ASR::Compare_t &x) {
void visit_IntegerCompare(const ASR::IntegerCompare_t &x) {
std::string id = std::to_string(get_hash((ASR::asr_t*)&x));
this->visit_expr(*x.m_right);
m_a.asm_push_r32(X86Reg::eax);
Expand All @@ -348,46 +348,40 @@ class ASRToX86Visitor : public ASR::BaseVisitor<ASRToX86Visitor>
// The left operand is in eax, the right operand is in ecx
// Leave the result in eax.
m_a.asm_cmp_r32_r32(X86Reg::eax, X86Reg::ecx);
LFORTRAN_ASSERT(LFortran::ASRUtils::expr_type(x.m_left)->type == LFortran::ASRUtils::expr_type(x.m_right)->type);
ASR::ttypeType optype = LFortran::ASRUtils::expr_type(x.m_left)->type;
if (optype == ASR::ttypeType::Integer) {
switch (x.m_op) {
case (ASR::cmpopType::Eq) : {
m_a.asm_je_label(".compare1" + id);
break;
}
case (ASR::cmpopType::Gt) : {
m_a.asm_jg_label(".compare1" + id);
break;
}
case (ASR::cmpopType::GtE) : {
m_a.asm_jge_label(".compare1" + id);
break;
}
case (ASR::cmpopType::Lt) : {
m_a.asm_jl_label(".compare1" + id);
break;
}
case (ASR::cmpopType::LtE) : {
m_a.asm_jle_label(".compare1" + id);
break;
}
case (ASR::cmpopType::NotEq) : {
m_a.asm_jne_label(".compare1" + id);
break;
}
default : {
throw CodeGenError("Comparison operator not implemented");
}
switch (x.m_op) {
case (ASR::cmpopType::Eq) : {
m_a.asm_je_label(".compare1" + id);
break;
}
case (ASR::cmpopType::Gt) : {
m_a.asm_jg_label(".compare1" + id);
break;
}
case (ASR::cmpopType::GtE) : {
m_a.asm_jge_label(".compare1" + id);
break;
}
case (ASR::cmpopType::Lt) : {
m_a.asm_jl_label(".compare1" + id);
break;
}
case (ASR::cmpopType::LtE) : {
m_a.asm_jle_label(".compare1" + id);
break;
}
case (ASR::cmpopType::NotEq) : {
m_a.asm_jne_label(".compare1" + id);
break;
}
default : {
throw CodeGenError("Comparison operator not implemented");
}
m_a.asm_mov_r32_imm32(X86Reg::eax, 0);
m_a.asm_jmp_label(".compareend" + id);
m_a.add_label(".compare1" + id);
m_a.asm_mov_r32_imm32(X86Reg::eax, 1);
m_a.add_label(".compareend" + id);
} else {
throw CodeGenError("Only Integer implemented in Compare");
}
m_a.asm_mov_r32_imm32(X86Reg::eax, 0);
m_a.asm_jmp_label(".compareend" + id);
m_a.add_label(".compare1" + id);
m_a.asm_mov_r32_imm32(X86Reg::eax, 1);
m_a.add_label(".compareend" + id);
}

void visit_Assignment(const ASR::Assignment_t &x) {
Expand Down

0 comments on commit 3fb8922

Please sign in to comment.