* src/mcs51/gen.c (outBitC, genRet): used IS_OP_RUONLY,
authorMaartenBrock <MaartenBrock@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sat, 2 Jun 2007 19:41:33 +0000 (19:41 +0000)
committerMaartenBrock <MaartenBrock@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sat, 2 Jun 2007 19:41:33 +0000 (19:41 +0000)
  (genNot, genXor): used toCarry, also fixes a bug for c = bit ^ val
* src/mcs51/ralloc.c: removed IS_OP_RUONLY + some cosmetic changes
* src/SDCCast.c (resultTypePropagate): propagate for '!',
  (decorateType): also optimize comparisons with RESULT_TYPE_BIT,
  bugfix: only use newBoolLink for bit result type
* src/SDCCicode.c (geniCodeLogic): added param tree,
  bugfix: use newBoolLink if tree is bit type, bug appears when ruonly,
  (geniCodeLogicAndOr): use IS_BIT,
  (geniCodeJumpTable, geniCodeSwitch): added NULL param to geniCodeLogic,
  (ast2iCode): added tree param to geniCodeLogic for comparisons
* src/SDCCsymt.h: added IS_OP_RUONLY and IS_OP_ACCUSE
* support/regression/tests/bug1723128.c: added test NotZero

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

ChangeLog
src/SDCCast.c
src/SDCCicode.c
src/SDCCsymt.h
src/mcs51/gen.c
src/mcs51/ralloc.c
support/regression/tests/bug1723128.c

index 6920c3212609c16430fa504dfb3651ded9b2c33e..603bcd9268873b7d5d0801ce3c82d3889d4b52d0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2007-06-02 Maarten Brock <sourceforge.brock AT dse.nl>
+
+       * src/mcs51/gen.c (outBitC, genRet): used IS_OP_RUONLY,
+         (genNot, genXor): used toCarry, also fixes a bug for c = bit ^ val
+       * src/mcs51/ralloc.c: removed IS_OP_RUONLY + some cosmetic changes
+       * src/SDCCast.c (resultTypePropagate): propagate for '!',
+         (decorateType): also optimize comparisons with RESULT_TYPE_BIT,
+         bugfix: only use newBoolLink for bit result type
+       * src/SDCCicode.c (geniCodeLogic): added param tree,
+         bugfix: use newBoolLink if tree is bit type, bug appears when ruonly,
+         (geniCodeLogicAndOr): use IS_BIT,
+         (geniCodeJumpTable, geniCodeSwitch): added NULL param to geniCodeLogic,
+         (ast2iCode): added tree param to geniCodeLogic for comparisons
+       * src/SDCCsymt.h: added IS_OP_RUONLY and IS_OP_ACCUSE
+       * support/regression/tests/bug1723128.c: added test NotZero
+
 2007-06-01 Borut Razem <borut.razem AT siol.net>
 
        * SDCPP synchronized with GCC CPP release version 4.2.0,
        * src/regression/Makefile,
        * src/regression/pcodeopt.c: regression test for the above fix
 
-2007-05-08 Maarten Brock <sourceforge.brock AT dse.nl>
+2007-05-11 Maarten Brock <sourceforge.brock AT dse.nl>
 
        * src/SDCCpeeph.c (labelIsUncondJump): ignore identical labels for
          jumps to self, fixed bug 1717281
index d48f3c00126d2af0f60a0e136402998bbd26587e..84bbdd8f67d8b0cffb202b0fd7a3383da8b9f725 100644 (file)
@@ -2280,6 +2280,7 @@ resultTypePropagate (ast *tree, RESULT_TYPE resultType)
     {
       case AND_OP:
       case OR_OP:
+      case '!':
         return resultType;
       case '=':
       case '?':
@@ -4153,7 +4154,7 @@ decorateType (ast * tree, RESULT_TYPE resultType)
       if (IS_LITERAL(RTYPE(tree))  &&
           floatFromVal (valFromType (RETYPE (tree))) == 0 &&
           tree->opval.op == EQ_OP &&
-          resultType == RESULT_TYPE_IFX)
+          (resultType == RESULT_TYPE_IFX || resultType == RESULT_TYPE_BIT))
         {
           tree->opval.op = '!';
           tree->right = NULL;
@@ -4208,7 +4209,7 @@ decorateType (ast * tree, RESULT_TYPE resultType)
         }
 
       LRVAL (tree) = RRVAL (tree) = 1;
-      TTYPE (tree) = TETYPE (tree) = newBoolLink ();
+      TTYPE (tree) = TETYPE (tree) = (resultType == RESULT_TYPE_BIT) ? newBoolLink() :newCharLink();
 
       /* condition transformations */
       {
@@ -5757,8 +5758,8 @@ optimizeCompare (ast * root)
             root->right->opval.val : NULL);
 
   /* if left is a BITVAR in BITSPACE */
