* src/SDCCicode.c (geniCodeAdd, geniCodeArray): use char for array offset if possible
authorbernhardheld <bernhardheld@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Fri, 20 Jan 2006 21:58:55 +0000 (21:58 +0000)
committerbernhardheld <bernhardheld@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Fri, 20 Jan 2006 21:58:55 +0000 (21:58 +0000)
* src/SDCCast.c (getLeftResultType): 255 fits in char, not 256

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

ChangeLog
src/SDCCast.c
src/SDCCicode.c

index b4c2f67534846957abb29d3e3ff531d59d1aea00..61b509a734b9a87e8cdadaaa29a130df9606fcbb 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2006-01-20 Bernhard Held <bernhard AT bernhardheld.de>
+
+       * src/SDCCicode.c (geniCodeAdd, geniCodeArray): use char for array
+       offset if possible
+       * src/SDCCast.c (getLeftResultType): 255 fits in char, not 256
+
 2006-01-18 Bernhard Held <bernhard AT bernhardheld.de>
 
        * src/SDCCast.c (backPatchLabels): fixed bug #1408066: made it
index 9e49cd43c0eb7be2cf5f10f357bcd094e5b45687..dcddefdbf81827cf0c7d4d7c65d46720d8f01753 100644 (file)
@@ -2239,7 +2239,7 @@ getLeftResultType (ast *tree, RESULT_TYPE resultType)
       case '[':
         if (!IS_ARRAY (LTYPE (tree)))
           return resultType;
-        if (DCL_ELEM (LTYPE (tree)) > 0 && DCL_ELEM (LTYPE (tree)) <= 256)
+        if (DCL_ELEM (LTYPE (tree)) > 0 && DCL_ELEM (LTYPE (tree)) <= 255)
           return RESULT_TYPE_CHAR;
         return resultType;
       default:
index e24cc39564a7fd32665db75ce2bdd0255ad71083..30503b61f5a8c5dee33bc785ad3044f7186cd730 100644 (file)
@@ -2410,11 +2410,7 @@ geniCodeAdd (operand * left, operand * right, RESULT_TYPE resultType, int lvl)
           size  = operandFromLit (getSize (ltype->next));
           SPEC_USIGN (getSpec (operandType (size))) = 1;
           indexUnsigned = IS_UNSIGNED (getSpec (operandType (right)));
-          right = geniCodeMultiply (right,
-                                    size,
-                                    (getArraySizePtr(left) >= INTSIZE) ?
-                                      RESULT_TYPE_INT :
-                                      RESULT_TYPE_CHAR);
+          right = geniCodeMultiply (right, size, resultType);
           /* Even if right is a 'unsigned char',
              the result will be a 'signed int' due to the promotion rules.
              It doesn't make sense when accessing arrays, so let's fix it here: */
@@ -2513,6 +2509,14 @@ geniCodeArray (operand * left, operand * right, int lvl)
   operand *size;
   sym_link *ltype = operandType (left);
   bool indexUnsigned;
+  RESULT_TYPE resultType;
+
+  resultType = (getArraySizePtr(left) >= INTSIZE) ? RESULT_TYPE_INT : RESULT_TYPE_CHAR;
+  if (DCL_ELEM (ltype))
+    {
+      if (DCL_ELEM (ltype) * getSize (ltype->next) <= 255)
+        resultType = RESULT_TYPE_CHAR;
+    }
 
   if (IS_PTR (ltype))
     {
@@ -2521,22 +2525,13 @@ geniCodeArray (operand * left, operand * right, int lvl)
           left = geniCodeRValue (left, FALSE);
         }
 
-      return geniCodeDerefPtr (geniCodeAdd (left,
-                                            right,
-                                            (getArraySizePtr(left) >= INTSIZE) ?
-                                              RESULT_TYPE_INT :
-                                              RESULT_TYPE_CHAR,
-                                            lvl),
+      return geniCodeDerefPtr (geniCodeAdd (left, right, resultType, lvl),
                                lvl);
     }
   size = operandFromLit (getSize (ltype->next));
   SPEC_USIGN (getSpec (operandType (size))) = 1;
   indexUnsigned = IS_UNSIGNED (getSpec (operandType (right)));
-  right = geniCodeMultiply (right,
-                            size,
-                            (getArraySizePtr(left) >= INTSIZE) ?
-                              RESULT_TYPE_INT :
-                              RESULT_TYPE_CHAR);
+  right = geniCodeMultiply (right, size, resultType);
   /* Even if right is a 'unsigned char', the result will be a 'signed int' due to the promotion rules.
      It doesn't make sense when accessing arrays, so let's fix it here: */
   if (indexUnsigned)