* src/SDCCast.c (constExprValue): return NULL if not a value
authormaartenbrock <maartenbrock@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Mon, 13 Feb 2006 22:48:50 +0000 (22:48 +0000)
committermaartenbrock <maartenbrock@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Mon, 13 Feb 2006 22:48:50 +0000 (22:48 +0000)
* src/SDCCglue.c (printIvalArray): fixed bug 1225568
* src/hc08/gen.c(genUnpackBits, genUnpackBitsImmed): fixed bug 1019480
* support/regression/tests/bitfields.c: enabled signed bitfield for all

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

ChangeLog
src/SDCCast.c
src/SDCCglue.c
src/hc08/gen.c
support/regression/tests/bitfields.c

index e2849995f2c0e9ba2dce1eb0af4ec1c72e82b7bf..8ad899526c5e781f79b5b7ca24c2fbe3ae00cc6d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,7 +1,14 @@
+2006-02-13 Maarten Brock <sourceforge.brock AT dse.nl>
+
+       * src/SDCCast.c (constExprValue): return NULL if not a value
+       * src/SDCCglue.c (printIvalArray): fixed bug 1225568
+       * src/hc08/gen.c(genUnpackBits, genUnpackBitsImmed): fixed bug 1019480
+       * support/regression/tests/bitfields.c: enabled signed bitfield for all
+
 2006-02-13 Borut Razem <borut.razem AT siol.net>
 
        * src/regression/ptrarg.c: added, fails due to bug #1430967
-       * src/regression/Makefiel: ptrarg.c added, ...
+       * src/regression/Makefile: ptrarg.c added, ...
 
 2006-02-12 Maarten Brock <sourceforge.brock AT dse.nl>
 
index 86fad20a2c504b803c58a6f1326c60858f92d4ca..f27842ea4970e7cfd6cab1294595879fc0e9aef7 100644 (file)
@@ -1467,8 +1467,11 @@ constExprValue (ast * cexpr, int check)
     }
 
   /* return the value */
-  return cexpr->opval.val;
-
+  if (IS_AST_VALUE (cexpr))
+    {
+      return cexpr->opval.val;
+    }
+   return NULL;
 }
 
 /*-----------------------------------------------------------------*/
@@ -2250,7 +2253,7 @@ getLeftResultType (ast *tree, RESULT_TYPE resultType)
 /*--------------------------------------------------------------------*/
 /* decorateType - compute type for this tree, also does type checking.*/
 /* This is done bottom up, since type has to flow upwards.            */
-/* resultType flows top-down and forces e.g. char-arithmetik, if the  */
+/* resultType flows top-down and forces e.g. char-arithmetic, if the  */
 /* result is a char and the operand(s) are int's.                     */
 /* It also does constant folding, and parameter checking.             */
 /*--------------------------------------------------------------------*/
@@ -5220,12 +5223,12 @@ optimizeRRCRLC (ast * root)
      into a RRC operation
      note : by 7 I mean (number of bits required to hold the
      variable -1 ) */
-  /* if the root operations is not a | operation the not */
+  /* if the root operation is not a | operation then not */
   if (!IS_BITOR (root))
     return root;
 
   /* I have to think of a better way to match patterns this sucks */
