More return code cleanup.

Don't use the true void return in traditional mode.
Prefer the true void return over "done" at the end of functions.
Don't emit the above if the last emitted statement is a return and there is
no label at the end of the function.
This commit is contained in:
Bill Currie 2011-01-13 00:46:46 +09:00
parent 3c9991364b
commit 638f4445cc
2 changed files with 13 additions and 3 deletions

View file

@ -877,7 +877,7 @@ emit_expr (expr_t *e)
def = 0;
if (e->e.expr.e1)
def = emit_sub_expr (e->e.expr.e1, 0);
if (!def && op_return_v)
if (!def && !options.traditional && op_return_v)
emit_statement (e, op_return_v, 0, 0, 0);
else
emit_statement (e, op_return, def, 0, 0);

View file

@ -543,6 +543,8 @@ finish_function (function_t *f)
void
emit_function (function_t *f, expr_t *e)
{
int last_is_label = 0;
dstatement_t *s;
//#define DUMP_EXPR
#ifdef DUMP_EXPR
printf (" %s =\n", f->def->name);
@ -563,11 +565,19 @@ emit_function (function_t *f, expr_t *e)
print_expr (e);
puts("");
#endif
last_is_label = (e->type == ex_label);
emit_expr (e);
e = e->next;
}
emit_statement (0, op_done, 0, 0, 0);
s = &pr.code->code[pr.code->size - 1];
if (last_is_label
|| !(s->op == op_return->opcode
|| (op_return_v && s->op == op_return_v->opcode))) {
if (!options.traditional && op_return_v)
emit_statement (0, op_return_v, 0, 0, 0);
else
emit_statement (0, op_done, 0, 0, 0);
}
flush_scope (current_scope, 0);
current_scope = pr.scope;
reset_tempdefs ();