|
|
@ -688,7 +688,7 @@ void IRBuilder::visit(SyntaxTree::UnaryCondExpr &node) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
// FINISH
|
|
|
|
void IRBuilder::visit(SyntaxTree::BinaryCondExpr &node) {
|
|
|
|
void IRBuilder::visit(SyntaxTree::BinaryCondExpr &node) {
|
|
|
|
auto curFunc = builder->get_insert_block()->get_parent();
|
|
|
|
auto curFunc = builder->get_insert_block()->get_parent();
|
|
|
|
auto trueBB = BasicBlock::create(module, "trueBB_and", curFunc);
|
|
|
|
auto trueBB = BasicBlock::create(module, "trueBB_and", curFunc);
|
|
|
@ -697,92 +697,40 @@ void IRBuilder::visit(SyntaxTree::BinaryCondExpr &node) {
|
|
|
|
switch (node.op) {
|
|
|
|
switch (node.op) {
|
|
|
|
case SyntaxTree::BinaryCondOp::LAND:
|
|
|
|
case SyntaxTree::BinaryCondOp::LAND:
|
|
|
|
node.lhs->accept(*this);
|
|
|
|
node.lhs->accept(*this);
|
|
|
|
cond = tmpInst;
|
|
|
|
TypeConvert(tmpInst, INT1_T);
|
|
|
|
builder->create_cond_br(cond, trueBB, falseBB);
|
|
|
|
builder->create_cond_br(tmpInst, trueBB, falseBB);
|
|
|
|
|
|
|
|
|
|
|
|
// True - continue
|
|
|
|
// True - continue
|
|
|
|
builder->set_insert_point(trueBB);
|
|
|
|
builder->set_insert_point(trueBB);
|
|
|
|
node.rhs->accept(*this);
|
|
|
|
node.rhs->accept(*this);
|
|
|
|
cond = tmpInst;
|
|
|
|
TypeConvert(tmpInst, INT1_T);
|
|
|
|
|
|
|
|
|
|
|
|
// False
|
|
|
|
// False
|
|
|
|
builder->set_insert_point(falseBB);
|
|
|
|
builder->set_insert_point(falseBB);
|
|
|
|
tmpInst = cond;
|
|
|
|
TypeConvert(tmpInst, INT1_T);
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case SyntaxTree::BinaryCondOp::LOR:
|
|
|
|
case SyntaxTree::BinaryCondOp::LOR:
|
|
|
|
|
|
|
|
|
|
|
|
node.lhs->accept(*this);
|
|
|
|
node.lhs->accept(*this);
|
|
|
|
cond = tmpInst;
|
|
|
|
TypeConvert(tmpInst, INT1_T);
|
|
|
|
builder->create_cond_br(cond, trueBB, falseBB);
|
|
|
|
builder->create_cond_br(tmpInst, trueBB, falseBB);
|
|
|
|
|
|
|
|
|
|
|
|
// False - continue
|
|
|
|
// False - continue
|
|
|
|
builder->set_insert_point(falseBB);
|
|
|
|
builder->set_insert_point(falseBB);
|
|
|
|
node.rhs->accept(*this);
|
|
|
|
node.rhs->accept(*this);
|
|
|
|
cond = tmpInst;
|
|
|
|
TypeConvert(tmpInst, INT1_T);
|
|
|
|
|
|
|
|
|
|
|
|
// True
|
|
|
|
// True
|
|
|
|
builder->set_insert_point(trueBB);
|
|
|
|
builder->set_insert_point(trueBB);
|
|
|
|
tmpInst = cond;
|
|
|
|
TypeConvert(tmpInst, INT1_T);
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
node.lhs->accept(*this);
|
|
|
|
node.lhs->accept(*this);
|
|
|
|
auto lhs = tmpInst;
|
|
|
|
auto lhs = tmpInst;
|
|
|
|
node.rhs->accept(*this);
|
|
|
|
node.rhs->accept(*this);
|
|
|
|
auto rhs = tmpInst;
|
|
|
|
auto rhs = tmpInst;
|
|
|
|
switch (node.op) {
|
|
|
|
BinaryCondExprGen(lhs, rhs, 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;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|