* src/Makefile.in (dep): include SLIBOBJS in dependency check
authorbernhardheld <bernhardheld@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Thu, 26 Feb 2004 20:04:51 +0000 (20:04 +0000)
committerbernhardheld <bernhardheld@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Thu, 26 Feb 2004 20:04:51 +0000 (20:04 +0000)
* src/SDCCast.c (decorateType): catch another small optimization with '?' operator
* src/SDCCsymt.c (computeType): added comments and cosmetic changes
* src/SDCCval.c (valMult, valDiv, valMod, valPlus, valMinus, valShift): modified to finally use computeType() all over SDCC, see Feature Request #877103
* src/SDCCval.h: cosmetic

git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@3234 4a8a32a2-be11-0410-ad9d-d568d2c75423

ChangeLog
src/Makefile.in
src/SDCCast.c
src/SDCCsymt.c
src/SDCCval.c
src/SDCCval.h

index e31cf03c146c733bafef6116d64294d5f06f6e27..35fa24b11ff19146b22985158e08d5cdd4e25c3c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2004-02-26 Bernhard Held <bernhard AT bernhardheld.de>
+
+       * src/Makefile.in (dep): include SLIBOBJS in dependency check
+       * src/SDCCast.c (decorateType): catch another small optimization
+       with '?' operator
+       * src/SDCCsymt.c (computeType): added comments and cosmetic changes
+       * src/SDCCval.c (valMult, valDiv, valMod, valPlus, valMinus, valShift):
+       modified to finally use computeType() all over SDCC,
+       see Feature Request #877103
+       * src/SDCCval.h: cosmetic
+
 2004-02-23 Bernhard Held <bernhard AT bernhardheld.de>
 
        * src/SDCCast.c (decorateType): fixed bug #902362
@@ -15,7 +26,7 @@
 
        * src/pic16/ralloc.c (packRegsForAccUse):  disabled functions with #if
        to eliminate build warnings.
-       * src/pic16/gen.c (pic16_popGet): fixed for gcc 2.95.4 
+       * src/pic16/gen.c (pic16_popGet): fixed for gcc 2.95.4
 
 2004-02-20 Vangelis Rokas <vrokas AT otenet.gr>
           Hans-Juergen Dorn <hans.dorn AT apl-landau.de>
index 1c3d85b228c96532283b58d587ed26dcfd5f3c0e..a7d91aa5f5b3d35548054e6502dc419fc2e5b7ca 100644 (file)
@@ -37,6 +37,7 @@ else
 OBJECTS                += SDCClex.o
 endif
 
+SLIBSOURCES    = $(patsubst %.o,$(SLIB)/%.c,$(SLIBOBJS))
 SOURCES                = $(patsubst %.o,%.c,$(OBJECTS))
 
 TARGET         = $(PRJDIR)/bin/sdcc$(EXEEXT)
@@ -85,8 +86,8 @@ installdirs:
 # ---------------------
 dep: Makefile.dep
 
