From 52b561f7cb7dbaa262e4d377ef0f6285c4cf1d41 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Fri, 21 Jan 2011 19:07:58 +0900 Subject: [PATCH] Nuke bind expressions. Since I'm planning on implementing CSE and other optimizations, they're rather redundant (and I'm having trouble getting them to work). --- tools/qfcc/include/expr.h | 12 ---------- tools/qfcc/source/constfold.c | 44 ++++++++++++++-------------------- tools/qfcc/source/expr.c | 36 ++++++---------------------- tools/qfcc/source/statements.c | 22 ----------------- tools/qfcc/source/switch.c | 2 +- 5 files changed, 26 insertions(+), 90 deletions(-) diff --git a/tools/qfcc/include/expr.h b/tools/qfcc/include/expr.h index 999fb2892..f6bb8127c 100644 --- a/tools/qfcc/include/expr.h +++ b/tools/qfcc/include/expr.h @@ -473,18 +473,6 @@ int is_quaternion_val (expr_t *e); int is_integer_val (expr_t *e); int is_short_val (expr_t *e); -/** Bind the result of an expression to a temporary variable. - - If a temporary variable is not needed when emitting code, none will - be used. - - \param e1 The expression which will be bound. - \param e2 The temporary variable to which the expression will be - bound. Must be a temporary expression (ex_temp). - \return The new bind expression. -*/ -expr_t *new_bind_expr (expr_t *e1, expr_t *e2); - /** Create a reference to the global .self entity variable. This is used for \@self. diff --git a/tools/qfcc/source/constfold.c b/tools/qfcc/source/constfold.c index 28bdf42ec..b4ba705c3 100644 --- a/tools/qfcc/source/constfold.c +++ b/tools/qfcc/source/constfold.c @@ -77,7 +77,7 @@ do_op_string (int op, expr_t *e, expr_t *e1, expr_t *e2) { const char *s1, *s2; static dstring_t *temp_str; - static int valid[] = {'=', 'b', '+', LT, GT, LE, GE, EQ, NE, 0}; + static int valid[] = {'=', '+', LT, GT, LE, GE, EQ, NE, 0}; if (!valid_op (op, valid)) return error (e1, "invalid operand for string"); @@ -91,7 +91,7 @@ do_op_string (int op, expr_t *e, expr_t *e1, expr_t *e2) e->e.expr.type = &type_string; } - if (op == '=' || op == 'b' || !is_constant (e1) || !is_constant (e2)) + if (op == '=' || !is_constant (e1) || !is_constant (e2)) return e; s1 = expr_string (e1); @@ -174,22 +174,14 @@ do_op_float (int op, expr_t *e, expr_t *e1, expr_t *e2) expr_t *conv; type_t *type = &type_float; static int valid[] = { - '=', 'b', '+', '-', '*', '/', '&', '|', '^', '%', + '=', '+', '-', '*', '/', '&', '|', '^', '%', SHL, SHR, AND, OR, LT, GT, LE, GE, EQ, NE, 0 }; if (!valid_op (op, valid)) return error (e1, "invalid operand for float"); - if (op == 'b') { - // bind is backwards to assign (why did I do that? :P) - if ((type = get_type (e2)) != &type_float) { - //FIXME optimize casting a constant - e->e.expr.e1 = e1 = cf_cast_expr (type, e1); - } else if ((conv = convert_to_float (e1)) != e1) { - e->e.expr.e1 = e1 = conv; - } - } else if (op == '=' || op == PAS) { + if (op == '=' || op == PAS) { if ((type = get_type (e1)) != &type_float) { //FIXME optimize casting a constant e->e.expr.e2 = e2 = cf_cast_expr (type, e2); @@ -233,7 +225,7 @@ do_op_float (int op, expr_t *e, expr_t *e1, expr_t *e2) if (op == '-' && is_constant (e2) && expr_float (e2) == 0) return e1; - if (op == '=' || op == 'b' || !is_constant (e1) || !is_constant (e2)) + if (op == '=' || !is_constant (e1) || !is_constant (e2)) return e; f1 = expr_float (e1); @@ -309,7 +301,7 @@ do_op_vector (int op, expr_t *e, expr_t *e1, expr_t *e2) { const float *v1, *v2; vec3_t v; - static int valid[] = {'=', 'b', '+', '-', '*', EQ, NE, 0}; + static int valid[] = {'=', '+', '-', '*', EQ, NE, 0}; expr_t *t; if (get_type (e1) != &type_vector) { @@ -363,7 +355,7 @@ do_op_vector (int op, expr_t *e, expr_t *e1, expr_t *e2) if (op == '-' && is_constant (e2) && VectorIsZero (expr_vector (e2))) return e1; - if (op == '=' || op == 'b' || !is_constant (e1) || !is_constant (e2)) + if (op == '=' || !is_constant (e1) || !is_constant (e2)) return e; v1 = expr_vector (e1); @@ -420,7 +412,7 @@ do_op_entity (int op, expr_t *e, expr_t *e1, expr_t *e2) e->e.expr.type = &type_float; return e; } - if ((op != '=' && op != 'b') || type != &type_entity) + if (op != '=' || type != &type_entity) return error (e1, "invalid operand for entity"); e->e.expr.type = &type_entity; return e; @@ -429,7 +421,7 @@ do_op_entity (int op, expr_t *e, expr_t *e1, expr_t *e2) static expr_t * do_op_field (int op, expr_t *e, expr_t *e1, expr_t *e2) { - if (op != '=' && op != 'b') + if (op != '=') return error (e1, "invalid operand for field"); e->e.expr.type = &type_field; return e; @@ -449,7 +441,7 @@ do_op_func (int op, expr_t *e, expr_t *e1, expr_t *e2) e->e.expr.type = &type_float; return e; } - if (op != '=' && op != 'b') + if (op != '=') return error (e1, "invalid operand for func"); e->e.expr.type = &type_function; return e; @@ -459,7 +451,7 @@ static expr_t * do_op_pointer (int op, expr_t *e, expr_t *e1, expr_t *e2) { type_t *type; - static int valid[] = {'=', 'b', PAS, '&', 'M', '.', EQ, NE, 0}; + static int valid[] = {'=', PAS, '&', 'M', '.', EQ, NE, 0}; if (!valid_op (op, valid)) return error (e1, "invalid operand for pointer"); @@ -498,7 +490,7 @@ do_op_quaternion (int op, expr_t *e, expr_t *e1, expr_t *e2) { const float *q1, *q2; quat_t q; - static int valid[] = {'=', 'b', '+', '-', '*', EQ, NE, 0}; + static int valid[] = {'=', '+', '-', '*', EQ, NE, 0}; expr_t *t; if (get_type (e1) != &type_quaternion) { @@ -544,7 +536,7 @@ do_op_quaternion (int op, expr_t *e, expr_t *e1, expr_t *e2) if (op == '-' && is_constant (e2) && QuatIsZero (expr_quaternion (e2))) return e1; - if (op == '=' || op == 'b' || !is_constant (e1) || !is_constant (e2)) + if (op == '=' || !is_constant (e1) || !is_constant (e2)) return e; q1 = expr_quaternion (e1); @@ -595,7 +587,7 @@ do_op_integer (int op, expr_t *e, expr_t *e1, expr_t *e2) { int i1, i2; static int valid[] = { - '=', 'b', '+', '-', '*', '/', '&', '|', '^', '%', + '=', '+', '-', '*', '/', '&', '|', '^', '%', SHL, SHR, AND, OR, LT, GT, LE, GE, EQ, NE, 0 }; @@ -638,7 +630,7 @@ do_op_integer (int op, expr_t *e, expr_t *e1, expr_t *e2) if (op == '-' && is_constant (e2) && expr_integer (e2) == 0) return e1; - if (op == '=' || op == 'b' || !is_constant (e1) || !is_constant (e2)) + if (op == '=' || !is_constant (e1) || !is_constant (e2)) return e; i1 = expr_integer (e1); @@ -714,7 +706,7 @@ do_op_short (int op, expr_t *e, expr_t *e1, expr_t *e2) { short i1, i2; static int valid[] = { - '=', 'b', '+', '-', '*', '/', '&', '|', '^', '%', + '=', '+', '-', '*', '/', '&', '|', '^', '%', SHL, SHR, AND, OR, LT, GT, LE, GE, EQ, NE, 0 }; @@ -730,7 +722,7 @@ do_op_short (int op, expr_t *e, expr_t *e1, expr_t *e2) e->e.expr.type = &type_short; } - if (op == '=' || op == 'b' || !is_constant (e1) || !is_constant (e2)) + if (op == '=' || !is_constant (e1) || !is_constant (e2)) return e; i1 = expr_short (e1); @@ -806,7 +798,7 @@ do_op_struct (int op, expr_t *e, expr_t *e1, expr_t *e2) { type_t *type; - if (op != '=' && op != 'b' && op != 'M') + if (op != '=' && op != 'M') return error (e1, "invalid operand for struct"); if ((type = get_type (e1)) != get_type (e2)) return type_mismatch (e1, e2, op); diff --git a/tools/qfcc/source/expr.c b/tools/qfcc/source/expr.c index 829b80cb2..c0cf148bd 100644 --- a/tools/qfcc/source/expr.c +++ b/tools/qfcc/source/expr.c @@ -166,7 +166,6 @@ get_op_string (int op) case IFA: return ""; case 'g': return ""; case 'r': return ""; - case 'b': return ""; case 's': return ""; case 'c': return ""; case 'C': return ""; @@ -768,23 +767,6 @@ expr_short (expr_t *e) internal_error (e, "not a short constant"); } -expr_t * -new_bind_expr (expr_t *e1, expr_t *e2) -{ - expr_t *e; - - if (!e2 || e2->type != ex_temp) { - internal_error (e1, 0); - } - e = new_expr (); - e->type = ex_expr; - e->e.expr.op = 'b'; - e->e.expr.e1 = e1; - e->e.expr.e2 = e2; - e->e.expr.type = get_type (e2); - return e; -} - expr_t * new_self_expr (void) { @@ -1535,19 +1517,19 @@ binary_expr (int op, expr_t *e1, expr_t *e2) tmp2 = new_temp_def_expr (&type_float); tmp3 = new_temp_def_expr (&type_float); - append_expr (e, new_bind_expr (e1, t1)); + append_expr (e, assign_expr (t1, e1)); e1 = binary_expr ('&', t1, t1); - append_expr (e, new_bind_expr (e1, tmp1)); + append_expr (e, assign_expr (tmp1, e1)); - append_expr (e, new_bind_expr (e2, t2)); + append_expr (e, assign_expr (t2, e2)); e2 = binary_expr ('&', t2, t2); - append_expr (e, new_bind_expr (e2, tmp2)); + append_expr (e, assign_expr (tmp2, e2)); e1 = binary_expr ('/', tmp1, tmp2); append_expr (e, assign_expr (tmp3, e1)); e2 = binary_expr ('&', tmp3, tmp3); - append_expr (e, new_bind_expr (e2, tmp3)); + append_expr (e, assign_expr (tmp3, e2)); e1 = binary_expr ('*', tmp2, tmp3); e2 = binary_expr ('-', tmp1, e1); @@ -1885,8 +1867,8 @@ build_function_call (expr_t *fexpr, type_t *ftype, expr_t *params) append_expr (call, assign_expr (arg_exprs[i][1], arg_exprs[i][0])); } if (arg_expr_count) { - e = new_bind_expr (arg_exprs[arg_expr_count - 1][0], - arg_exprs[arg_expr_count - 1][1]); + e = assign_expr (arg_exprs[arg_expr_count - 1][1], + arg_exprs[arg_expr_count - 1][0]); inc_users (arg_exprs[arg_expr_count - 1][0]); inc_users (arg_exprs[arg_expr_count - 1][1]); append_expr (call, e); @@ -2161,10 +2143,6 @@ address_expr (expr_t *e1, expr_t *e2, type_t *t) e->e.expr.op = '&'; e->e.expr.type = pointer_type (e->e.expr.type); break; - } else if (e1->e.expr.op == 'b') { - e = new_unary_expr ('&', e1); - e->e.expr.type = pointer_type (e1->e.expr.type); - break; } return error (e1, "invalid type for unary &"); case ex_uexpr: diff --git a/tools/qfcc/source/statements.c b/tools/qfcc/source/statements.c index a694c4c4c..d8e53285a 100644 --- a/tools/qfcc/source/statements.c +++ b/tools/qfcc/source/statements.c @@ -365,22 +365,6 @@ expr_block (sblock_t *sblock, expr_t *e, operand_t **op) return sblock; } -static sblock_t * -expr_bind (sblock_t *sblock, expr_t *e, operand_t **op) -{ - expr_t *src_expr = e->e.expr.e1; - expr_t *dst_expr = e->e.expr.e2; - type_t *dst_type; - operand_t *tmp = 0; - - if (!dst_expr || dst_expr->type != ex_temp) - internal_error (e, "bad bind expression"); - dst_type = get_type (dst_expr); - sblock = statement_subexpr (sblock, src_expr, &tmp); - tmp->type = dst_type->type; - return sblock; -} - static sblock_t * expr_expr (sblock_t *sblock, expr_t *e, operand_t **op) { @@ -388,9 +372,6 @@ expr_expr (sblock_t *sblock, expr_t *e, operand_t **op) statement_t *s; switch (e->e.expr.op) { - case 'b': - sblock = expr_bind (sblock, e, op); - break; case 'c': sblock = expr_call (sblock, e, op); break; @@ -654,9 +635,6 @@ static sblock_t * statement_expr (sblock_t *sblock, expr_t *e) { switch (e->e.expr.op) { - case 'b': - sblock = expr_bind (sblock, e, 0); - break; case 'c': sblock = expr_call (sblock, e, 0); break; diff --git a/tools/qfcc/source/switch.c b/tools/qfcc/source/switch.c index 5a2a56a39..58b4b059e 100644 --- a/tools/qfcc/source/switch.c +++ b/tools/qfcc/source/switch.c @@ -367,7 +367,7 @@ switch_expr (switch_block_t *switch_block, expr_t *break_label, } default_expr = new_unary_expr ('g', default_label->label); - append_expr (sw, new_bind_expr (switch_block->test, sw_val)); + append_expr (sw, assign_expr (sw_val, switch_block->test)); for (l = labels; *l; l++) num_labels++;