+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
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));
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)
} 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);
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--) {
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;
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 */
/*--------------------------------------------------------------------------*/
/* 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;
}
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)
{
*
*/
- 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);
}
-/* forward declarations */
-extern const char *pic16_linkCmd[];
-extern const char *pic16_asmCmd[];
-extern set *asmOptionsSet;
-
static void
_pic16_finaliseOptions (void)
{