* src/SDCCcse.c (replaceAllSymBySym): renamed siaddr to isaddr,
authorMaartenBrock <MaartenBrock@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Fri, 13 Jul 2007 12:21:56 +0000 (12:21 +0000)
committerMaartenBrock <MaartenBrock@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Fri, 13 Jul 2007 12:21:56 +0000 (12:21 +0000)
  (cseBBlock): remember aggr2ptr has been used
* src/SDCCicode.c (operandSize): added function to handle aggr2ptr,
  (geniCodeAssign): fixed bug 868103
* src/SDCCicode.h: made operand.aggr2ptr 2 bits wide,
  added operandSize prototype
* src/mcs51/gen.c (aopOp): use operandSize to fix bug 868103,
  (genDataPointerSet): use size of result,
  (gencjne): added parameter useCarry for optimization,
  (genCmpEq): use carry if appropriate,
  (genXor): check if operand already in carry
* support/regression/tests/bug-868103.c: enabled test

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

ChangeLog
src/SDCCcse.c
src/SDCCicode.c
src/SDCCicode.h
src/mcs51/gen.c
support/regression/tests/bug-868103.c

index 354787226e7c3c8bb05a794a66143f103ec0ecd6..a053bc9fbd3f065c55b2b74d7f01c9212bbd809f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2007-07-13 Maarten Brock <sourceforge.brock AT dse.nl>
+
+       * src/SDCCcse.c (replaceAllSymBySym): renamed siaddr to isaddr,
+         (cseBBlock): remember aggr2ptr has been used
+       * src/SDCCicode.c (operandSize): added function to handle aggr2ptr,
+         (geniCodeAssign): fixed bug 868103
+       * src/SDCCicode.h: made operand.aggr2ptr 2 bits wide,
+         added operandSize prototype
+       * src/mcs51/gen.c (aopOp): use operandSize to fix bug 868103,
+         (genDataPointerSet): use size of result,
+         (gencjne): added parameter useCarry for optimization,
+         (genCmpEq): use carry if appropriate,
+         (genXor): check if operand already in carry
+       * support/regression/tests/bug-868103.c: enabled test
+
 2007-07-12 Raphael Neider <rneider AT web.de>
 
        * src/pic16/gen.c (genNearPointerSet): fixed handling of literals
index 7d86488d608017f3c36d5c4c96243ea6a5d63f23..d33632abea2854df7283aaeebb5875987b545400 100644 (file)
@@ -188,7 +188,7 @@ replaceAllSymBySym (iCode * ic, operand * from, operand * to, bitVect ** ndpset)
 #endif
   for (lic = ic; lic; lic = lic->next)
     {
-      int siaddr;
+      int isaddr;
 
       /* do the special cases first */
       if (lic->op == IFX)
@@ -199,9 +199,9 @@ replaceAllSymBySym (iCode * ic, operand * from, operand * to, bitVect ** ndpset)
 
               bitVectUnSetBit (OP_USES (from), lic->key);
               OP_USES(to)=bitVectSetBit (OP_USES (to), lic->key);
-              siaddr = IC_COND (lic)->isaddr;
+              isaddr = IC_COND (lic)->isaddr;
               IC_COND (lic) = operandFromOperand (to);
-              IC_COND (lic)->isaddr = siaddr;
+              IC_COND (lic)->isaddr = isaddr;
 
             }
           continue;
@@ -215,9 +215,9 @@ replaceAllSymBySym (iCode * ic, operand * from, operand * to, bitVect ** ndpset)
 
               bitVectUnSetBit (OP_USES (from), lic->key);
               OP_USES(to)=bitVectSetBit (OP_USES (to), lic->key);
-              siaddr = IC_COND (lic)->isaddr;
+              isaddr = IC_COND (lic)->isaddr;
               IC_JTCOND (lic) = operandFromOperand (to);
-              IC_JTCOND (lic)->isaddr = siaddr;
+              IC_JTCOND (lic)->isaddr = isaddr;
 
             }
           continue;
