0
0
Fork 0
mirror of https://git.code.sf.net/p/quake/quakeforge synced 2025-02-27 22:21:00 +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:
Bill Currie 2011-01-13 00:46:46 +09:00
parent 3c9991364b
commit 638f4445cc
2 changed files with 13 additions and 3 deletions
tools/qfcc/source

View file

@ -877,7 +877,7 @@ emit_expr (expr_t *e)
def = 0; def = 0;
if (e->e.expr.e1) if (e->e.expr.e1)
def = emit_sub_expr (e->e.expr.e1, 0); 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); emit_statement (e, op_return_v, 0, 0, 0);
else else
emit_statement (e, op_return, def, 0, 0); emit_statement (e, op_return, def, 0, 0);

View file

@ -543,6 +543,8 @@ finish_function (function_t *f)
void void
emit_function (function_t *f, expr_t *e) emit_function (function_t *f, expr_t *e)
{ {
int last_is_label = 0;
dstatement_t *s;
//#define DUMP_EXPR //#define DUMP_EXPR
#ifdef DUMP_EXPR #ifdef DUMP_EXPR
printf (" %s =\n", f->def->name); printf (" %s =\n", f->def->name);
@ -563,11 +565,19 @@ emit_function (function_t *f, expr_t *e)
print_expr (e); print_expr (e);
puts(""); puts("");
#endif #endif
last_is_label = (e->type == ex_label);
emit_expr (e); emit_expr (e);
e = e->next; e = e->next;
} }
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); emit_statement (0, op_done, 0, 0, 0);
}
flush_scope (current_scope, 0); flush_scope (current_scope, 0);
current_scope = pr.scope; current_scope = pr.scope;
reset_tempdefs (); reset_tempdefs ();