* src/SDCCmain.c: fixed --help
[fw/sdcc] / src / SDCCicode.c
index 513c7b6ccee6a2aaf7cc8fe47e7d04f0465d9136..8ad10a8d9fde7eb0af19fcc3ea4a940009c792e2 100644 (file)
@@ -725,14 +725,15 @@ newiTempLabel (char *s)
 }
 
 /*-----------------------------------------------------------------*/
-/* newiTempPreheaderLabel - creates a new preheader label          */
+/* newiTempLoopHeaderLabel - creates a new loop header label       */
 /*-----------------------------------------------------------------*/
 symbol *
-newiTempPreheaderLabel ()
+newiTempLoopHeaderLabel (bool pre)
 {
   symbol *itmplbl;
 
-  SNPRINTF (buffer, sizeof(buffer), "preHeaderLbl%d", iTempLblNum++);
+  SNPRINTF (buffer, sizeof(buffer), pre ? "preHeaderLbl%d" : LOOPEXITLBL "%d",
+            iTempLblNum++);
   itmplbl = newSymbol (buffer, 1);
 
   itmplbl->isitmp = 1;
@@ -1838,7 +1839,7 @@ setOperandType (operand * op, sym_link * type)
 /*-----------------------------------------------------------------*/
 /* Get size in byte of ptr need to access an array                 */
 /*-----------------------------------------------------------------*/
-static int
+static unsigned int
 getArraySizePtr (operand * op)
 {
   sym_link *ltype = operandType(op);
@@ -2409,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: */
@@ -2512,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))
     {
@@ -2520,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)
@@ -2847,7 +2843,7 @@ geniCodeAddressOf (operand * op)
       return op;
     }
 
-  /* other wise make this of the type coming in */
+  /* otherwise make this of the type coming in */
   ic = newiCode (ADDRESS_OF, op, NULL);
   IC_RESULT (ic) = newiTempOperand (p, 1);
   IC_RESULT (ic)->isaddr = 0;
@@ -3061,7 +3057,7 @@ geniCodeLogic (operand * left, operand * right, int op)
         }
     }
 
-  ctype = usualBinaryConversions (&left, &right, RESULT_TYPE_NONE, 0);
+  ctype = usualBinaryConversions (&left, &right, RESULT_TYPE_BIT, 0);
 
   ic = newiCode (op, left, right);
   IC_RESULT (ic) = newiTempOperand (newCharLink (), 1);
@@ -3635,8 +3631,6 @@ geniCodeIfx (ast * tree,int lvl)
         {
           if (tree->falseLabel)
             geniCodeGoto (tree->falseLabel);
-          else
-            assert (0);
         }
       goto exit;
     }