* src/ds390/gen.c (opIsGptr, adjustArithmeticResult, genAddrOf, genAssign),
authorMaartenBrock <MaartenBrock@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Fri, 21 Mar 2008 18:05:23 +0000 (18:05 +0000)
committerMaartenBrock <MaartenBrock@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Fri, 21 Mar 2008 18:05:23 +0000 (18:05 +0000)
* src/mcs51/gen.c (opIsGptr, adjustArithmeticResult, genAddrOf, genAssign):
  fixed bug 1839277
* src/mcs51/gen.c: throughout only output hex constants
* src/SDCCicode.c (getPtrType, geniCodeCast): fixed code size regression

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

ChangeLog
src/SDCCicode.c
src/ds390/gen.c
src/mcs51/gen.c

index ffddb6e3d20aa0507d4aec9affd8dabb9c515621..67ae67737e7163220985b5cb63e79fdcb755d7cb 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2008-03-21 Maarten Brock <sourceforge.brock AT dse.nl>
+
+       * src/ds390/gen.c (opIsGptr, adjustArithmeticResult, genAddrOf, genAssign),
+       * src/mcs51/gen.c (opIsGptr, adjustArithmeticResult, genAddrOf, genAssign):
+         fixed bug 1839277
+       * src/mcs51/gen.c: throughout only output hex constants
+       * src/SDCCicode.c (getPtrType, geniCodeCast): fixed code size regression
+
 2008-03-21 Philipp Klaus Krause <pkk AT spth.de>
 
        * src/z80/ralloc.c (callFuncByName):
index 03da8a0c88f8dc811ee1bb93c4a0ac4895b46af9..0c5264fddcaab7dd342cdc0fd5545e0528a087dc 100644 (file)
@@ -801,7 +801,6 @@ operandType (operand * op)
   /* depending on type of operand */
   switch (op->type)
     {
-
     case VALUE:
       return op->operand.valOperand->type;
 
@@ -810,6 +809,7 @@ operandType (operand * op)
 
     case TYPE:
       return op->operand.typeOperand;
+
     default:
       werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
               " operand type not known ");
@@ -1947,6 +1947,33 @@ geniCodeRValue (operand * op, bool force)
   return IC_RESULT (ic);
 }
 
+static DECLARATOR_TYPE
+getPtrType(sym_link *type)
+{
+  //for Z80 anything goes
+  if (TARGET_Z80_LIKE)
+    return POINTER;
+
+  //for HC08 only zeropage ptr is different
+  if (TARGET_IS_HC08)
+    {
+      if (IS_DATA_PTR (type))
+        return POINTER;
+      else
+        return FPOINTER;
+    }
+
+  if (IS_DATA_PTR (type) && TARGET_MCS51_LIKE)
+    return IPOINTER;
+  if (IS_PTR (type))
+    return DCL_TYPE (type);
+  else if (IS_FUNC (type))
+    return CPOINTER;
+  else if (IS_ARRAY (type))
+    return PTR_TYPE (SPEC_OCLS (getSpec (type)));
+  return UPOINTER;
+}
+
 /*-----------------------------------------------------------------*/
 /* geniCodeCast - changes the value from one type to another       */
 /*-----------------------------------------------------------------*/
@@ -1979,8 +2006,7 @@ geniCodeCast (sym_link * type, operand * op, bool implicit)
   /* if this is a literal then just change the type & return */
   if (IS_LITERAL (opetype) && op->type == VALUE && !IS_PTR (type) && !IS_PTR (optype))
     {
-      return operandFromValue (valCastLiteral (type,
-                                               operandLitValue (op)));
+      return operandFromValue (valCastLiteral (type, operandLitValue (op)));
     }
 
   /* if casting to/from pointers, do some checking */