-Makefile.dep: $(SOURCES) $(SPECIAL) *.h $(PRJDIR)/*.h
-       $(CPP) $(CPPFLAGS) $(M_OR_MM) $(SOURCES) >Makefile.dep
+Makefile.dep: $(SOURCES) $(SLIBSOURCES) $(SPECIAL) *.h $(PRJDIR)/*.h
+       $(CPP) $(CPPFLAGS) $(M_OR_MM) $(SOURCES) $(SLIBSOURCES) >Makefile.dep
 
 include Makefile.dep
 include clean.mk
index 143d7b2d8708c12336ecef777c4b14b754a5b01b..5308992cf4efbcfb9855ff352de4587f59c689d2 100644 (file)
@@ -2288,7 +2288,7 @@ decorateType (ast * tree, RESULT_TYPE resultType)
     resultTypeProp = resultTypePropagate (tree, resultType);
 
     if (tree->opval.op == '?')
-      dtl = decorateType (tree->left, RESULT_TYPE_NONE);
+      dtl = decorateType (tree->left, RESULT_TYPE_IFX);
     else
       dtl = decorateType (tree->left, resultTypeProp);
 
index e462c2b4766906a53968d9be6dddd26d66998b9b..43996bf36bbbe4ad6a80995fd3cb5b77f4b3f952 100644 (file)
@@ -1556,25 +1556,57 @@ computeType (sym_link * type1, sym_link * type2, bool promoteCharToInt)
   if (IS_CHAR (reType) && promoteCharToInt)
     SPEC_NOUN (reType) = V_INT;
 
+  /* SDCC's sign promotion:
+     - if one or both operands are unsigned, the resultant type will be unsigned
+       (except char, see below)
+     - if an operand is promoted to a larger type (char -> int, int -> long),
+       the larger type will be signed
+
+     SDCC tries hard to avoid promotion to int and does 8 bit calculation as
+     much as possible. We're leaving ISO IEC 9899 here and have to extrapolate
+     the standard. The standard demands, that the result has to be the same
+     "as if" the promotion would have been performed:
+
+     - if the result of an operation with two char's is promoted to a
+       larger type, the result will be signed.
+
+     More sophisticated is the last one:
+     - if the result of an operation with two char's is a char again,
+       the result will only then be unsigned, if both operands are
+       unsigned. In all other cases the result will be signed.
+
+       This seems to be contradictionary to the first two rules, but it makes
+       real sense (all types are char's):
+
+       A signed char can be negative; this must be preserved in the result
+               -1 * 100 = -100;
+
+       Only if both operands are unsigned it's safe to make the result
+       unsigned; this helps to avoid overflow:
+               2 * 100 =  200;
+
+     Homework: - why is (200 * 200 < 0) true?
+              - why is { char l = 200, r = 200; (r * l > 0) } true?
+  */
+
   if (!IS_FLOAT (reType)
-      && (   (   SPEC_USIGN (etype1)
-              /* if this operand is promoted to a larger
-                type don't check it's signedness */
-             && (getSize (etype1) >= getSize (reType))
-             /* char has to handled as it would have
-                been promoted to int */
+      && (   (SPEC_USIGN (etype1)
+              /* if this operand is promoted to a larger type,
+                then it will be promoted to a signed type */
+             && !(getSize (etype1) < getSize (reType))
+              /* char require special handling */
              && !IS_CHAR (etype1))
-             /* same for 2nd operand */  
-         || (   SPEC_USIGN (etype2)
-             && (getSize (etype2) >= getSize (reType))
+         || /* same for 2nd operand */  
+            (SPEC_USIGN (etype2)
+             && !(getSize (etype2) < getSize (reType))
              && !IS_CHAR (etype2))
-         /* if both are unsigned char and not promoted
-            let the result be unsigned too */
-         || (   SPEC_USIGN (etype1)
+         || /* if both are 'unsigned char' and not promoted
+               let the result be unsigned too */
+            (   SPEC_USIGN (etype1)
              && SPEC_USIGN (etype2)
              && IS_CHAR (etype1)
              && IS_CHAR (etype2)
-             && !promoteCharToInt)))
+             && IS_CHAR (reType))))
     SPEC_USIGN (reType) = 1;
   else
     SPEC_USIGN (reType) = 0;
index 542ca5754aa5eb118bf97453c0c47ce251b43cd6..c5f2556844b40d33f25b86e3421d3767784c5968 100644 (file)
@@ -1084,14 +1084,11 @@ valMult (value * lval, value * rval)
 
   /* create a new value */
   val = newValue ();
-  val->type = val->etype = newLink (SPECIFIER);
-  SPEC_NOUN (val->type) = (IS_FLOAT (lval->etype) ||
-                          IS_FLOAT (rval->etype) ? V_FLOAT : V_INT);
-  SPEC_SCLS  (val->type) = S_LITERAL;  /* will remain literal */
-  SPEC_LONG  (val->type) = (SPEC_LONG  (lval->etype) | SPEC_LONG  (rval->etype));
-  SPEC_USIGN (val->type) = SPEC_USIGN (computeType (lval->etype,
-                                                   rval->etype,
-                                                   TRUE));
+  val->type = val->etype = computeType (lval->etype,
+                                       rval->etype,
+                                       TRUE);
+  SPEC_SCLS (val->etype) = S_LITERAL; /* will remain literal */
+
   if (IS_FLOAT (val->type))
     SPEC_CVAL (val->type).v_float = floatFromVal (lval) * floatFromVal (rval);
       /* signed and unsigned mul are the same, as long as the precision of the
@@ -1136,14 +1133,10 @@ valDiv (value * lval, value * rval)
 
   /* create a new value */
   val = newValue ();
-  val->type = val->etype = newLink(SPECIFIER);
-  SPEC_NOUN (val->type) = (IS_FLOAT (lval->etype) ||
-                          IS_FLOAT (rval->etype) ? V_FLOAT : V_INT);
-  SPEC_SCLS (val->etype) = S_LITERAL;
-  SPEC_LONG  (val->type) = (SPEC_LONG  (lval->etype) | SPEC_LONG  (rval->etype));
-  SPEC_USIGN (val->type) = SPEC_USIGN (computeType (lval->etype,
-                                                   rval->etype,
-                                                   FALSE));
+  val->type = val->etype = computeType (lval->etype,
+                                       rval->etype,
+                                       TRUE);
+  SPEC_SCLS (val->etype) = S_LITERAL; /* will remain literal */
 
   if (IS_FLOAT (val->type))
     SPEC_CVAL (val->type).v_float = floatFromVal (lval) / floatFromVal (rval);
@@ -1177,14 +1170,11 @@ valMod (value * lval, value * rval)
   value *val;
 
   /* create a new value */
-  val = newValue ();
-  val->type = val->etype = newLink (SPECIFIER);
-  SPEC_NOUN (val->type) = V_INT;       /* type is int */
-  SPEC_SCLS (val->type) = S_LITERAL;   /* will remain literal */
-  SPEC_LONG  (val->type) = (SPEC_LONG  (lval->etype) | SPEC_LONG  (rval->etype));
-  SPEC_USIGN (val->type) = SPEC_USIGN (computeType (lval->etype,
-                                                   rval->etype,
-                                                   TRUE));
+  val = newValue();
+  val->type = val->etype = computeType (lval->etype,
+                                       rval->etype,
+                                       TRUE);
+  SPEC_SCLS (val->etype) = S_LITERAL; /* will remain literal */
 
   if (SPEC_LONG (val->type))
     {
@@ -1216,15 +1206,12 @@ valPlus (value * lval, value * rval)
   value *val;
 
   /* create a new value */
-  val = newValue ();
-  val->type = val->etype = newLink (SPECIFIER);
-  SPEC_NOUN (val->type) = (IS_FLOAT (lval->etype) ||
-                          IS_FLOAT (rval->etype) ? V_FLOAT : V_INT);
-  SPEC_SCLS  (val->type) = S_LITERAL;  /* will remain literal */
-  SPEC_LONG  (val->type) = (SPEC_LONG  (lval->etype) | SPEC_LONG  (rval->etype));
-  SPEC_USIGN (val->type) = SPEC_USIGN (computeType (lval->etype,
-                                                   rval->etype,
-                                                   TRUE));
+  val = newValue();
+  val->type = val->etype = computeType (lval->etype,
+                                       rval->etype,
+                                       TRUE);
+  SPEC_SCLS (val->etype) = S_LITERAL; /* will remain literal */
+  
   if (IS_FLOAT (val->type))
     SPEC_CVAL (val->type).v_float = floatFromVal (lval) + floatFromVal (rval);
   else  if (SPEC_LONG (val->type))
@@ -1257,15 +1244,12 @@ valMinus (value * lval, value * rval)
   value *val;
 
   /* create a new value */
-  val = newValue ();
-  val->type = val->etype = newLink (SPECIFIER);
-  SPEC_NOUN (val->type) = (IS_FLOAT (lval->etype) ||
-                          IS_FLOAT (rval->etype) ? V_FLOAT : V_INT);
-  SPEC_SCLS (val->type) = S_LITERAL;   /* will remain literal */
-  SPEC_LONG  (val->type) = (SPEC_LONG  (lval->etype) | SPEC_LONG  (rval->etype));
-  SPEC_USIGN (val->type) = SPEC_USIGN (computeType (lval->etype,
-                                                   rval->etype,
-                                                   TRUE));
+  val = newValue();
+  val->type = val->etype = computeType (lval->etype,
+                                       rval->etype,
+                                       TRUE);
+  SPEC_SCLS (val->etype) = S_LITERAL; /* will remain literal */
+  
   if (IS_FLOAT (val->type))
     SPEC_CVAL (val->type).v_float = floatFromVal (lval) - floatFromVal (rval);
   else  if (SPEC_LONG (val->type))
@@ -1298,14 +1282,12 @@ valShift (value * lval, value * rval, int lr)
   value *val;
 
   /* create a new value */
-  val = newValue ();
-  val->type = val->etype = newIntLink ();
-  SPEC_SCLS (val->type) = S_LITERAL;   /* will remain literal */
-  SPEC_NOUN  (val->etype) = V_INT;
-  /* 'unsigned char' promotes to 'signed int' */
-  if (!IS_CHAR (lval->etype))
-    SPEC_USIGN (val->type) = SPEC_USIGN (lval->etype);
-  SPEC_LONG (val->type) = SPEC_LONG (lval->etype);
+  val = newValue();
+  val->type = val->etype = computeType (lval->etype,
+                                       NULL,
+                                       /* promote left shift */
+                                       lr ? TRUE : FALSE);
+  SPEC_SCLS (val->etype) = S_LITERAL; /* will remain literal */
 
   if (getSize (val->type) * 8 <= (TYPE_UDWORD) floatFromVal (rval) &&
        /* left shift */
index d49495a85157e5a5e050fb578b39dcc99d4b77f0..363b5e459ea6e4c7fbe0169caf17320820439a2f 100644 (file)
   You are forbidden to forbid anyone else to use, share and improve
   what you give them.   Help stamp out software-hoarding!  
 -------------------------------------------------------------------------*/
-#include "SDCCsymt.h"
 #ifndef SDCCVAL_H
 #define SDCCVAL_H
 
+#include "SDCCsymt.h"
+
 /* value wrapper */
 typedef struct value
   {