-  /* and right is a LITERAL then opt- */
-  /* imize else do nothing       */
+  /* and right is a LITERAL then     */
+  /* optimize else do nothing        */
   if (vleft && vright &&
       IS_BITVAR (vleft->etype) &&
       IN_BITSPACE (SPEC_OCLS (vleft->etype)) &&
index 04a3e055b2cd7c981cd9212a7be62038bdf25cf2..7e397fcd5f434338486ad41d1214c381ea63a784 100644 (file)
@@ -2038,7 +2038,7 @@ geniCodeCast (sym_link * type, operand * op, bool implicit)
 
   /* This seems very dangerous to me, since there are several */
   /* optimizations (for example, gcse) that don't notice the  */
-  /* cast hidden in this assignement and may simplify an      */
+  /* cast hidden in this assignment and may simplify an       */
   /* iCode to use the original (uncasted) operand.            */
   /* Unfortunately, other things break when this cast is      */
   /* made explicit. Need to fix this someday.                 */
@@ -2733,7 +2733,7 @@ geniCodePreDec (operand * op, bool lvalue)
 
 
 /*-----------------------------------------------------------------*/
-/* geniCodeBitwise - gen int code for bitWise  operators           */
+/* geniCodeBitwise - gen int code for bitWise operators            */
 /*-----------------------------------------------------------------*/
 operand *
 geniCodeBitwise (operand * left, operand * right,
@@ -2947,10 +2947,10 @@ geniCodeRightShift (operand * left, operand * right)
 /* geniCodeLogic- logic code                                       */
 /*-----------------------------------------------------------------*/
 static operand *
-geniCodeLogic (operand * left, operand * right, int op)
+geniCodeLogic (operand * left, operand * right, int op, ast *tree)
 {
   iCode *ic;
-  sym_link *ctype;
+  sym_link *ctype, *ttype;
   sym_link *rtype = operandType (right);
   sym_link *ltype = operandType (left);
 
@@ -3017,7 +3017,9 @@ geniCodeLogic (operand * left, operand * right, int op)
   ctype = usualBinaryConversions (&left, &right, RESULT_TYPE_BIT, 0);
 
   ic = newiCode (op, left, right);
-  IC_RESULT (ic) = newiTempOperand (newCharLink (), 1);
+  /* store 0 or 1 in result */
+  ttype = (tree && IS_BIT (tree->ftype)) ? newBoolLink() : newCharLink();
+  IC_RESULT (ic) = newiTempOperand (ttype, 1);
 
   /* if comparing float
      and not a '==' || '!=' || '&&' || '||' (these
@@ -3088,7 +3090,7 @@ geniCodeLogicAndOr (ast *tree, int lvl)
   ADDTOCHAIN (ic);
 
   /* store 0 or 1 in result */
-  type = (SPEC_NOUN(tree->ftype) == V_BIT) ? newBoolLink() : newCharLink();
+  type = (IS_BIT (tree->ftype)) ? newBoolLink() : newCharLink();
   result = newiTempOperand (type, 1);
 
   geniCodeLabel (falseLabel);
@@ -3761,13 +3763,13 @@ geniCodeJumpTable (operand * cond, value * caseVals, ast * tree)
          the condition is unsigned & minimum value is zero */
       if (!(min == 0 && IS_UNSIGNED (cetype)))
         {
-          boundary = geniCodeLogic (cond, operandFromLit (min), '<');
+          boundary = geniCodeLogic (cond, operandFromLit (min), '<', NULL);
           ic = newiCodeCondition (boundary, falseLabel, NULL);
           ADDTOCHAIN (ic);
         }
 
       /* now for upper bounds */
-      boundary = geniCodeLogic (cond, operandFromLit (max), '>');
+      boundary = geniCodeLogic (cond, operandFromLit (max), '>', NULL);
       ic = newiCodeCondition (boundary, falseLabel, NULL);
       ADDTOCHAIN (ic);
     }
@@ -3848,7 +3850,7 @@ geniCodeSwitch (ast * tree,int lvl)
 
       operand *compare = geniCodeLogic (cond,
                                         operandFromValue (caseVals),
-                                        EQ_OP);
+                                        EQ_OP, NULL);
 
       SNPRINTF (buffer, sizeof(buffer), "_case_%d_%d",
                tree->values.switchVals.swNum,
@@ -4293,7 +4295,7 @@ ast2iCode (ast * tree,int lvl)
         leftOp  = geniCodeRValue (left , FALSE);
         rightOp = geniCodeRValue (right, FALSE);
 
-        return geniCodeLogic (leftOp, rightOp, tree->opval.op);
+        return geniCodeLogic (leftOp, rightOp, tree->opval.op, tree);
       }
     case '?':
       return geniCodeConditional (tree,lvl);
index 10778f32ae2935c470952f0351e1aeb8d9347fb8..79230277b586947d5cae4404cf6f747c3ef8f5e1 100644 (file)
@@ -156,7 +156,7 @@ typedef struct specifier
     unsigned b_signed:1;                /* just for sanity checks only*/
     unsigned b_static:1;                /* 1=static keyword found     */
     unsigned b_extern:1;                /* 1=extern found             */
-    unsigned b_inline:1;               /* inline function requested  */
+    unsigned b_inline:1;                /* inline function requested  */
     unsigned b_absadr:1;                /* absolute address specfied  */
     unsigned b_volatile:1;              /* is marked as volatile      */
     unsigned b_const:1;                 /* is a constant              */
@@ -329,7 +329,7 @@ typedef struct symbol
     struct iCode *fuse;                 /* furthest use */
     struct iCode *rematiCode;           /* rematerialise with which instruction */
     struct operand *reqv;               /* register equivalent of a local variable */
-    struct symbol *prereqv;             /* symbol before register equiv. substituion */
+    struct symbol *prereqv;             /* symbol before register equiv. substitution */
     struct symbol *psbase;              /* if pseudo symbol, the symbol it is based on */
     union
       {
@@ -367,6 +367,9 @@ extern sym_link *validateLink(sym_link  *l,
                                const char       *file,
                                unsigned         line);
 /* Easy Access Macros */
+#define IS_OP_RUONLY(x) (x && IS_SYMOP(x) && OP_SYMBOL(x)->ruonly)
+#define IS_OP_ACCUSE(x) (x && IS_SYMOP(x) && OP_SYMBOL(x)->accuse)
+
 #define DCL_TYPE(l)  validateLink(l, "DCL_TYPE", #l, DECLARATOR, __FILE__, __LINE__)->select.d.dcl_type
 #define DCL_ELEM(l)  validateLink(l, "DCL_ELEM", #l, DECLARATOR, __FILE__, __LINE__)->select.d.num_elem
 #define DCL_PTR_CONST(l) validateLink(l, "DCL_PTR_CONST", #l, DECLARATOR, __FILE__, __LINE__)->select.d.ptr_const
index 39a01cbe694c2e0d65af6fe2f0e3d582abbb0e1a..957d58dca8dcff26bb363f35348308b930bc40fd 100644 (file)
@@ -66,8 +66,6 @@ static char *accUse[] =
 
 static unsigned short rbank = -1;
 
-#define IS_OP_RUONLY(x) (x && IS_SYMOP(x) && OP_SYMBOL(x)->ruonly)
-
 #define REG_WITH_INDEX   mcs51_regWithIdx
 
 #define AOP(op) op->aop
@@ -1854,7 +1852,7 @@ outBitC (operand * result)
   /* if the result is bit */
   if (AOP_TYPE (result) == AOP_CRY)
     {
-      if (!OP_SYMBOL (result)->ruonly)
+      if (!IS_OP_RUONLY (result))
         aopPut (result, "c", 0);
     }
   else
@@ -2008,7 +2006,7 @@ genNot (iCode * ic)
         }
       else
         {
-          emitcode ("mov", "c,%s", IC_LEFT (ic)->aop->aopu.aop_dir);
+          toCarry (IC_LEFT (ic));
           emitcode ("cpl", "c");
           outBitC (IC_RESULT (ic));
         }
@@ -4055,7 +4053,7 @@ genRet (iCode * ic)
 
   if (IS_BIT(_G.currentFunc->etype))
     {
-      if (!(IS_SYMOP (IC_LEFT (ic)) && OP_SYMBOL (IC_LEFT (ic))->ruonly))
+      if (!IS_OP_RUONLY (IC_LEFT (ic)))
         toCarry (IC_LEFT (ic));
     }
   else
@@ -7454,21 +7452,8 @@ genXor (iCode * ic, iCode * ifx)
             }
           else
             {
-              int sizer = AOP_SIZE (right);
               // c = bit ^ val
-              // if val>>1 != 0, result = 1
-              emitcode ("setb", "c");
-              while (sizer)
-                {
-                  MOVA (aopGet (right, sizer - 1, FALSE, FALSE));
-                  if (sizer == 1)
-                    // test the msb of the lsb
-                    emitcode ("anl", "a,#0xfe");
-                  emitcode ("jnz", "%05d$", tlbl->key + 100);
-                  sizer--;
-                }
-              // val = (0,1)
-              emitcode ("rrc", "a");
+              toCarry (right);
             }
           emitcode ("jnb", "%s,%05d$", AOP (left)->aopu.aop_dir, (tlbl->key + 100));
           emitcode ("cpl", "c");
