* src/pic16/gen.c (genPcall,pic16_derefPtr,genGenPointerGet,
authortecodev <tecodev@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Thu, 2 Mar 2006 16:30:48 +0000 (16:30 +0000)
committertecodev <tecodev@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Thu, 2 Mar 2006 16:30:48 +0000 (16:30 +0000)
  genConstPointerGet): use safe way of generating MOVFF to cover
    literals as well as registers, fixes bug #1440527
* src/pic16/glue.c (pic16_printIvalBitFields): prevent NULL pointer
    dereference
  (pic16_printIvalUnion,pic16_isUnion): NEW, handle initialized unions
    more correctly, fixes bug #1232186
  (pic16_printIval): use pic16_printIvalUnion() for initialized unions
* src/pic16/main.c (_pic16_linkEdit): reorder linker arguments to make
    gplink guess the correct processor in more cases, applied patch
    from Till Riedel attached to and fixing bug #1436552

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

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

index 162fff2272e35045964b40ab21a24aa182f1a41b..65c7c3ea7be5dfccec00d74903b72d7727ad18bc 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2006-03-01 Raphael Neider <rneider AT web.de>
+
+       * src/pic16/gen.c (genPcall,pic16_derefPtr,genGenPointerGet,
+         genConstPointerGet): use safe way of generating MOVFF to cover
+           literals as well as registers, fixes bug #1440527
+       * src/pic16/glue.c (pic16_printIvalBitFields): prevent NULL pointer
+           dereference
+         (pic16_printIvalUnion,pic16_isUnion): NEW, handle initialized unions
+           more correctly, fixes bug #1232186
+         (pic16_printIval): use pic16_printIvalUnion() for initialized unions
+       * src/pic16/main.c (_pic16_linkEdit): reorder linker arguments to make
+           gplink guess the correct processor in more cases, applied patch
+           from Till Riedel attached to and fixing bug #1436552
+
 2006-02-20 Frieder Ferlemann <Frieder.Ferlemann AT web.de>
 
        * support/regression/tests/array.c: added, contains check for #1434401
index 8e9cd666337f2417accd4efa5dab6598464024ea..d184da35e12ef4ac0265d3bc1445c41cf61561fe 100644 (file)
@@ -3473,11 +3473,11 @@ static void genPcall (iCode *ic)
     pic16_emitpcode(POC_MOVWF, pic16_popCopyReg(&pic16_pc_intcon));
 
     /* make the call by writing the pointer into pc */
-    pic16_emitpcode(POC_MOVFF, pic16_popGet2p(pic16_popGet(AOP(IC_LEFT(ic)),2), pic16_popCopyReg(&pic16_pc_pclatu)));
-    pic16_emitpcode(POC_MOVFF, pic16_popGet2p(pic16_popGet(AOP(IC_LEFT(ic)),1), pic16_popCopyReg(&pic16_pc_pclath)));
+    mov2fp(pic16_popCopyReg(&pic16_pc_pclatu), AOP(IC_LEFT(ic)), 2);
+    mov2fp(pic16_popCopyReg(&pic16_pc_pclath), AOP(IC_LEFT(ic)), 1);
 
     // note: MOVFF to PCL not allowed
-    pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(IC_LEFT(ic)),0));
+    pic16_mov2w(AOP(IC_LEFT(ic)), 0);
     pic16_emitpcode(POC_MOVWF, pic16_popCopyReg(&pic16_pc_pcl));
 
 
