Coercion from int to float is now always done compile time
This commit is contained in:
parent
4cecb6bffb
commit
6b7a135b2b
|
@ -51,9 +51,10 @@ GEN = $(EMHOME)/bin/LLgen
|
|||
GENOPTIONS = -v
|
||||
|
||||
# Special #defines during compilation
|
||||
PROF = #-pg
|
||||
CDEFS = $(EM_INCLUDES) $(LIB_INCLUDES)
|
||||
CFLAGS = $(CDEFS) $(COPTIONS) -O
|
||||
LDFLAGS = -i
|
||||
CFLAGS = $(CDEFS) $(COPTIONS) -O $(PROF)
|
||||
LDFLAGS = -i $(PROF)
|
||||
|
||||
# Grammar files and their objects
|
||||
LSRC = tokenfile.g declar.g statement.g expression.g program.g ival.g
|
||||
|
|
|
@ -270,9 +270,22 @@ int2float(expp, tp)
|
|||
/* The expression *expp, which is of some integral type, is
|
||||
converted to the floating type tp.
|
||||
*/
|
||||
register struct expr *exp = *expp;
|
||||
char buf[32];
|
||||
|
||||
fp_used = 1;
|
||||
*expp = arith2arith(tp, INT2FLOAT, *expp);
|
||||
if (is_cp_cst(exp)) {
|
||||
*expp = new_expr();
|
||||
**expp = *exp;
|
||||
sprint(buf+1, "%ld", (long)(exp->VL_VALUE));
|
||||
buf[0] = '-';
|
||||
exp = *expp;
|
||||
exp->ex_type = tp;
|
||||
exp->ex_class = Float;
|
||||
exp->FL_VALUE = Salloc(buf, (unsigned)strlen(buf)+1) + 1;
|
||||
exp->FL_DATLAB = 0;
|
||||
}
|
||||
else *expp = arith2arith(tp, INT2FLOAT, *expp);
|
||||
}
|
||||
|
||||
float2int(expp, tp)
|
||||
|
|
|
@ -504,6 +504,13 @@ check_ival(expp, tp)
|
|||
#endif DEBUG
|
||||
if (expr->ex_class == Float)
|
||||
C_con_fcon(expr->FL_VALUE, expr->ex_type->tp_size);
|
||||
#ifdef NOTDEF
|
||||
|
||||
Coercion from int to float is now always done compile time.
|
||||
This, to accept declarations like
|
||||
double x = -(double)1;
|
||||
and also to prevent runtime coercions for compile-time constants.
|
||||
|
||||
else
|
||||
if (expr->ex_class == Oper && expr->OP_OPER == INT2FLOAT) {
|
||||
/* float f = 1; */
|
||||
|
@ -514,6 +521,7 @@ check_ival(expp, tp)
|
|||
else
|
||||
illegal_init_cst(expr);
|
||||
}
|
||||
#endif NOTDEF
|
||||
else
|
||||
illegal_init_cst(expr);
|
||||
break;
|
||||
|
|
Loading…
Reference in a new issue