mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-22 20:41:20 +00:00
better code generation for foo(bar(baz)). foo(snafu,bar(baz)) isn't optimal
yet, but the code is at least correct
This commit is contained in:
parent
eeec89e6ba
commit
08f73bed78
2 changed files with 26 additions and 6 deletions
|
@ -388,6 +388,13 @@ emit_expr (expr_t *e)
|
|||
def_b = emit_sub_expr (e->e.expr.e2, 0);
|
||||
emit_statement (e->line, op_state, def_a, def_b, 0);
|
||||
break;
|
||||
case 'b':
|
||||
if (!e->e.expr.e2 || e->e.expr.e2->type != ex_temp) {
|
||||
error (e, "internal error");
|
||||
abort ();
|
||||
}
|
||||
e->e.expr.e2->e.temp.def = emit_sub_expr (e->e.expr.e1, e->e.expr.e2->e.temp.def);
|
||||
break;
|
||||
default:
|
||||
warning (e, "Ignoring useless expression");
|
||||
break;
|
||||
|
|
|
@ -332,6 +332,10 @@ print_expr (expr_t *e)
|
|||
p = p->next;
|
||||
}
|
||||
printf (")");
|
||||
} else if (e->e.expr.op == 'b') {
|
||||
print_expr (e->e.expr.e1);
|
||||
printf ("<-->");
|
||||
print_expr (e->e.expr.e2);
|
||||
} else {
|
||||
print_expr (e->e.expr.e2);
|
||||
printf (" %s", get_op_string (e->e.expr.op));
|
||||
|
@ -1106,24 +1110,33 @@ function_expr (expr_t *e1, expr_t *e2)
|
|||
for (e = e2, i = 0; e; e = e->next, i++) {
|
||||
if (has_function_call (e)) {
|
||||
*a = new_temp_def_expr (arg_types[i]);
|
||||
if (i) // compensate for new_binary_expr and the first arg
|
||||
inc_users(*a);
|
||||
append_expr (call, binary_expr ('=', *a, e));
|
||||
if (e->next) {
|
||||
if (i) // compensate for new_binary_expr and the first arg
|
||||
inc_users(*a);
|
||||
append_expr (call, binary_expr ('=', *a, e));
|
||||
} else {
|
||||
e = new_binary_expr ('b', e, *a);
|
||||
append_expr (call, e);
|
||||
}
|
||||
} else {
|
||||
*a = e;
|
||||
}
|
||||
a = &(*a)->next;
|
||||
}
|
||||
} a = &(*a)->next; }
|
||||
e = new_binary_expr ('c', e1, args);
|
||||
e->e.expr.type = ftype->aux_type;
|
||||
append_expr (call, e);
|
||||
if (ftype->aux_type != &type_void) {
|
||||
expr_t *ret = new_expr ();
|
||||
ret->type = ex_def;
|
||||
#if 0
|
||||
ret->e.def = memcpy (malloc (sizeof (def_t)), &def_ret, sizeof (def_t));
|
||||
ret->e.def->type = ftype->aux_type;
|
||||
call->e.block.result = ret;
|
||||
#else
|
||||
ret->e.def = &def_ret;
|
||||
e = new_temp_def_expr (ftype->aux_type);
|
||||
append_expr (call, new_binary_expr ('=', e, ret));
|
||||
call->e.block.result = e;
|
||||
#endif
|
||||
}
|
||||
return call;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue