mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-01-18 15:01:41 +00:00
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:
parent
3c9991364b
commit
638f4445cc
2 changed files with 13 additions and 3 deletions
|
@ -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);
|
||||
|
|
|
@ -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 ();
|
||||
|
|
Loading…
Reference in a new issue