@@ -246,9 +246,9 @@ replaceAllSymBySym (iCode * ic, operand * from, operand * to, bitVect ** ndpset)
               bitVectUnSetBit (OP_DEFS (from), lic->key);
               OP_DEFS(to)=bitVectSetBit (OP_DEFS (to), lic->key);
             }
-          siaddr = IC_RESULT (lic)->isaddr;
+          isaddr = IC_RESULT (lic)->isaddr;
           IC_RESULT (lic) = operandFromOperand (to);
-          IC_RESULT (lic)->isaddr = siaddr;
+          IC_RESULT (lic)->isaddr = isaddr;
         }
 
       if (IS_SYMOP (to) &&
@@ -256,9 +256,9 @@ replaceAllSymBySym (iCode * ic, operand * from, operand * to, bitVect ** ndpset)
         {
           bitVectUnSetBit (OP_USES (from), lic->key);
           OP_USES(to)=bitVectSetBit (OP_USES (to), lic->key);
-          siaddr = IC_RIGHT (lic)->isaddr;
+          isaddr = IC_RIGHT (lic)->isaddr;
           IC_RIGHT (lic) = operandFromOperand (to);
-          IC_RIGHT (lic)->isaddr = siaddr;
+          IC_RIGHT (lic)->isaddr = isaddr;
         }
 
       if (IS_SYMOP (to) &&
@@ -266,9 +266,9 @@ replaceAllSymBySym (iCode * ic, operand * from, operand * to, bitVect ** ndpset)
         {
           bitVectUnSetBit (OP_USES (from), lic->key);
           OP_USES(to)=bitVectSetBit (OP_USES (to), lic->key);
-          siaddr = IC_LEFT (lic)->isaddr;
+          isaddr = IC_LEFT (lic)->isaddr;
           IC_LEFT (lic) = operandFromOperand (to);
-          IC_LEFT (lic)->isaddr = siaddr;
+          IC_LEFT (lic)->isaddr = isaddr;
         }
     }
 }
@@ -1980,11 +1980,11 @@ cseBBlock (eBBlock * ebb, int computeOnly,
               IC_LEFT (ic)->aggr2ptr = 0;
               fixUpTypes (ic);
             }
-          else if (IC_LEFT (ic)->aggr2ptr)
+          else if (IC_LEFT (ic)->aggr2ptr == 1)
             {/* band aid for kludge */
               setOperandType (IC_LEFT (ic),
                               aggrToPtr (operandType (IC_LEFT (ic)), TRUE));
-              IC_LEFT (ic)->aggr2ptr = 0;
+              IC_LEFT (ic)->aggr2ptr++;
               fixUpTypes (ic);
             }
         }
@@ -1997,11 +1997,11 @@ cseBBlock (eBBlock * ebb, int computeOnly,
                               aggrToPtr (operandType (IC_RESULT (ic)), FALSE));
               IC_RESULT (ic)->aggr2ptr = 0;
             }
-          else if (IC_RESULT (ic)->aggr2ptr)
+          else if (IC_RESULT (ic)->aggr2ptr == 1)
             {/* band aid for kludge */
               setOperandType (IC_RESULT (ic),
                               aggrToPtr (operandType (IC_RESULT (ic)), TRUE));
-              IC_RESULT (ic)->aggr2ptr = 0;
+              IC_RESULT (ic)->aggr2ptr++;
             }
         }
 
@@ -2090,7 +2090,7 @@ cseBBlock (eBBlock * ebb, int computeOnly,
             }
         }
 