@@ -2068,7 +2094,7 @@ geniCodeCast (sym_link * type, operand * op, bool implicit)
       !IS_FIXED (type) &&
       !IS_FIXED (optype) &&
       ((IS_SPEC (type) && IS_SPEC (optype)) ||
-       (IS_DECL (type) && IS_DECL (optype) && DCL_TYPE (type) == DCL_TYPE (optype))))
+       (IS_DECL (type) && IS_DECL (optype) && getPtrType (type) == getPtrType (optype))))
     {
       ic = newiCode ('=', NULL, op);
       IC_RESULT (ic) = newiTempOperand (type, 0);
index da277d24b43a9004356acdc23e97ed772eb39fad..761b4a9d3cea90939a60f918c93ec4bbd3e8b2b3 100644 (file)
@@ -1947,9 +1947,7 @@ reAdjustPreg (asmop * aop)
 static int
 opIsGptr (operand * op)
 {
-  sym_link *type = operandType (op);
-
-  if ((AOP_SIZE (op) == GPTRSIZE) && IS_GENPTR (type))
+  if (op && IS_GENPTR (operandType (op)) && (AOP_SIZE (op) == GPTRSIZE))
     {
       return 1;
     }
@@ -1962,8 +1960,8 @@ opIsGptr (operand * op)
 static int
 getDataSize (operand * op)
 {
-  int size;
-  size = AOP_SIZE (op);
+  int size = AOP_SIZE (op);
+
   if (size == GPTRSIZE)
     {
       sym_link *type = operandType (op);
@@ -4467,8 +4465,8 @@ adjustArithmeticResult (iCode * ic)
     }
 
   if (opIsGptr (IC_RESULT (ic)) &&
-      AOP_SIZE (IC_LEFT (ic)) < GPTRSIZE &&
-      AOP_SIZE (IC_RIGHT (ic)) < GPTRSIZE &&
+      IC_LEFT (ic) && AOP_SIZE (IC_LEFT (ic)) < GPTRSIZE &&
+      IC_RIGHT (ic) && AOP_SIZE (IC_RIGHT (ic)) < GPTRSIZE &&
       !sameRegs (AOP (IC_RESULT (ic)), AOP (IC_LEFT (ic))) &&
       !sameRegs (AOP (IC_RESULT (ic)), AOP (IC_RIGHT (ic))))
     {
@@ -11952,13 +11950,14 @@ genAddrOf (iCode * ic)
   }
 
   /* object not on stack then we need the name */
-  size = AOP_SIZE (IC_RESULT (ic));
+  size = getDataSize (IC_RESULT (ic));
   offset = 0;
 
   while (size--)
     {
       char s[SDCC_NAME_MAX];
-      if (offset) {
+      if (offset)
+        {
           switch (offset) {
           case 1:
               tsprintf(s, sizeof(s), "#!his",sym->rname);
@@ -11970,9 +11969,7 @@ genAddrOf (iCode * ic)
               tsprintf(s, sizeof(s), "#!hihihis",sym->rname);
               break;
           default: /* should not need this (just in case) */
-              SNPRINTF (s, sizeof(s), "#(%s >> %d)",
-                       sym->rname,
-                       offset * 8);
+              SNPRINTF (s, sizeof(s), "#(%s >> %d)", sym->rname, offset * 8);
           }
       }
       else
@@ -11982,6 +11979,13 @@ genAddrOf (iCode * ic)
 
       aopPut (IC_RESULT (ic), s, offset++);
     }
+  if (opIsGptr (IC_RESULT (ic)))
+    {
+      char buffer[10];
+      SNPRINTF (buffer, sizeof(buffer), "#0x%02x",
+                pointerTypeToGPByte (pointerCode (getSpec (operandType (IC_LEFT (ic)))), NULL, NULL));
+      aopPut (IC_RESULT (ic), buffer, GPTRSIZE - 1);
+    }
 
 release:
   freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
@@ -12270,7 +12274,7 @@ genAssign (iCode * ic)
 
   /* bit variables done */
   /* general case */
-  size = AOP_SIZE (result);
+  size = getDataSize (result);
   offset = 0;
   if (AOP_TYPE (right) == AOP_LIT)
     lit = ulFromVal (AOP (right)->aopu.aop_lit);
@@ -12312,6 +12316,7 @@ genAssign (iCode * ic)
         }
       _endLazyDPSEvaluation ();
     }
+  adjustArithmeticResult (ic);
 
 release:
   freeAsmop (result, NULL, ic, TRUE);
index 9db691c3917305b244b58a6d05f6645a4393de48..a8086d65a1726b9e9fdf7bdf85a236c2c5ac83f9 100644 (file)
@@ -1786,15 +1786,13 @@ reAdjustPreg (asmop * aop)
 }
 
 /*-----------------------------------------------------------------*/
-/* opIsGptr: returns non-zero if the passed operand is       */
-/* a generic pointer type.             */
+/* opIsGptr: returns non-zero if the passed operand is             */
+/* a generic pointer type.                                         */
 /*-----------------------------------------------------------------*/
 static int
 opIsGptr (operand * op)
 {
-  sym_link *type = operandType (op);
-
-  if ((AOP_SIZE (op) == GPTRSIZE) && IS_GENPTR (type))
+  if (op && IS_GENPTR (operandType (op)) && (AOP_SIZE (op) == GPTRSIZE))
     {
       return 1;
     }
@@ -1807,8 +1805,8 @@ opIsGptr (operand * op)
 static int
 getDataSize (operand * op)
 {
-  int size;
-  size = AOP_SIZE (op);
+  int size = AOP_SIZE (op);
+
   if (size == GPTRSIZE)
     {
       sym_link *type = operandType (op);
@@ -2173,7 +2171,7 @@ genUminus (iCode * ic)
           if (offset == 0)
             SETC;
           emitcode ("cpl", "a");
-          emitcode ("addc", "a,#0");
+          emitcode ("addc", "a,#0x00");
         }
       else
         {
@@ -2277,7 +2275,7 @@ saveRegisters (iCode * lic)
             }
           emitcode ("mov", "r0,%s", spname);
           MOVA ("r0");
-          emitcode ("add", "a,#%d", count);
+          emitcode ("add", "a,#0x%02x", count);
           emitcode ("mov", "%s,a", spname);
           for (i = 0; i < mcs51_nRegs; i++)
             {
@@ -2523,7 +2521,7 @@ genXpush (iCode * ic)
       // allocate space first
       emitcode ("mov", "%s,%s", r->name, spname);
       MOVA (r->name);
-      emitcode ("add", "a,#%d", size);
+      emitcode ("add", "a,#0x%02x", size);
       emitcode ("mov", "%s,a", spname);
 
       while (size--)
@@ -2666,7 +2664,7 @@ saveRBank (int bank, iCode * ic, bool pushPsw)
       // allocate space first
       emitcode ("mov", "%s,%s", r->name, spname);
       MOVA (r->name);
-      emitcode ("add", "a,#%d", count);
+      emitcode ("add", "a,#0x%02x", count);
       emitcode ("mov", "%s,a", spname);
     }
 
@@ -4446,14 +4444,14 @@ adjustArithmeticResult (iCode * ic)
     }
 
   if (opIsGptr (IC_RESULT (ic)) &&
-      AOP_SIZE (IC_LEFT (ic)) < GPTRSIZE &&
-      AOP_SIZE (IC_RIGHT (ic)) < GPTRSIZE &&
+      IC_LEFT (ic) && AOP_SIZE (IC_LEFT (ic)) < GPTRSIZE &&
+      IC_RIGHT (ic) && AOP_SIZE (IC_RIGHT (ic)) < GPTRSIZE &&
       !sameRegs (AOP (IC_RESULT (ic)), AOP (IC_LEFT (ic))) &&
       !sameRegs (AOP (IC_RESULT (ic)), AOP (IC_RIGHT (ic))))
     {
-      char buffer[5];
+      char buffer[10];
       SNPRINTF (buffer, sizeof(buffer),
-                "#%d", pointerTypeToGPByte (pointerCode (getSpec (operandType (IC_LEFT (ic)))), NULL, NULL));
+                "#0x%02x", pointerTypeToGPByte (pointerCode (getSpec (operandType (IC_LEFT (ic)))), NULL, NULL));
       aopPut (IC_RESULT (ic), buffer, GPTRSIZE - 1);
     }
 }
