From: tecodev Date: Thu, 2 Mar 2006 16:30:48 +0000 (+0000) Subject: * src/pic16/gen.c (genPcall,pic16_derefPtr,genGenPointerGet, X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=4f6c68996624658afc5330d91bdd9688092ccfa7;p=fw%2Fsdcc * 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 git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@4048 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/ChangeLog b/ChangeLog index 162fff22..65c7c3ea 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2006-03-01 Raphael Neider + + * 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 * support/regression/tests/array.c: added, contains check for #1434401 diff --git a/src/pic16/gen.c b/src/pic16/gen.c index 8e9cd666..d184da35 100644 --- a/src/pic16/gen.c +++ b/src/pic16/gen.c @@ -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--) { diff --git a/src/pic16/glue.c b/src/pic16/glue.c index dcb109af..d148eb3e 100644 --- a/src/pic16/glue.c +++ b/src/pic16/glue.c @@ -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; } diff --git a/src/pic16/main.c b/src/pic16/main.c index 67c85790..e630439c 100644 --- a/src/pic16/main.c +++ b/src/pic16/main.c @@ -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) {