From 224e90f5da71852c9660db0012ed8aea33c67ff8 Mon Sep 17 00:00:00 2001 From: Odeinjul Date: Fri, 15 Dec 2023 00:24:32 +0800 Subject: [PATCH] Finish everything except VarDef --- src/SysYFIRBuilder/IRBuilder.cpp | 72 +++++--------------------------- 1 file changed, 10 insertions(+), 62 deletions(-) diff --git a/src/SysYFIRBuilder/IRBuilder.cpp b/src/SysYFIRBuilder/IRBuilder.cpp index 093a320..9102f68 100644 --- a/src/SysYFIRBuilder/IRBuilder.cpp +++ b/src/SysYFIRBuilder/IRBuilder.cpp @@ -688,7 +688,7 @@ void IRBuilder::visit(SyntaxTree::UnaryCondExpr &node) { } -// TODO +// FINISH void IRBuilder::visit(SyntaxTree::BinaryCondExpr &node) { auto curFunc = builder->get_insert_block()->get_parent(); auto trueBB = BasicBlock::create(module, "trueBB_and", curFunc); @@ -697,92 +697,40 @@ void IRBuilder::visit(SyntaxTree::BinaryCondExpr &node) { switch (node.op) { case SyntaxTree::BinaryCondOp::LAND: node.lhs->accept(*this); - cond = tmpInst; - builder->create_cond_br(cond, trueBB, falseBB); + TypeConvert(tmpInst, INT1_T); + builder->create_cond_br(tmpInst, trueBB, falseBB); // True - continue builder->set_insert_point(trueBB); node.rhs->accept(*this); - cond = tmpInst; + TypeConvert(tmpInst, INT1_T); // False builder->set_insert_point(falseBB); - tmpInst = cond; + TypeConvert(tmpInst, INT1_T); break; case SyntaxTree::BinaryCondOp::LOR: node.lhs->accept(*this); - cond = tmpInst; - builder->create_cond_br(cond, trueBB, falseBB); + TypeConvert(tmpInst, INT1_T); + builder->create_cond_br(tmpInst, trueBB, falseBB); // False - continue builder->set_insert_point(falseBB); node.rhs->accept(*this); - cond = tmpInst; + TypeConvert(tmpInst, INT1_T); // True builder->set_insert_point(trueBB); - tmpInst = cond; - + TypeConvert(tmpInst, INT1_T); break; default: node.lhs->accept(*this); auto lhs = tmpInst; node.rhs->accept(*this); auto rhs = tmpInst; - switch (node.op) { - case SyntaxTree::BinaryCondOp::LT: - if (isFloat) { - tmpInst = builder->create_fcmp_lt(lhs, rhs); - } - else { - tmpInst = builder->create_icmp_gt(lhs, rhs); - } - break; - case SyntaxTree::BinaryCondOp::LTE: - if (isFloat) { - tmpInst = builder->create_fcmp_le(lhs, rhs); - } - else { - tmpInst = builder->create_icmp_le(lhs, rhs); - } - break; - case SyntaxTree::BinaryCondOp::GT: - if (isFloat) { - tmpInst = builder->create_fcmp_gt(lhs, rhs); - } - else { - tmpInst = builder->create_icmp_gt(lhs, rhs); - } - break; - case SyntaxTree::BinaryCondOp::GTE: - if (isFloat) { - tmpInst = builder->create_fcmp_ge(lhs, rhs); - } - else { - tmpInst = builder->create_icmp_ge(lhs, rhs); - } - break; - case SyntaxTree::BinaryCondOp::EQ: - if (isFloat) { - tmpInst = builder->create_fcmp_eq(lhs, rhs); - } - else { - tmpInst = builder->create_icmp_eq(lhs, rhs); - } - break; - case SyntaxTree::BinaryCondOp::NEQ: - if (isFloat) { - tmpInst = builder->create_fcmp_ne(lhs, rhs); - } - else { - tmpInst = builder->create_icmp_ne(lhs, rhs); - } - break; - default: - break; - } + BinaryCondExprGen(lhs, rhs, node.op); } }