Finish everything except VarDef

main
Odeinjul 11 months ago
parent c512f5c08e
commit 224e90f5da
No known key found for this signature in database
GPG Key ID: E384228B2B38FFBB

@ -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);
}
}

Loading…
Cancel
Save