Move the output block of a loop to after the loop, otherwise IR dumps looks just messy... note that this is merely a cosmetic change

This commit is contained in:
Wolfgang (Blub) Bumiller 2012-05-04 10:01:38 +02:00
parent 6b52c66d11
commit 2f92dedb4c

12
ast.c
View file

@ -939,6 +939,9 @@ bool ast_loop_codegen(ast_loop *self, ast_function *func, bool lvalue, ir_value
ir_block *bincrement, *end_bincrement;
ir_block *bout, *bin;
/* let's at least move the outgoing block to the end */
size_t bout_id;
/* 'break' and 'continue' need to be able to find the right blocks */
ir_block *bcontinue = NULL;
ir_block *bbreak = NULL;
@ -1014,6 +1017,7 @@ bool ast_loop_codegen(ast_loop *self, ast_function *func, bool lvalue, ir_value
bpostcond = end_bpostcond = NULL;
}
bout_id = func->ir_func->blocks_count;
bout = ir_function_create_block(func->ir_func, ast_function_label(func, "after_loop"));
if (!bout)
return false;
@ -1135,5 +1139,13 @@ bool ast_loop_codegen(ast_loop *self, ast_function *func, bool lvalue, ir_value
return false;
}
/* Move 'bout' to the end */
if (!ir_function_blocks_remove(func->ir_func, bout_id) ||
!ir_function_blocks_add(func->ir_func, bout))
{
ir_block_delete(bout);
return false;
}
return true;
}