index 54af801e55919137a881463623e6eacf818df23a..833c70e18ff6820b69b2ca76a559a4d44986c073 100644 (file)
@@ -2114,10 +2114,10 @@ packRegsForAssign (iCode * ic, eBBlock * ebp)
 
       /* Don't move an assignment out of a critical block */
       if (dic->op == CRITICAL)
-       {
-         dic = NULL;
-         break;
-       }
+        {
+          dic = NULL;
+          break;
+        }
 
       if (SKIP_IC2 (dic))
         continue;
@@ -2442,8 +2442,6 @@ packRegsForSupport (iCode * ic, eBBlock * ebp)
   return 0;
 }
 
-#define IS_OP_RUONLY(x) (x && IS_SYMOP(x) && OP_SYMBOL(x)->ruonly)
-
 
 /*-----------------------------------------------------------------*/
 /* packRegsForOneuse : - will reduce some registers for single Use */
@@ -2521,25 +2519,25 @@ packRegsForOneuse (iCode * ic, operand * op, eBBlock * ebp)
     }
   else
     {
-  /* otherwise check that the definition does
-     not contain any symbols in far space */
-  if (isOperandInFarSpace (IC_LEFT (dic)) ||
-      isOperandInFarSpace (IC_RIGHT (dic)) ||
-      IS_OP_RUONLY (IC_LEFT (ic)) ||
-      IS_OP_RUONLY (IC_RIGHT (ic)))
-    {
-      return NULL;
-    }
+      /* otherwise check that the definition does
+         not contain any symbols in far space */
+      if (isOperandInFarSpace (IC_LEFT (dic)) ||
+          isOperandInFarSpace (IC_RIGHT (dic)) ||
+          IS_OP_RUONLY (IC_LEFT (ic)) ||
+          IS_OP_RUONLY (IC_RIGHT (ic)))
+        {
+          return NULL;
+        }
 
-  /* if pointer set then make sure the pointer
-     is one byte */
-  if (POINTER_SET (dic) &&
-      !IS_DATA_PTR (aggrToPtr (operandType (IC_RESULT (dic)), FALSE)))
-    return NULL;
+      /* if pointer set then make sure the pointer
+         is one byte */
+      if (POINTER_SET (dic) &&
+          !IS_DATA_PTR (aggrToPtr (operandType (IC_RESULT (dic)), FALSE)))
+        return NULL;
 
-  if (POINTER_GET (dic) &&
-      !IS_DATA_PTR (aggrToPtr (operandType (IC_LEFT (dic)), FALSE)))
-    return NULL;
+      if (POINTER_GET (dic) &&
+          !IS_DATA_PTR (aggrToPtr (operandType (IC_LEFT (dic)), FALSE)))
+        return NULL;
     }
 
   /* Make sure no overlapping liverange is already assigned to DPTR */
