mirror of https://github.com/colgm/colgm.git
🐛 fix label issue in if/loop statements
This commit is contained in:
parent
62cddc4767
commit
73ec2e8f7e
|
@ -8,6 +8,8 @@ out.ll:
|
|||
test: $(COLGMCC)
|
||||
@ $(COLGMCC) test/assign.colgm
|
||||
@ lli out.ll
|
||||
@ $(COLGMCC) test/branch.colgm
|
||||
@ lli out.ll
|
||||
@ $(COLGMCC) test/func.colgm
|
||||
@ lli out.ll
|
||||
@ $(COLGMCC) test/hello.colgm
|
||||
|
|
|
@ -889,8 +889,9 @@ bool ir_gen::visit_ret_stmt(ret_stmt* node) {
|
|||
}
|
||||
|
||||
bool ir_gen::visit_while_stmt(while_stmt* node) {
|
||||
auto while_begin_label = ircode_block->stmt_size();
|
||||
auto while_begin_label = ircode_block->stmt_size()+1;
|
||||
// condition
|
||||
ircode_block->add_stmt(new sir_br(ircode_block->stmt_size()+1));
|
||||
ircode_block->add_stmt(new sir_label(ircode_block->stmt_size()));
|
||||
|
||||
node->get_condition()->accept(this);
|
||||
|
@ -931,8 +932,9 @@ bool ir_gen::visit_if_stmt(if_stmt* node) {
|
|||
ircode_block->add_stmt(new sir_label(ircode_block->stmt_size()));
|
||||
node->get_block()->accept(this);
|
||||
if (br_cond) {
|
||||
br_cond->set_false_label(ircode_block->stmt_size());
|
||||
br_cond->set_false_label(ircode_block->stmt_size()+1);
|
||||
}
|
||||
ircode_block->add_stmt(new sir_br(ircode_block->stmt_size()+1));
|
||||
ircode_block->add_stmt(new sir_label(ircode_block->stmt_size()));
|
||||
ircode_block->add_nop();
|
||||
return true;
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
func puts(v: i8*) -> i32;
|
||||
|
||||
func main() -> i64 {
|
||||
if (1==1) {
|
||||
puts("1==1");
|
||||
}
|
||||
if (1!=2) {
|
||||
puts("1!=2");
|
||||
}
|
||||
puts(" -> branch.colgm: if statement");
|
||||
|
||||
var a: i64 = 0;
|
||||
while(a<10) {
|
||||
puts("wow!");
|
||||
a += 1;
|
||||
}
|
||||
puts(" -> branch.colgm: loop statement");
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue