Allow the operand to override the symbol's type.

This commit is contained in:
Bill Currie 2011-01-21 10:54:40 +09:00
parent 3f2793ef72
commit 16e013ff5d
2 changed files with 8 additions and 3 deletions

View file

@ -40,7 +40,8 @@ typedef enum {
typedef struct operand_s { typedef struct operand_s {
struct operand_s *next; struct operand_s *next;
op_type_e type; op_type_e op_type;
etype_t type; ///< possibly override symbol's type
union { union {
struct symbol_s *symbol; struct symbol_s *symbol;
struct ex_value_s *value; struct ex_value_s *value;

View file

@ -54,7 +54,7 @@ static __attribute__ ((used)) const char rcsid[] = "$Id$";
static void static void
print_operand (operand_t *op) print_operand (operand_t *op)
{ {
switch (op->type) { switch (op->op_type) {
case op_symbol: case op_symbol:
printf ("%s", op->o.symbol->name); printf ("%s", op->o.symbol->name);
break; break;
@ -159,7 +159,7 @@ new_operand (op_type_e op)
{ {
operand_t *operand; operand_t *operand;
ALLOC (256, operand_t, operands, operand); ALLOC (256, operand_t, operands, operand);
operand->type = op; operand->op_type = op;
return operand; return operand;
} }
@ -294,6 +294,7 @@ expr_expr (sblock_t *sblock, expr_t *e, operand_t **op)
sblock = statement_subexpr (sblock, e->e.expr.e1, &s->opa); sblock = statement_subexpr (sblock, e->e.expr.e1, &s->opa);
sblock = statement_subexpr (sblock, e->e.expr.e2, &s->opb); sblock = statement_subexpr (sblock, e->e.expr.e2, &s->opb);
*op = s->opc = new_operand (op_temp); *op = s->opc = new_operand (op_temp);
s->opc->type = e->e.expr.type->type;
sblock_add_statement (sblock, s); sblock_add_statement (sblock, s);
break; break;
} }
@ -310,6 +311,7 @@ static sblock_t *
expr_symbol (sblock_t *sblock, expr_t *e, operand_t **op) expr_symbol (sblock_t *sblock, expr_t *e, operand_t **op)
{ {
*op = new_operand (op_symbol); *op = new_operand (op_symbol);
(*op)->type = e->e.symbol->type->type;
(*op)->o.symbol = e->e.symbol; (*op)->o.symbol = e->e.symbol;
return sblock; return sblock;
} }
@ -318,6 +320,7 @@ static sblock_t *
expr_temp (sblock_t *sblock, expr_t *e, operand_t **op) expr_temp (sblock_t *sblock, expr_t *e, operand_t **op)
{ {
*op = new_operand (op_temp); *op = new_operand (op_temp);
(*op)->type = e->e.temp.type->type;
return sblock; return sblock;
} }
@ -325,6 +328,7 @@ static sblock_t *
expr_value (sblock_t *sblock, expr_t *e, operand_t **op) expr_value (sblock_t *sblock, expr_t *e, operand_t **op)
{ {
*op = new_operand (op_value); *op = new_operand (op_value);
(*op)->type = e->e.value.type;
(*op)->o.value = &e->e.value; (*op)->o.value = &e->e.value;
return sblock; return sblock;
} }