mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-10 23:32:09 +00:00
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).
This commit is contained in:
parent
0d01930056
commit
52b561f7cb
5 changed files with 26 additions and 90 deletions
|
@ -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 <code>.self</code> entity variable.
|
||||
|
||||
This is used for <code>\@self</code>.
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -166,7 +166,6 @@ get_op_string (int op)
|
|||
case IFA: return "<ifa>";
|
||||
case 'g': return "<goto>";
|
||||
case 'r': return "<return>";
|
||||
case 'b': return "<bind>";
|
||||
case 's': return "<state>";
|
||||
case 'c': return "<call>";
|
||||
case 'C': return "<cast>";
|
||||
|
@ -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:
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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++;
|
||||
|
|
Loading…
Reference in a new issue