-  /* that aside let start looking for the first case : I use a the
+  /* that aside let's start looking for the first case : I use a
      negative check a lot to improve the efficiency */
   /* (?expr << 1) | (?expr >> 7) */
   if (IS_LEFT_OP (root->left) &&
@@ -5383,7 +5386,7 @@ optimizeSWAP (ast * root)
      into a SWAP : operation ..
      note : by 4 I mean (number of bits required to hold the
      variable /2 ) */
-  /* if the root operations is not a | operation the not */
+  /* if the root operation is not a | operation then not */
   if (!IS_BITOR (root))
     return root;
 
index c803c0be0bcce0675f6a7b600725cc839598fe94..671909ed06ad2d4c2a68042e0c14dbf908c79053 100644 (file)
@@ -836,6 +836,7 @@ void
 printIvalArray (symbol * sym, sym_link * type, initList * ilist,
                 FILE * oFile)
 {
+  value *val;
   initList *iloop;
   unsigned int size = 0;
 
@@ -844,7 +845,12 @@ printIvalArray (symbol * sym, sym_link * type, initList * ilist,
     /* array of characters can be init  */
     /* by a string                      */
     if (IS_CHAR (type->next)) {
-      if (!IS_LITERAL(list2val(ilist)->etype)) {
+      val = list2val(ilist);
+      if (!val) {
+        werrorfl (ilist->filename, ilist->lineno, E_INIT_STRUCT, sym->name);
+        return;
+      }
+      if (!IS_LITERAL(val->etype)) {
         werrorfl (ilist->filename, ilist->lineno, E_CONST_EXPECTED);
         return;
       }
index d824ed12ff01db6f3cd4affd86e666402919f083..c364471101b43dac26be1cd2d49b26f777b7fd77 100644 (file)
@@ -6912,22 +6912,38 @@ genUnpackBits (operand * result, iCode *ifx)
   blen = SPEC_BLEN (etype);
   bstr = SPEC_BSTR (etype);
 
-  /* If the bitfield length is less than a byte */
-  if (blen < 8)
+  if (ifx && blen <= 8)
     {
       emitcode ("lda", ",x");
       hc08_dirtyReg (hc08_reg_a, FALSE);
-      if (!ifx)
-        {
-          AccRsh (bstr, FALSE);
-          emitcode ("and", "#0x%02x", ((unsigned char) -1) >> (8 - blen));
-          storeRegToAop (hc08_reg_a, AOP (result), offset++);
-        }
-      else
+      if (blen < 8)
         {
           emitcode ("and", "#0x%02x",
                     (((unsigned char) -1) >> (8 - blen)) << bstr);
         }
+      genIfxJump (ifx, "a");
+      return;
+    }
+  wassert (!ifx);
+
+  /* If the bitfield length is less than a byte */
+  if (blen < 8)
+    {
+      emitcode ("lda", ",x");
+      hc08_dirtyReg (hc08_reg_a, FALSE);
+      AccRsh (bstr, FALSE);
+      emitcode ("and", "#0x%02x", ((unsigned char) -1) >> (8 - blen));
+      if (!SPEC_USIGN (etype))
+        {
+          /* signed bitfield */
+          symbol *tlbl = newiTempLabel (NULL);
+
+          emitcode ("bit", "#0x%02x", 1<<(blen - 1));
+          emitcode ("beq", "%05d$", tlbl->key + 100);
+          emitcode ("ora", "#0x%02x", (unsigned char) (0xff << blen));
+          emitLabel (tlbl);
+        }
+      storeRegToAop (hc08_reg_a, AOP (result), offset++);
       goto finish;
     }
 
@@ -6937,8 +6953,7 @@ genUnpackBits (operand * result, iCode *ifx)
     {
       emitcode ("lda", ",x");
       hc08_dirtyReg (hc08_reg_a, FALSE);
-      if (!ifx)
-        storeRegToAop (hc08_reg_a, AOP (result), offset);
+      storeRegToAop (hc08_reg_a, AOP (result), offset);
       offset++;
       if (rlen>8)
         emitcode ("aix", "#1");
@@ -6949,6 +6964,16 @@ genUnpackBits (operand * result, iCode *ifx)
     {
       emitcode ("lda", ",x");
       emitcode ("and", "#0x%02x", ((unsigned char) -1) >> (8-rlen));
+      if (!SPEC_USIGN (etype))
+        {
+          /* signed bitfield */
+          symbol *tlbl = newiTempLabel (NULL);
+
+          emitcode ("bit", "#0x%02x", 1<<(rlen - 1));
+          emitcode ("beq", "%05d$", tlbl->key + 100);
+          emitcode ("ora", "#0x%02x", (unsigned char) (0xff << rlen));
+          emitLabel (tlbl);
+        }
       storeRegToAop (hc08_reg_a, AOP (result), offset++);
     }
 
@@ -6956,13 +6981,21 @@ finish:
   if (offset < rsize)
     {
       rsize -= offset;
-      while (rsize--)
-        storeConstToAop (zero, AOP (result), offset++);
-    }
+      if (SPEC_USIGN (etype))
+        {
+          while (rsize--)
+            storeConstToAop (zero, AOP (result), offset++);
+        }
+      else
+        {
+          /* signed bitfield: sign extension with 0x00 or 0xff */
+          emitcode ("rola", "");
+          emitcode ("clra", "");
+          emitcode ("sbc", zero);
   
-  if (ifx && !ifx->generated)
-    {
-      genIfxJump (ifx, "a");
+          while (rsize--)
+            storeRegToAop (hc08_reg_a, AOP (result), offset++);
+        }
     }
 }
 
@@ -7010,7 +7043,10 @@ genUnpackBitsImmed (operand * left,
           emitcode ("brclr", "#%d,%s,%05d$",
                     bstr, aopAdrStr (derefaop, 0, FALSE),
                     (tlbl->key + 100));
-          rmwWithReg ("inc", hc08_reg_a);
+          if (SPEC_USIGN (etype))
+            rmwWithReg ("inc", hc08_reg_a);
+          else
+            rmwWithReg ("dec", hc08_reg_a);
           emitLabel (tlbl);
           storeRegToAop (hc08_reg_a, AOP (result), offset);
           hc08_freeReg (hc08_reg_a);
@@ -7053,6 +7089,16 @@ genUnpackBitsImmed (operand * left,
           AccRsh (bstr, FALSE);
           emitcode ("and", "#0x%02x", ((unsigned char) -1) >> (8 - blen));
           hc08_dirtyReg (hc08_reg_a, FALSE);
+          if (!SPEC_USIGN (etype))
+            {
+              /* signed bitfield */
+              symbol *tlbl = newiTempLabel (NULL);
+
+              emitcode ("bit", "#0x%02x", 1<<(blen - 1));
+              emitcode ("beq", "%05d$", tlbl->key + 100);
+              emitcode ("ora", "#0x%02x", (unsigned char) (0xff << blen));
+              emitLabel (tlbl);
+            }
           storeRegToAop (hc08_reg_a, AOP (result), offset);
         }
       else
@@ -7082,6 +7128,16 @@ genUnpackBitsImmed (operand * left,
     {
       loadRegFromAop (hc08_reg_a, derefaop, size-offset-1);
       emitcode ("and", "#0x%02x", ((unsigned char) -1) >> (8-rlen));
+      if (!SPEC_USIGN (etype))
+        {
+          /* signed bitfield */
+          symbol *tlbl = newiTempLabel (NULL);
+
+          emitcode ("bit", "#0x%02x", 1<<(rlen - 1));
+          emitcode ("beq", "%05d$", tlbl->key + 100);
+          emitcode ("ora", "#0x%02x", (unsigned char) (0xff << rlen));
+          emitLabel (tlbl);
+        }
       storeRegToAop (hc08_reg_a, AOP (result), offset++);
     }
 
@@ -7089,8 +7145,21 @@ finish:
   if (offset < rsize)
     {
       rsize -= offset;
-      while (rsize--)
-        storeConstToAop (zero, AOP (result), offset++);
+      if (SPEC_USIGN (etype))
+        {
+          while (rsize--)
+            storeConstToAop (zero, AOP (result), offset++);
+        }
+      else
+        {
+          /* signed bitfield: sign extension with 0x00 or 0xff */
+          emitcode ("rola", "");
+          emitcode ("clra", "");
+          emitcode ("sbc", zero);
+
+          while (rsize--)
+            storeRegToAop (hc08_reg_a, AOP (result), offset++);
+        }
     }
   
   freeAsmop (NULL, derefaop, ic, TRUE);
index 095734fb6958eec07fd24029b62eaef31defa287..7007741142d02d80e72e5cbbf18dd29f8df8c824 100644 (file)
@@ -131,16 +131,16 @@ testBitfieldSizeof(void)
 void
 testBitfieldsSingleBitLiteral(void)
 {
-  size2b_bf.b0 = 0; 
-  size2b_bf.b1 = 0; 
-  size2b_bf.b2 = 0; 
-  size2b_bf.b3 = 0; 
-  size2b_bf.b4 = 0; 
-  size2b_bf.b5 = 0; 
-  size2b_bf.b6 = 0; 
-  size2b_bf.b7 = 0; 
-  size2b_bf.b8 = 0; 
-  size2b_bf.b9 = 0; 
+  size2b_bf.b0 = 0;
+  size2b_bf.b1 = 0;
+  size2b_bf.b2 = 0;
+  size2b_bf.b3 = 0;
+  size2b_bf.b4 = 0;
+  size2b_bf.b5 = 0;
+  size2b_bf.b6 = 0;
+  size2b_bf.b7 = 0;
+  size2b_bf.b8 = 0;
+  size2b_bf.b9 = 0;
 
   /* make sure modulo 2 truncation works */
   size2b_bf.b0 = 0x3fe;
@@ -186,16 +186,16 @@ testBitfieldsSingleBit(void)
   volatile unsigned char c;
 
   c = 0;
-  size2b_bf.b0 = c; 
-  size2b_bf.b1 = c; 
-  size2b_bf.b2 = c; 
-  size2b_bf.b3 = c; 
-  size2b_bf.b4 = c; 
-  size2b_bf.b5 = c; 
-  size2b_bf.b6 = c; 
-  size2b_bf.b7 = c; 
-  size2b_bf.b8 = c; 
-  size2b_bf.b9 = c; 
+  size2b_bf.b0 = c;
+  size2b_bf.b1 = c;
+  size2b_bf.b2 = c;
+  size2b_bf.b3 = c;
+  size2b_bf.b4 = c;
+  size2b_bf.b5 = c;
+  size2b_bf.b6 = c;
+  size2b_bf.b7 = c;
+  size2b_bf.b8 = c;
+  size2b_bf.b9 = c;
 
   /* make sure modulo 2 truncation works */
   c = 0xfe;
@@ -287,7 +287,7 @@ testBitfieldsMultibit(void)
   volatile int allones = 0xffff;
   volatile int zero = 0;
   volatile int x;
-  
+
   size2c_bf.b0 = allones;      /* should truncate to 0x0f */
   size2c_bf.b1 = zero;
   ASSERT(size2c_bf.b0==0x0f);
@@ -345,7 +345,6 @@ testBitfields(void)
 void
 testSignedBitfields(void)
 {
-#if !defined(SDCC_hc08)
   s_bf.s0_7 =   0xf0;
   s_bf.s7_1 =      1;
   s_bf.s8_9 = 0xfff8;
@@ -364,5 +363,4 @@ testSignedBitfields(void)
   ASSERT(s_bf.s8_9 == 0xff);
   ASSERT(s_bf.s0_7 > 0);
   ASSERT(s_bf.s8_9 > 0);
-#endif
 }