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:
Bill Currie 2001-08-24 21:14:04 +00:00
parent eeec89e6ba
commit 08f73bed78
2 changed files with 26 additions and 6 deletions

View file

@ -388,6 +388,13 @@ emit_expr (expr_t *e)
def_b = emit_sub_expr (e->e.expr.e2, 0); def_b = emit_sub_expr (e->e.expr.e2, 0);
emit_statement (e->line, op_state, def_a, def_b, 0); emit_statement (e->line, op_state, def_a, def_b, 0);
break; 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: default:
warning (e, "Ignoring useless expression"); warning (e, "Ignoring useless expression");
break; break;

View file

@ -332,6 +332,10 @@ print_expr (expr_t *e)
p = p->next; p = p->next;
} }
printf (")"); printf (")");
} else if (e->e.expr.op == 'b') {
print_expr (e->e.expr.e1);
printf ("<-->");
print_expr (e->e.expr.e2);
} else { } else {
print_expr (e->e.expr.e2); print_expr (e->e.expr.e2);
printf (" %s", get_op_string (e->e.expr.op)); 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++) { for (e = e2, i = 0; e; e = e->next, i++) {
if (has_function_call (e)) { if (has_function_call (e)) {
*a = new_temp_def_expr (arg_types[i]); *a = new_temp_def_expr (arg_types[i]);
if (e->next) {
if (i) // compensate for new_binary_expr and the first arg if (i) // compensate for new_binary_expr and the first arg
inc_users(*a); inc_users(*a);
append_expr (call, binary_expr ('=', *a, e)); append_expr (call, binary_expr ('=', *a, e));
} else {
e = new_binary_expr ('b', e, *a);
append_expr (call, e);
}
} else { } else {
*a = e; *a = e;
} } a = &(*a)->next; }
a = &(*a)->next;
}
e = new_binary_expr ('c', e1, args); e = new_binary_expr ('c', e1, args);
e->e.expr.type = ftype->aux_type; e->e.expr.type = ftype->aux_type;
append_expr (call, e); append_expr (call, e);
if (ftype->aux_type != &type_void) { if (ftype->aux_type != &type_void) {
expr_t *ret = new_expr (); expr_t *ret = new_expr ();
ret->type = ex_def; 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; ret->e.def = &def_ret;
e = new_temp_def_expr (ftype->aux_type); e = new_temp_def_expr (ftype->aux_type);
append_expr (call, new_binary_expr ('=', e, ret)); append_expr (call, new_binary_expr ('=', e, ret));
call->e.block.result = e; call->e.block.result = e;
#endif
} }
return call; return call;
} }