@@ -5172,10 +5170,10 @@ genMultOneByte (operand * left,
         emitcode ("inc", "a"); /* inc doesn't set carry flag */
       else
         {
-          emitcode ("add", "a,#1"); /* this sets carry flag */
+          emitcode ("add", "a,#0x01"); /* this sets carry flag */
           emitcode ("xch", "a,b");
           emitcode ("cpl", "a"); /* msb 2's complement */
-          emitcode ("addc", "a,#0");
+          emitcode ("addc", "a,#0x00");
           emitcode ("xch", "a,b");
         }
       emitLabel (lbl);
@@ -5458,7 +5456,7 @@ genDivOneByte (operand * left,
             }
           else /* compiletimeSign */
             {
-              if (aopPutUsesAcc (result, "#0xFF", offset))
+              if (aopPutUsesAcc (result, "#0xff", offset))
                 {
                   emitcode ("push", "acc");
                   pushedA = TRUE;
@@ -7178,7 +7176,7 @@ genOr (iCode * ic, iCode * ifx)
                 }
               else if (bytelit == 0x0FF)
                 {
-                  aopPut (result, "#0xFF", offset);
+                  aopPut (result, "#0xff", offset);
                 }
               else if (IS_AOP_PREG (left))
                 {
@@ -7319,7 +7317,7 @@ genOr (iCode * ic, iCode * ifx)
                       /* dummy read of volatile operand */
                       if (isOperandVolatile (left, FALSE))
                         MOVA (aopGet (left, offset, FALSE, FALSE));
-                      aopPut (result, "#0xFF", offset);
+                      aopPut (result, "#0xff", offset);
                       continue;
                     }
                 }
@@ -11018,7 +11016,7 @@ genIfx (iCode * ic, iCode * popIc)
 
   /* if there was something to be popped then do it */
   if (popIc)
-    genIpop (popIc);
+      genIpop (popIc);
 
   /* if the condition is a bit variable */
   if (isbit && dup)
@@ -11091,7 +11089,7 @@ genAddrOf (iCode * ic)
     }
 
   /* object not on stack then we need the name */
