* src/pic16/gen.c (genAssign): removed useless compiler output
authortecodev <tecodev@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 31 Aug 2008 21:08:28 +0000 (21:08 +0000)
committertecodev <tecodev@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 31 Aug 2008 21:08:28 +0000 (21:08 +0000)
* (genPointerGet,genPointerSet,genCast),
  src/pic16/glue.c (pic16_printGPointerType):
  also handle PPOINTERs just to avoid spurious asserts
* (pic16_printIvalType,pic16_printIvalBitFields):
  generalized to arbitrary type/bitfield sizes, allows compilation of
  regression test bug-1981238.c
* (pic16_printIvalChar): fix regression test structflexarray.c
* (pic16_printIvalArray): avoid SIGSEGV on uninitialized strings
  in initialized structs and fix #1843745
* (pic16_printIvalStruct): always output initializers for all fields,
  even those not explicitly given, fixes zeropad.c regression test
* (pic16_printIvalUnion): fix union initializers (bug1426356.c,
  #2073635, #1567098, and #1485812)
* src/pic16/main.c (_pic16_keywords): remove unsupported 'pdata'

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

ChangeLog
src/pic16/gen.c
src/pic16/glue.c
src/pic16/main.c

index 1628450580f1f4bb9a0186283e2192c25b91bb54..6fb756ed84a7963cba583faa344908a08103d10b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+2008-08-31 Raphael Neider <rneider AT web.de>
+
+       * src/pic16/gen.c (genAssign): removed useless compiler output
+       * (genPointerGet,genPointerSet,genCast),
+         src/pic16/glue.c (pic16_printGPointerType):
+         also handle PPOINTERs just to avoid spurious asserts
+       * (pic16_printIvalType,pic16_printIvalBitFields):
+         generalized to arbitrary type/bitfield sizes, allows compilation of
+         regression test bug-1981238.c
+       * (pic16_printIvalChar): fix regression test structflexarray.c
+       * (pic16_printIvalArray): avoid SIGSEGV on uninitialized strings
+         in initialized structs and fix #1843745
+       * (pic16_printIvalStruct): always output initializers for all fields,
+         even those not explicitly given, fixes zeropad.c regression test
+       * (pic16_printIvalUnion): fix union initializers (bug1426356.c,
+         #2073635, #1567098, and #1485812)
+       * src/pic16/main.c (_pic16_keywords): remove unsupported 'pdata'
+
 2008-08-31 Borut Razem <borut.razem AT siol.net>
 
        * support/regression/tests/bug-895992.c,
@@ -5,7 +23,7 @@
          enabled pic16 regression testing since the bugs
          1511794: pic16: regression test bug-895992.c fails
          1444425: onebyte.c regression tes fails on pic16
-         are fiexed, probably by fixing
+         are fixed, probably by fixing
          2048464: PIC16: fix genUminus - addresses not.c regression test
        * src/SDCCsymt.c, src/SDCCglue.c,
          support/regression/tests/bug-1981238.c:
index c298845c2a788c79ed0184921efccba7c7689d3f..1786aa495de35540cce57e35b2ec3d1b6c83dbc7 100644 (file)
@@ -8412,19 +8412,9 @@ static void genPointerGet (iCode *ic)
       case POINTER:
       case FPOINTER:
       case IPOINTER:
-        genNearPointerGet (left,result,ic);
-        break;
-
-#if 0
-      /* MUST move them somewhere; handle [PF]POINTERs like POINTERS or like GPOINTERs?!? */
       case PPOINTER:
-        genPagedPointerGet(left,result,ic);
-        break;
-
-      case FPOINTER:
-        genFarPointerGet (left,result,ic);
+        genNearPointerGet (left,result,ic);
         break;
-#endif
 
       case CPOINTER:
         genConstPointerGet (left,result,ic);
@@ -8954,19 +8944,9 @@ static void genPointerSet (iCode *ic)
       case POINTER:
       case FPOINTER:
       case IPOINTER:
-        genNearPointerSet (right,result,ic);
-        break;
-
-#if 0
-      /* MUST move them somewhere; handle [PF]POINTERs like POINTERS or like GPOINTERs?!? */
       case PPOINTER:
-        genPagedPointerSet (right,result,ic);
-        break;
-
-      case FPOINTER:
-        genFarPointerSet (right,result,ic);
+        genNearPointerSet (right,result,ic);
         break;
-#endif
 
       case GPOINTER:
         genGenPointerSet (right,result,ic);
@@ -9247,7 +9227,7 @@ static void genAssign (iCode *ic)
       && !IS_ITEMP(right)) {
 
       DEBUGpic16_emitcode(";   ", "%s:%d symbol in code space, take special care\n", __FUNCTION__, __LINE__);
-      fprintf(stderr, "%s:%d symbol %s = [ %s ] is in code space\n", __FILE__, __LINE__, OP_SYMBOL(result)->name, OP_SYMBOL(right)->name);
+      //fprintf(stderr, "%s:%d symbol %s = [ %s ] is in code space\n", __FILE__, __LINE__, OP_SYMBOL(result)->name, OP_SYMBOL(right)->name);
 
       // set up table pointer
       if(pic16_isLitOp(right)) {
@@ -9795,7 +9775,6 @@ static void genCast (iCode *ic)
 
                 /* pointer to generic pointer */
                 if (IS_GENPTR(ctype)) {
-                  char *l = zero;
 
                         if (IS_PTR(type))
                                 p_type = DCL_TYPE(type);
@@ -9844,9 +9823,10 @@ static void genCast (iCode *ic)
             }
             /* the last byte depending on type */
             switch (p_type) {
-            case IPOINTER:
             case POINTER:
             case FPOINTER:
+            case IPOINTER:
+            case PPOINTER:
                 pic16_movLit2f(pic16_popGet(AOP(result), GPTRSIZE-1), GPTR_TAG_DATA);
                 break;
 
@@ -9854,11 +9834,6 @@ static void genCast (iCode *ic)
                 pic16_emitpcode(POC_MOVFF, pic16_popGet2(AOP(right), AOP(result), GPTRSIZE-1));
                 break;
 
-            case PPOINTER:
-              pic16_emitcode(";BUG!? ","%d",__LINE__);
-                l = "#0x03";
-                break;
-
             case GPOINTER:
                 if (GPTRSIZE > AOP_SIZE(right)) {
                   // assume __data pointer... THIS MIGHT BE WRONG!
index da95d2e016d9a42478a9a0c6e0a85212202649be..1a7adf3b189ba2ddccd6151bb55955401f39aed9 100644 (file)
@@ -559,16 +559,14 @@ pic16_printGPointerType (const char *iname, const unsigned int itype,
       pic16_emitDS (buf, ptype, p);
       break;
 
-    case POINTER: /* __data space */
+    case POINTER:  /* fall through */
+    case FPOINTER: /* fall through */
+    case IPOINTER: /* fall through */
+    case PPOINTER: /* __data space */
       sprintf (buf, "0x%02x", GPTR_TAG_DATA);
       pic16_emitDS (buf, ptype, p);
       break;
 
-    /*
-     * FPOINTER and IPOINTER are not used in pic16 port
-      case FPOINTER:
-      case IPOINTER:
-     */
     default:
       debugf ("itype = %d\n", itype );
       assert (0);
@@ -592,6 +590,7 @@ static void
 pic16_printIvalType (symbol *sym, sym_link * type, initList * ilist, char ptype, void *p)
 {
   value *val;
+  int i;
 
 //  fprintf(stderr, "%s for symbol %s\n",__FUNCTION__, sym->rname);
 
@@ -617,26 +616,9 @@ pic16_printIvalType (symbol *sym, sym_link * type, initList * ilist, char ptype,
     val = valCastLiteral(type, floatFromVal(val));
   }
 
-  switch (getSize (type)) {
-  case 1:
-    pic16_emitDB(pic16aopLiteral(val, 0), ptype, p);
-    break;
-
-  case 2:
-    pic16_emitDB(pic16aopLiteral(val, 0), ptype, p);
-    pic16_emitDB(pic16aopLiteral(val, 1), ptype, p);
-    break;
-  case 3:
-    pic16_emitDB(pic16aopLiteral(val, 0), ptype, p);
-    pic16_emitDB(pic16aopLiteral(val, 1), ptype, p);
-    pic16_emitDB(pic16aopLiteral(val, 2), ptype, p);
-  case 4:
-    pic16_emitDB(pic16aopLiteral(val, 0), ptype, p);
-    pic16_emitDB(pic16aopLiteral(val, 1), ptype, p);
-    pic16_emitDB(pic16aopLiteral(val, 2), ptype, p);
-    pic16_emitDB(pic16aopLiteral(val, 3), ptype, p);
-    break;
-  }
+  for (i = 0; i < getSize (type); i++) {
+    pic16_emitDB(pic16aopLiteral(val, i), ptype, p);
+  } // for
 }
 
 /*--------------------------------------------------------------------*/
@@ -663,8 +645,11 @@ pic16_printIvalChar (symbol *sym, sym_link * type, initList * ilist, char *s, ch
       /* length of initializer string (might contain \0, so do not use strlen) */
       ilen = DCL_ELEM(val->type);
 
+#if 0
+      /* This causes structflexarray.c to fail. */
       if(!DCL_ELEM (type))
         DCL_ELEM (type) = ilen;
+#endif
 
       /* len is 0 if declartion equals initializer,
        * >0 if declaration greater than initializer
@@ -680,19 +665,25 @@ pic16_printIvalChar (symbol *sym, sym_link * type, initList * ilist, char *s, ch
 
       if(len >= 0) {
         /* emit initializer */
-        for(remain=0; remain<ilen; remain++)
+        for(remain=0; remain<ilen; remain++) {
           pic16_emitDB(SPEC_CVAL(val->etype).v_char[ remain ], ptype, p);
-
-          /* fill array with 0x00 */
-          while(len--) {
-            pic16_emitDB(0x00, ptype, p);
-          }
+        } // for
+
+        /* fill array with 0x00 */
+        while(len--) {
+          pic16_emitDB(0x00, ptype, p);
+        } // while
+      } else if (!DCL_ELEM (type)) {
+        // flexible arrays: char str[] = "something"; */
+        for(remain=0; remain<ilen; remain++) {
+          pic16_emitDB(SPEC_CVAL(val->etype).v_char[ remain ], ptype, p);
+        } // for
       } else {
         werror (W_EXCESS_INITIALIZERS, "array of chars", sym->name, sym->lineDef);
-
-        for(remain=0; remain<DCL_ELEM (type); remain++)
+        for(remain=0; remain<DCL_ELEM (type); remain++) {
           pic16_emitDB(SPEC_CVAL(val->etype).v_char[ remain ], ptype, p);
-      }
+        } // for
+      } // if
 
 
 //      if((remain = (DCL_ELEM (type) - strlen (SPEC_CVAL (val->etype).v_char) - 1)) > 0) {
@@ -727,7 +718,7 @@ pic16_printIvalArray (symbol * sym, sym_link * type, initList * ilist,
   /* take care of the special   case  */
   /* array of characters can be init  */
   /* by a string                      */
-  if (IS_CHAR (type->next)) {
+  if (IS_CHAR (type->next) && ilist) {
     if (!IS_LITERAL(list2val(ilist)->etype)) {
       werror (W_INIT_WRONG);
       return;
@@ -745,7 +736,7 @@ pic16_printIvalArray (symbol * sym, sym_link * type, initList * ilist,
       return;
     }
 
-  iloop = ilist->init.deep;
+  iloop = (ilist ? ilist->init.deep : NULL);
   lcnt = DCL_ELEM (type);
 
   for (;;)
@@ -771,9 +762,12 @@ pic16_printIvalArray (symbol * sym, sym_link * type, initList * ilist,
       }
     }
 
+#if 0
+  /* This causes bug #1843745. */
   /* if we have not been given a size  */
   if (!DCL_ELEM (type))
     DCL_ELEM (type) = size;
+#endif
 
   return;
 }
@@ -788,6 +782,7 @@ pic16_printIvalBitFields(symbol **sym, initList **ilist, char ptype, void *p)
   symbol *lsym = *sym;
   initList *lilist = *ilist ;
   unsigned long ival = 0;
+  unsigned long i;
   int size =0;
 
 
@@ -797,7 +792,6 @@ pic16_printIvalBitFields(symbol **sym, initList **ilist, char ptype, void *p)
 
 
   do {
-    unsigned long i;
     val = list2val(lilist);
     if (size) {
       if (SPEC_BLEN(lsym->etype) > 8) {
@@ -818,27 +812,11 @@ pic16_printIvalBitFields(symbol **sym, initList **ilist, char ptype, void *p)
     lsym = lsym->next;
     lilist = lilist->next;
   } while (1);
-  switch (size) {
-  case 1:
-        pic16_emitDB(BYTE_IN_LONG(ival, 0), ptype, p);
-        break;
 
-  case 2:
-        pic16_emitDB(BYTE_IN_LONG(ival, 0), ptype, p);
-        pic16_emitDB(BYTE_IN_LONG(ival, 1), ptype, p);
-    break;
-
-  case 4: /* EEP: why is this db and not dw? */
-        pic16_emitDB(BYTE_IN_LONG(ival, 0), ptype, p);
-        pic16_emitDB(BYTE_IN_LONG(ival, 1), ptype, p);
-        pic16_emitDB(BYTE_IN_LONG(ival, 2), ptype, p);
-        pic16_emitDB(BYTE_IN_LONG(ival, 3), ptype, p);
-    break;
-  default:
-        /* VR - only 1,2,4 size long can be handled???? Why? */
-        fprintf(stderr, "%s:%d: unhandled case. Contact author.\n", __FILE__, __LINE__);
-        assert(0);
-  }
+  for (i = 0; i < size; i++) {
+    pic16_emitDB(BYTE_IN_LONG(ival, i), ptype, p);
+  } // for
+
   *sym = lsym;
   *ilist = lilist;
 }
@@ -870,7 +848,7 @@ pic16_printIvalStruct (symbol * sym, sym_link * type,
     iloop = ilist->init.deep;
   }
 
-  for (; (sflds && iloop); sflds = sflds->next, iloop = (iloop ? iloop->next : NULL)) {
+  for (; sflds; sflds = sflds->next, iloop = (iloop ? iloop->next : NULL)) {
 //    fprintf(stderr, "%s:%d sflds: %p\tiloop = %p\n", __FILE__, __LINE__, sflds, iloop);
     if (IS_BITFIELD(sflds->type)) {
       pic16_printIvalBitFields(&sflds, &iloop, ptype, p);
@@ -893,38 +871,35 @@ pic16_printIvalUnion (symbol * sym, sym_link * type,
 {
   //symbol *sflds;
   initList *iloop = NULL;
-  int i, size;
-
+  int size;
+  symbol *sflds = NULL;
 
 #if DEBUG_PRINTIVAL
   fprintf(stderr, "%s\n",__FUNCTION__);
 #endif
 
-  iloop = ilist;
-  i = 0;
-  while (iloop)
-  {
-    i++;
-    iloop = iloop->next;
-  } // while
+  assert (type);
 
-  size = -1;
-  if (type) size = SPEC_STRUCT(type)->size;
+  sflds = SPEC_STRUCT (type)->fields;
 
-  if (i == 1 && size >= 0 && size <= sizeof(long))
-  {
-    unsigned long val = ulFromVal (list2val(ilist));
-    while (size--)
-    {
-      pic16_emitDB(val, ptype, p);
-      val >>= 8;
-    } // while
-    return;
-  } // if
+  if (ilist) {
+    if (ilist->type != INIT_DEEP) {
+      werrorfl (sym->fileDef, sym->lineDef, E_INIT_STRUCT, sym->name);
+      return;
+    }
+
+    iloop = ilist->init.deep;
+  }
 
-  fprintf( stderr, "INCOMPLETE SUPPORT FOR INITIALIZED union---FALLING BACK TO struct\n" );
-  fprintf( stderr, "This is a bug. Please file a bug-report with your source attached.\n" );
-  pic16_printIvalStruct( sym, type, ilist, ptype, p );
+  size = SPEC_STRUCT(type)->size;
+  sflds = SPEC_STRUCT(type)->fields;
+  pic16_printIval (sym, sflds->type, iloop, ptype, p);
+
+  /* if the first field is not the longest, fill with 0s */
+  while (size > getSize (sflds->type)) {
+      pic16_emitDB(0, ptype, p);
+      size--;
+  } // while
 }
 
 static int
index f396f9a2383059779557c86b3e87721f49e52149..bd4a7e49ae01a0b2f70899f1ad418929d2ace75a 100644 (file)
@@ -51,7 +51,7 @@ static char *_pic16_keywords[] =
   "far",
   "interrupt",
   "near",
-  "pdata",
+  //"pdata",
   "reentrant",
   "sfr",
   "sfr16",
@@ -60,7 +60,7 @@ static char *_pic16_keywords[] =
   "_code",
   "_generic",
   "_near",
-  "_pdata",
+  //"_pdata",
   "_naked",
   "shadowregs",
   "wparam",