@@ -10504,9 +10504,9 @@ static void pic16_derefPtr (operand *ptr, int p_type, int doWrite, int *fsr0_set
       if (AOP(ptr)->aopu.aop_reg[2]) {
         if (doWrite) pic16_emitpcode (POC_MOVWF, pic16_popCopyReg(pic16_stack_postdec));
        // prepare call to __gptrget1, this is actually genGenPointerGet(result, WREG, ?ic?)
-       pic16_emitpcode (POC_MOVFF, pic16_popGet2p(pic16_popGet(AOP(ptr),0), pic16_popCopyReg(&pic16_pc_fsr0l)));
-       pic16_emitpcode (POC_MOVFF, pic16_popGet2p(pic16_popGet(AOP(ptr),1), pic16_popCopyReg(&pic16_pc_prodl)));
-       pic16_emitpcode (POC_MOVFW, pic16_popGet(AOP(ptr),2));
+       mov2fp(pic16_popCopyReg(&pic16_pc_fsr0l), AOP(ptr), 0);
+       mov2fp(pic16_popCopyReg(&pic16_pc_prodl), AOP(ptr), 1);
+       pic16_mov2w(AOP(ptr), 2);
        pic16_callGenericPointerRW(doWrite, 1);
       } else {
        // data pointer (just 2 byte given)
@@ -11157,10 +11157,9 @@ static void genGenPointerGet (operand *left,
     } else { /* we need to get it byte by byte */
 
       /* set up WREG:PRODL:FSR0L with address from left */
-      pic16_emitpcode(POC_MOVFF, pic16_popGet2p(pic16_popGet(AOP(left),0), pic16_popCopyReg(&pic16_pc_fsr0l)));
-      pic16_emitpcode(POC_MOVFF, pic16_popGet2p(pic16_popGet(AOP(left),1), pic16_popCopyReg(&pic16_pc_prodl)));
-      pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(left), 2));
-      
+      mov2fp(pic16_popCopyReg(&pic16_pc_fsr0l), AOP(left), 0);
+      mov2fp(pic16_popCopyReg(&pic16_pc_prodl), AOP(left), 1);
+      pic16_mov2w(AOP(left), 2);
       pic16_callGenericPointerRW(0, size);
       
       assignResultValue(result, 1);
@@ -11207,9 +11206,9 @@ static void genConstPointerGet (operand *left,
       pic16_emitpcode(POC_MOVLW,pic16_popGet(AOP(left),2));
       pic16_emitpcode(POC_MOVWF,pic16_popCopyReg(&pic16_pc_tblptru));
   } else {
-    pic16_emitpcode(POC_MOVFF, pic16_popGet2p(pic16_popGet(AOP(left),0), pic16_popCopyReg(&pic16_pc_tblptrl)));
-    pic16_emitpcode(POC_MOVFF, pic16_popGet2p(pic16_popGet(AOP(left),1), pic16_popCopyReg(&pic16_pc_tblptrh)));
-    pic16_emitpcode(POC_MOVFF, pic16_popGet2p(pic16_popGet(AOP(left),2), pic16_popCopyReg(&pic16_pc_tblptru)));
+    mov2fp(pic16_popCopyReg(&pic16_pc_tblptrl), AOP(left), 0);
+    mov2fp(pic16_popCopyReg(&pic16_pc_tblptrh), AOP(left), 1);
+    mov2fp(pic16_popCopyReg(&pic16_pc_tblptru), AOP(left), 2);
   }
 
   while(size--) {
index dcb109afcce5809790a44cb651ccc44219b80caa..d148eb3ed0d84ff31748d9651bc3678880bde731 100644 (file)
@@ -809,6 +809,7 @@ void pic16_printIvalBitFields(symbol **sym, initList **ilist, char ptype, void *
     i <<= SPEC_BSTR (lsym->etype);
     ival |= i;
     if (! ( lsym->next &&
+          (lilist && lilist->next) &&
           (IS_BITFIELD(lsym->next->type)) &&
           (SPEC_BSTR(lsym->next->etype)))) break;
     lsym = lsym->next;
@@ -879,6 +880,55 @@ void pic16_printIvalStruct (symbol * sym, sym_link * type,
   return;
 }
 
+/*-----------------------------------------------------------------*/
+/* printIvalUnion - generates initial value for unions             */
+/*-----------------------------------------------------------------*/
+void pic16_printIvalUnion (symbol * sym, sym_link * type,
+                 initList * ilist, char ptype, void *p)
+{
+  //symbol *sflds;
+  initList *iloop = NULL;
+  int i, size;
+
+
+#if DEBUG_PRINTIVAL
+  fprintf(stderr, "%s\n",__FUNCTION__);
+#endif
+
+  iloop = ilist;
+  i = 0;
+  while (iloop)
+  {
+    i++;
+    iloop = iloop->next;
+  } // while
+
+  size = -1;
+  if (type) size = SPEC_STRUCT(type)->size;
+
+  if (i == 1 && size >= 0 && size <= sizeof(long))
+  {
+    unsigned long val = (unsigned long)floatFromVal(list2val(ilist));
+    while (size--)
+    {
+      pic16_emitDB(val, ptype, p);
+      val >>= 8;
+    } // while
+    return;
+  } // if
+
+  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 );
+}
+
+static int
+pic16_isUnion( symbol *sym, sym_link *type )
+{
+  if (type && SPEC_STRUCT(type)->type == UNION) return 1;
+  return 0;
+}
+
 /*--------------------------------------------------------------------------*/
 /* pic16_printIvalCharPtr - generates initial values for character pointers */
 /*--------------------------------------------------------------------------*/
@@ -1127,8 +1177,14 @@ void pic16_printIval (symbol * sym, sym_link * type, initList * ilist, char ptyp
   /* if structure then */
   if (IS_STRUCT (type))
     {
-//      fprintf(stderr,"%s struct\n",__FUNCTION__);
-      pic16_printIvalStruct (sym, type, ilist, ptype, p);
+      if (pic16_isUnion(sym, type))
+        {
+          //fprintf(stderr,"%s union\n",__FUNCTION__);
+          pic16_printIvalUnion (sym, type, ilist, ptype, p);
+       } else {
+          //fprintf(stderr,"%s struct\n",__FUNCTION__);
+          pic16_printIvalStruct (sym, type, ilist, ptype, p);
+        }
       return;
     }
 
index 67c857909c90ce5e0edd3c37870873b4ea04332d..e630439c3bf6e4dd35f5bfda2b052ed6fbf4864e 100644 (file)
@@ -639,6 +639,11 @@ extern set *linkOptionsSet;
 char *msprintf(hTab *pvals, const char *pformat, ...);
 int my_system(const char *cmd);
 
+/* forward declarations */   
+extern const char *pic16_linkCmd[];
+extern const char *pic16_asmCmd[];
+extern set *asmOptionsSet;
+  
 /* custom function to link objects */
 static void _pic16_linkEdit(void)
 {
@@ -655,9 +660,9 @@ static void _pic16_linkEdit(void)
         *
         */
         
-       sprintf(lfrm, "{linker} {incdirs} {lflags} -o {outfile} {user_ofile} {spec_ofiles} {ofiles} {libs}");
-                
-       shash_add(&linkValues, "linker", "gplink");
+       sprintf(lfrm, "{linker} {incdirs} {lflags} -o {outfile} {user_ofile} {ofiles} {spec_ofiles} {libs}");
+
+       shash_add(&linkValues, "linker", pic16_linkCmd[0]);
 
        mergeSets(&tSet, libDirsSet);
        mergeSets(&tSet, libPathsSet);
@@ -707,11 +712,6 @@ static void _pic16_linkEdit(void)
 }
 
 
-/* forward declarations */
-extern const char *pic16_linkCmd[];
-extern const char *pic16_asmCmd[];
-extern set *asmOptionsSet;
-
 static void
 _pic16_finaliseOptions (void)
 {