@@ -2770,7 +2768,7 @@ packRegsForAccUse (iCode * ic)
       getSize (aggrToPtr (operandType (IC_RESULT (uic)), FALSE)) > 1)
     return;
 
-  /* if the usage is not is an assignment
+  /* if the usage is not an assignment
      or an arithmetic / bitwise / shift operation then not */
   if (uic->op != '=' &&
       !IS_ARITHMETIC_OP (uic) &&
@@ -3050,8 +3048,7 @@ packRegisters (eBBlock ** ebpp, int blockno)
       if (POINTER_SET (ic))
         OP_SYMBOL (IC_RESULT (ic))->uptr = 1;
 
-      if (POINTER_GET (ic) &&
-          IS_SYMOP(IC_LEFT (ic)))
+      if (POINTER_GET (ic) && IS_SYMOP(IC_LEFT (ic)))
         OP_SYMBOL (IC_LEFT (ic))->uptr = 1;
 
       if (!SKIP_IC2 (ic))
@@ -3259,7 +3256,7 @@ mcs51_assignRegisters (ebbIndex * ebbi)
     }
   else
     {
-  mcs51_nRegs = 8;
+      mcs51_nRegs = 8;
     }
   _G.allBitregs = findAllBitregs ();
 
index 2565011b499fe6d10ee161e7bf6de8b8e6c2486f..e140e39b681dfddbe5719ce341fb81c7375b7be2 100644 (file)
@@ -72,12 +72,18 @@ bool VerifyCRC(void)
 
     for (i=0; i<(rx_index-1); i++)
                crc = crc_table[rx_buffer[i] ^ crc] ;
-       return (crc == rx_buffer[rx_index-1]) ;
+    return (crc == rx_buffer[rx_index-1]) ;
+}
+
+bool NotZero(unsigned int t)
+{
+    return (t != 0);
 }
 
 void
 testBug(void)
 {
-       rx_index = 1;
-       ASSERT (VerifyCRC());
+    rx_index = 1;
+    ASSERT (VerifyCRC());
+    ASSERT (NotZero(300));
 }