-      /*right operand */
+      /* right operand */
       if (IS_SYMOP (IC_RIGHT (ic)) && !computeOnly)
         {
 
@@ -2202,7 +2202,6 @@ cseBBlock (eBBlock * ebb, int computeOnly,
           deleteItemIf (&cseSet, ifOperandsHave, IC_RESULT (ic));
           /* delete any previous definitions */
           ebb->defSet = bitVectCplAnd (ebb->defSet, OP_DEFS (IC_RESULT (ic)));
-
         }
 
       /* add the left & right to the defUse set */
@@ -2211,7 +2210,6 @@ cseBBlock (eBBlock * ebb, int computeOnly,
           OP_USES(IC_LEFT (ic))=
             bitVectSetBit (OP_USES (IC_LEFT (ic)), ic->key);
           setUsesDefs (IC_LEFT (ic), ebb->defSet, ebb->outDefs, &ebb->usesDefs);
-
         }
 
       if (IC_RIGHT (ic) && IS_SYMOP (IC_RIGHT (ic)))
@@ -2219,7 +2217,6 @@ cseBBlock (eBBlock * ebb, int computeOnly,
           OP_USES(IC_RIGHT (ic))=
             bitVectSetBit (OP_USES (IC_RIGHT (ic)), ic->key);
           setUsesDefs (IC_RIGHT (ic), ebb->defSet, ebb->outDefs, &ebb->usesDefs);
-
         }
 
       /* for the result it is special case, put the result */
index 2c0b61eab1d9943fa53dd57be9171ea27749e97b..24def78eaa8f558fb652ae6eff3b8fd9c10cb5f3 100644 (file)
@@ -819,6 +819,24 @@ operandType (operand * op)
     }
 }
 
+/*-----------------------------------------------------------------*/
+/* operandSize - returns size of an operand in bytes               */
+/*-----------------------------------------------------------------*/
+unsigned int 
+operandSize (operand * op)
+{
+  sym_link *type;
+
+  /* if nothing return 0 */
+  if (!op)
+    return 0;
+
+  type = operandType (op);
+  if (op->aggr2ptr == 2)
+    type = type->next;
+  return getSize (type);
+}
+
 /*-----------------------------------------------------------------*/
 /* isParamterToCall - will return 1 if op is a parameter to args   */
 /*-----------------------------------------------------------------*/
@@ -3204,7 +3222,9 @@ geniCodeAssign (operand * left, operand * right, int nosupdate, int strictLval)
   if (left->isaddr && IS_PTR (ltype) && IS_ITEMP (left) &&
       compareType (ltype, rtype) <= 0)
     {
-      if (compareType (ltype->next, rtype) < 0)
+      if (left->aggr2ptr)
+        right = geniCodeCast (ltype, right, TRUE);
+      else if (compareType (ltype->next, rtype) < 0)
         right = geniCodeCast (ltype->next, right, TRUE);
     }
   else if (compareType (ltype, rtype) < 0)
