better timing for constant folding

This commit is contained in:
Bill Currie 2004-01-25 21:36:44 +00:00
parent c376982588
commit 7423ee389d
4 changed files with 33 additions and 33 deletions

View file

@ -1292,7 +1292,9 @@ fold_constants (expr_t *e)
return e1;
t1 = extract_type (e1);
if (e->e.expr.e2) {
if (op == 'i' || op == 'n' || op == 'c')
return e;
e->e.expr.e2 = e2 = fold_constants (e->e.expr.e2);
if (e2->type == ex_error)
return e2;
@ -1301,10 +1303,7 @@ fold_constants (expr_t *e)
return e;
t2 = extract_type (e2);
} else {
t2 = ev_void;
e2 = 0;
}
if (op == 's')
return e;

View file

@ -1874,11 +1874,11 @@ 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]);
arg_exprs[arg_expr_count][0] = fold_constants (e);
arg_exprs[arg_expr_count][0] = e;
arg_exprs[arg_expr_count][1] = *a;
arg_expr_count++;
} else {
*a = fold_constants (e);
*a = e;
}
// new_binary_expr calls inc_users for both args, but in_users doesn't
// walk expression chains so only the first arg expression in the chain
@ -2397,7 +2397,7 @@ init_elements (def_t *def, expr_t *eles)
}
for (i = 0, e = eles->e.block.head; i < count; i++, e = e->next) {
g = G_POINTER (pr_type_t, elements[i].ofs);
c = constant_expr (fold_constants (e));
c = constant_expr (e);
if (c->type == ex_block) {
if (elements[i].type->type != ev_array
&& elements[i].type->type != ev_struct) {

View file

@ -206,7 +206,6 @@ build_builtin_function (def_t *def, expr_t *bi_val)
return 0;
}
bi_val = fold_constants (bi_val);
if (bi_val->type != ex_integer && bi_val->type != ex_float) {
error (bi_val, "invalid constant for = #");
return 0;
@ -263,7 +262,6 @@ emit_function (function_t *f, expr_t *e)
//print_expr (e);
//puts("");
fold_constants (e);
emit_expr (e);
e = e->next;
}

View file

@ -158,7 +158,7 @@ expr_t *argv_expr (void);
%type <param> function_decl
%type <param> param param_list
%type <def> def_name opt_initializer methoddef var_initializer
%type <expr> const opt_expr expr element_list element_list1 element
%type <expr> const opt_expr fexpr expr element_list element_list1 element
%type <expr> string_val opt_state_expr array_decl
%type <expr> statement statements statement_block
%type <expr> label break_label continue_label enum_list enum
@ -281,7 +281,7 @@ enum_list
enum
: NAME { $$ = new_name_expr ($1); }
| NAME '=' expr
| NAME '=' fexpr
{
$$ = 0;
$3 = constant_expr ($3);
@ -421,7 +421,7 @@ opt_initializer
;
var_initializer
: '=' expr
: '=' fexpr
{
if (current_scope->type == sc_local
|| current_scope->type == sc_params) {
@ -450,7 +450,7 @@ var_initializer
init_elements ($<def>0, $4);
current_init = 0;
}
| '=' '#' expr
| '=' '#' fexpr
{
$3 = constant_expr ($3);
build_builtin_function ($<def>0, $3);
@ -525,7 +525,7 @@ element
{
$$ = $3;
}
| expr
| fexpr
{
$$ = $1;
}
@ -606,7 +606,7 @@ statements
statement
: ';' { $$ = 0; }
| statement_block { $$ = $1; }
| RETURN expr ';'
| RETURN fexpr ';'
{
$$ = return_expr (current_func, $2);
}
@ -630,7 +630,7 @@ statement
else
error (0, "continue outside of loop");
}
| CASE expr ':'
| CASE fexpr ':'
{
$$ = case_label_expr (switch_block, $2);
}
@ -638,7 +638,7 @@ statement
{
$$ = case_label_expr (switch_block, 0);
}
| SWITCH break_label switch_block '(' expr ')'
| SWITCH break_label switch_block '(' fexpr ')'
{
switch_block->test = $5;
}
@ -650,7 +650,7 @@ statement
switch_block = $3;
break_label = $2;
}
| WHILE break_label continue_label '(' expr ')' save_inits statement
| WHILE break_label continue_label '(' fexpr ')' save_inits statement
{
expr_t *l1 = new_label_expr ();
expr_t *l2 = break_label;
@ -684,7 +684,7 @@ statement
pr.source_line = line;
pr.source_file = file;
}
| DO break_label continue_label statement WHILE '(' expr ')' ';'
| DO break_label continue_label statement WHILE '(' fexpr ')' ';'
{
expr_t *l1 = new_label_expr ();
int line = pr.source_line;
@ -724,7 +724,7 @@ statement
$$ = local_expr;
local_expr = 0;
}
| IF '(' expr ')' save_inits statement
| IF '(' fexpr ')' save_inits statement
{
expr_t *tl = new_label_expr ();
expr_t *fl = new_label_expr ();
@ -753,7 +753,7 @@ statement
pr.source_line = line;
pr.source_file = file;
}
| IF '(' expr ')' save_inits statement ELSE
| IF '(' fexpr ')' save_inits statement ELSE
{
$<def_list>$ = save_local_inits (current_scope);
restore_local_inits ($5);
@ -849,7 +849,7 @@ statement
pr.source_line = line;
pr.source_file = file;
}
| expr ';'
| fexpr ';'
{
$$ = $1;
}
@ -894,7 +894,7 @@ save_inits
;
opt_expr
: expr
: fexpr
| /* empty */
{
$$ = 0;
@ -959,14 +959,17 @@ expr
| expr '%' expr { $$ = binary_expr ('%', $1, $3); }
;
fexpr
: expr { $$ = fold_constants ($1); }
opt_arg_list
: /* emtpy */ { $$ = 0; }
| arg_list { $$ = $1; }
;
arg_list
: expr
| arg_list ',' expr
: fexpr
| arg_list ',' fexpr
{
$3->next = $1;
$$ = $3;
@ -1393,7 +1396,7 @@ obj_messageexpr
;
receiver
: expr
: fexpr
| CLASS_NAME { $$ = new_name_expr ($1); }
| SUPER { $$ = new_name_expr ("super"); }
;