Coercion from int to float is now always done compile time
authorceriel <none@none>
Mon, 3 Oct 1988 10:09:19 +0000 (10:09 +0000)
committerceriel <none@none>
Mon, 3 Oct 1988 10:09:19 +0000 (10:09 +0000)
lang/cem/cemcom/Makefile
lang/cem/cemcom/arith.c
lang/cem/cemcom/ival.g

index 74b5aac..5938cb1 100644 (file)
@@ -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
index 04f9da6..5632e84 100644 (file)
@@ -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)
index 82a371e..3af7f14 100644 (file)
@@ -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;