@@ -4291,7 +4311,7 @@ ast2iCode (ast * tree,int lvl)
                             tree->opval.op);
       */
       {
-        operand *leftOp, *rightOp;
+               operand *leftOp, *rightOp;
 
         leftOp  = geniCodeRValue (left , FALSE);
         rightOp = geniCodeRValue (right, FALSE);
index a05c67c478135e113070735bee2db4a6ca054a97..30e730a855d1439323f8dc5bf28ba39ad8360203 100644 (file)
@@ -75,7 +75,8 @@ typedef struct operand
   {
     OPTYPE type;                /* type of operand */
     unsigned int isaddr:1;      /* is an address   */
-    unsigned int aggr2ptr:1;    /* must change aggregate to pointer to aggregate */
+    unsigned int aggr2ptr:2;    /* 1: must change aggregate to pointer to aggregate */
+                                /* 2: aggregate has been changed to pointer to aggregate */
     unsigned int isvolatile:1;  /* is a volatile operand */
     unsigned int isGlobal:1;    /* is a global operand */
     unsigned int isPtr:1;       /* is assigned a pointer */
@@ -322,6 +323,7 @@ symbol *newiTempLabel (char *);
 symbol *newiTempLoopHeaderLabel (bool);
 iCode *newiCode (int, operand *, operand *);
 sym_link *operandType (operand *);
+unsigned int operandSize (operand *);
 operand *operandFromValue (value *);
 operand *operandFromSymbol (symbol *);
 operand *operandFromLink (sym_link *);
index dbff5f9a619a3e96fe129341c8adf161507d83f1..dd0eb5a88bba1e2c69fef266db94f8429d1e4c4a 100644 (file)
@@ -969,7 +969,7 @@ aopOp (operand * op, iCode * ic, bool result)
       if (sym->remat)
         {
           sym->aop = op->aop = aop = aopForRemat (sym);
-          aop->size = getSize (sym->type);
+          aop->size = operandSize (op);
           return;
         }
 
@@ -6116,7 +6116,7 @@ gencjneshort (operand * left, operand * right, symbol * lbl)
 /* gencjne - compare and jump if not equal                         */
 /*-----------------------------------------------------------------*/
 static void
-gencjne (operand * left, operand * right, symbol * lbl)
+gencjne (operand * left, operand * right, symbol * lbl, bool useCarry)
 {
   symbol *tlbl = newiTempLabel (NULL);
 
@@ -6124,10 +6124,16 @@ gencjne (operand * left, operand * right, symbol * lbl)
 
   gencjneshort (left, right, lbl);
 
-  emitcode ("mov", "a,%s", one);
+  if (useCarry)
+      SETC;
+  else
+      MOVA (one);
   emitcode ("sjmp", "%05d$", tlbl->key + 100);
   emitLabel (lbl);
-  emitcode ("clr", "a");
+  if (useCarry)
+      CLRC;
+  else
+      MOVA (zero);
   emitLabel (tlbl);
 }
 
@@ -6288,12 +6294,13 @@ genCmpEq (iCode * ic, iCode * ifx)
     }
   else
     {
-      gencjne (left, right, newiTempLabel (NULL));
       if (AOP_TYPE (result) == AOP_CRY && AOP_SIZE (result))
         {
-          aopPut (result, "a", 0);
+          gencjne (left, right, newiTempLabel (NULL), TRUE);
+          aopPut (result, "c", 0);
           goto release;
         }
+      gencjne (left, right, newiTempLabel (NULL), FALSE);
       if (ifx)
         {
           genIfxJump (ifx, "a", left, right, result);
@@ -7448,7 +7455,16 @@ genXor (iCode * ic, iCode * ifx)
           if (AOP_TYPE (right) == AOP_CRY)
             {
               // c = bit ^ bit;
-              emitcode ("mov", "c,%s", AOP (right)->aopu.aop_dir);
+              if (IS_SYMOP (left) && OP_SYMBOL (left) && OP_SYMBOL (left)->accuse)
+                {// left already is in the carry
+                  operand *tmp = right;
+                  right = left;
+                  left = tmp;
+                }
+              else
+                {
+                  emitcode ("mov", "c,%s", AOP (right)->aopu.aop_dir);
+                }
             }
           else
             {
@@ -10519,7 +10535,7 @@ genDataPointerSet (operand * right,
 
   l = aopGet (result, 0, FALSE, TRUE);
   l++; //remove #
-  size = AOP_SIZE (right);
+  size = AOP_SIZE (result);
   while (size--)
     {
       if (offset)
@@ -10530,8 +10546,8 @@ genDataPointerSet (operand * right,
                 aopGet (right, offset++, FALSE, FALSE));
     }
 
-  freeAsmop (result, NULL, ic, TRUE);
   freeAsmop (right, NULL, ic, TRUE);
+  freeAsmop (result, NULL, ic, TRUE);
 }
 
 /*-----------------------------------------------------------------*/
@@ -10660,9 +10676,10 @@ genNearPointerSet (operand * right,
     }
 
   /* done */
-  if (pi) pi->generated = 1;
-  freeAsmop (result, NULL, ic, TRUE);
+  if (pi)
+    pi->generated = 1;
   freeAsmop (right, NULL, ic, TRUE);
+  freeAsmop (result, NULL, ic, TRUE);
 }
 
 /*-----------------------------------------------------------------*/
index ed2c04e72bd1324be1736d57eb642506c5f2e886..6180aa81d7a710be2e7894499a2daa9fc7f850bb 100644 (file)
 
 #include <testfwk.h>
 
-#if defined(PORT_HOST) || defined(SDCC_z80) || defined(SDCC_gbz80)
-# define near
-# define far
-# define code
-#endif
-
 typedef struct {
   STORAGE1 char * bar[2];
 } foo;
@@ -27,7 +21,8 @@ typedef struct {
 STORAGE1 char c = 'x';
 STORAGE2 foo f;
 
-void bug868103(void)
+void
+testBug868103(void)
 {
   f.bar[1] = &c;
   ASSERT(f.bar[1] == &c);