main
Odeinjul 11 months ago
parent e5754f92b9
commit 024aad74f2
No known key found for this signature in database
GPG Key ID: E384228B2B38FFBB

@ -638,11 +638,13 @@ void IRBuilder::visit(SyntaxTree::UnaryCondExpr &node) {
// FINISH
void IRBuilder::visit(SyntaxTree::BinaryCondExpr &node) {
auto curFunc = builder->get_insert_block()->get_parent();
auto trueBB = BasicBlock::create(module, "trueBB_and", curFunc);
auto falseBB = BasicBlock::create(module, "falseBB_and", curFunc);
Ptr<BasicBlock> trueBB;
Ptr<BasicBlock> falseBB;
Ptr<Instruction> cond;
switch (node.op) {
case SyntaxTree::BinaryCondOp::LAND:
trueBB = BasicBlock::create(module, "trueBB_and", curFunc);
falseBB = BasicBlock::create(module, "falseBB_and", curFunc);
node.lhs->accept(*this);
TypeConvert(tmpInst, INT1_T);
builder->create_cond_br(tmpInst, trueBB, falseBB);
@ -658,7 +660,8 @@ void IRBuilder::visit(SyntaxTree::BinaryCondExpr &node) {
break;
case SyntaxTree::BinaryCondOp::LOR:
trueBB = BasicBlock::create(module, "trueBB_and", curFunc);
falseBB = BasicBlock::create(module, "falseBB_and", curFunc);
node.lhs->accept(*this);
TypeConvert(tmpInst, INT1_T);
builder->create_cond_br(tmpInst, trueBB, falseBB);
@ -738,7 +741,7 @@ void IRBuilder::visit(SyntaxTree::IfStmt &node) {
auto curFunc = builder->get_insert_block()->get_parent();
auto trueBB = BasicBlock::create(module, "trueBB_if", curFunc);
auto falseBB = BasicBlock::create(module, "falseBB_if", curFunc);
auto exitBB = node.else_statement == nullptr ? falseBB : BasicBlock::create(module, "exitBB_if", curFunc);
auto afterBB = node.else_statement == nullptr ? falseBB : BasicBlock::create(module, "afterBB_if", curFunc);
node.cond_exp->accept(*this);
@ -747,15 +750,16 @@ void IRBuilder::visit(SyntaxTree::IfStmt &node) {
builder->set_insert_point(trueBB);
node.if_statement->accept(*this);
builder->create_br(exitBB);
if (builder->get_insert_block()->get_terminator() == nullptr)
builder->create_br(afterBB);
if (node.else_statement) {
builder->set_insert_point(falseBB);
node.else_statement->accept(*this);
builder->create_br(exitBB);
builder->create_br(afterBB);
}
if (!exitBB->get_pre_basic_blocks().empty()) {
builder->set_insert_point(exitBB);
if (!afterBB->get_pre_basic_blocks().empty()) {
builder->set_insert_point(afterBB);
}
}

Loading…
Cancel
Save