-  size = AOP_SIZE (IC_RESULT (ic));
+  size = getDataSize (IC_RESULT (ic));
   offset = 0;
 
   while (size--)
@@ -11105,6 +11103,13 @@ genAddrOf (iCode * ic)
         SNPRINTF (s, sizeof(s), "#%s", sym->rname);
       aopPut (IC_RESULT (ic), s, offset++);
     }
+  if (opIsGptr (IC_RESULT (ic)))
+    {
+      char buffer[10];
+      SNPRINTF (buffer, sizeof(buffer),
+                "#0x%02x", pointerTypeToGPByte (pointerCode (getSpec (operandType (IC_LEFT (ic)))), NULL, NULL));
+      aopPut (IC_RESULT (ic), buffer, GPTRSIZE - 1);
+    }
 
 release:
   freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
@@ -11192,7 +11197,7 @@ genAssign (iCode * ic)
 
   /* bit variables done */
   /* general case */
-  size = AOP_SIZE (result);
+  size = getDataSize (result);
   offset = 0;
   if (AOP_TYPE (right) == AOP_LIT)
     lit = ulFromVal (AOP (right)->aopu.aop_lit);
@@ -11233,6 +11238,7 @@ genAssign (iCode * ic)
           offset++;
         }
     }
+  adjustArithmeticResult (ic);
 
 release:
   freeAsmop (result, NULL, ic, TRUE);
@@ -11268,7 +11274,7 @@ genJumpTab (iCode * ic)
       /* multiply by three */
       if (aopGetUsesAcc (IC_JTCOND (ic), 0))
         {
-          emitcode ("mov", "b,#3");
+          emitcode ("mov", "b,#0x03");
           emitcode ("mul", "ab");
         }
       else
@@ -11446,7 +11452,7 @@ genCast (iCode * ic)
                     exit(1);
                 }
 
-                sprintf(gpValStr, "#0x%x", gpVal);
+                sprintf(gpValStr, "#0x%02x", gpVal);
                 aopPut (result, gpValStr, GPTRSIZE - 1);
             }
           goto release;
@@ -11919,18 +11925,18 @@ gen51Code (iCode * lic)
           break;
 
         case IPOP:
-          /* IPOP happens only when trying to restore a
-             spilt live range, if there is an ifx statement
+            /* IPOP happens only when trying to restore a
+               spilt live range, if there is an ifx statement
              following this pop then the if statement might
-             be using some of the registers being popped which
-             would destory the contents of the register so
-             we need to check for this condition and handle it */
+               be using some of the registers being popped which
+               would destory the contents of the register so
+               we need to check for this condition and handle it */
           if (ic->next &&
               ic->next->op == IFX &&
               regsInCommon (IC_LEFT (ic), IC_COND (ic->next)))
             genIfx (ic->next, ic);
-          else
-            genIpop (ic);
+            else
+              genIpop (ic);
           break;
 
         case CALL: