From: tecodev Date: Fri, 22 Jul 2005 16:04:56 +0000 (+0000) Subject: * src/pic/device.c (dump_sfr): replaced register declaration with X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=a10f1efe331d9feef47f4ce7a33234b86919d8e1;p=fw%2Fsdcc * src/pic/device.c (dump_sfr): replaced register declaration with call to emitSymbolToFile() to avoid duplicate symbols * (assignRelocatableRegisters): do not declare external symbols * src/pic/ralloc.c (allocNewDirReg): fixed to get size of arrays right (take size of type, not etype) * (allocDirReg): fixed call to allocNewDirReg() to pass OP_SYM_TYPE * (writeUsedRegs): also dump dynDirectRegs (e.g. local variables) * (packRegsForAccUse): disabled assignment of WREG as the result reg to prevent occurence of just fixed #1235003, fixes #1242954 * src/pic/glue.c (emitSymbolToFile): NEW, central place to declare symbols (avoids duplicate symbols in .asm file) * (pic14emitRegularMap): use emitSymbolToFile() * src/pic/gen.c (aopOp): fixed spillLocation handling * (gen{Unp,P}ackBits): fixed acquiring bit-operands * (genDataPointerSet): removed unneccessary variables/output git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@3807 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/ChangeLog b/ChangeLog index ea66ad0c..6b5ac978 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +2005-07-22 Raphael Neider + + * src/pic/device.c (dump_sfr): replaced register declaration with + call to emitSymbolToFile() to avoid duplicate symbols + * (assignRelocatableRegisters): do not declare external symbols + * src/pic/ralloc.c (allocNewDirReg): fixed to get size of arrays + right (take size of type, not etype) + * (allocDirReg): fixed call to allocNewDirReg() to pass OP_SYM_TYPE + * (writeUsedRegs): also dump dynDirectRegs (e.g. local variables) + * (packRegsForAccUse): disabled assignment of WREG as + the result reg to prevent occurence of just fixed #1235003, + fixes #1242954 + * src/pic/glue.c (emitSymbolToFile): NEW, central place to declare + symbols (avoids duplicate symbols in .asm file) + * (pic14emitRegularMap): use emitSymbolToFile() + * src/pic/gen.c (aopOp): fixed spillLocation handling + * (gen{Unp,P}ackBits): fixed acquiring bit-operands + * (genDataPointerSet): removed unneccessary variables/output + 2005-07-22 Maarten Brock * as/mcs51/lkarea.c: enlarged codemap for banked memory * device/lib/mcs51/crtbank.asm: added # to 0x0F diff --git a/src/pic/device.c b/src/pic/device.c index 495eee7d..1b9fd8e9 100644 --- a/src/pic/device.c +++ b/src/pic/device.c @@ -102,6 +102,8 @@ AssignedMemory *finalMapping=NULL; static unsigned int config_word = DEFAULT_CONFIG_WORD; +extern void emitSymbolToFile (FILE *of, const char *name, int size); + void addMemRange(memRange *r, int type) { int i; @@ -270,9 +272,12 @@ void dump_sfr(FILE *of) finalMapping[start].reg->address+i); } } else { + emitSymbolToFile (of, finalMapping[start].reg->name, finalMapping[start].reg->size); +#if 0 fprintf(of,"%s\tres\t%i\n", finalMapping[start].reg->name, finalMapping[start].reg->size); +#endif } finalMapping[start].reg->isEmitted = 1; } @@ -564,9 +569,9 @@ void assignRelocatableRegisters(set *regset, int used) for (reg = setFirstItem(regset) ; reg ; reg = setNextItem(regset)) { - //fprintf(stdout,"assigning %s isFixed=%d, wasUsed=%d\n",reg->name,reg->isFixed,reg->wasUsed); + //fprintf(stdout,"assigning %s (%d) isFixed=%d, wasUsed=%d\n",reg->name,reg->size,reg->isFixed,reg->wasUsed); - if((!reg->isFixed) && ( used || reg->wasUsed)) { + if((!reg->isExtern) && (!reg->isFixed) && ( used || reg->wasUsed)) { /* If register have been reused then shall not print it a second time. */ set *s; int done = 0; diff --git a/src/pic/gen.c b/src/pic/gen.c index d37b6e59..09487208 100644 --- a/src/pic/gen.c +++ b/src/pic/gen.c @@ -900,23 +900,27 @@ void aopOp (operand *op, iCode *ic, bool result) } /* else spill location */ - if (sym->usl.spillLoc && getSize(sym->type) != getSize(sym->usl.spillLoc->type)) { - /* force a new aop if sizes differ */ - sym->usl.spillLoc->aop = NULL; - } - DEBUGpic14_emitcode(";","%s %d %s sym->rname = %s, offset %d", - __FUNCTION__,__LINE__, - sym->usl.spillLoc->rname, - sym->rname, sym->usl.spillLoc->offset); - - sym->aop = op->aop = aop = newAsmop(AOP_PCODE); - //aop->aopu.pcop = popGetImmd(sym->usl.spillLoc->rname,0,sym->usl.spillLoc->offset); - aop->aopu.pcop = popRegFromString(sym->usl.spillLoc->rname, - getSize(sym->type), - sym->usl.spillLoc->offset); - aop->size = getSize(sym->type); + if (sym->usl.spillLoc) + { + if (getSize(sym->type) != getSize(sym->usl.spillLoc->type)) + { + /* force a new aop if sizes differ */ + sym->usl.spillLoc->aop = NULL; + } + DEBUGpic14_emitcode(";","%s %d %s sym->rname = %s, offset %d", + __FUNCTION__,__LINE__, + sym->usl.spillLoc->rname, + sym->rname, sym->usl.spillLoc->offset); + + sym->aop = op->aop = aop = newAsmop(AOP_PCODE); + //aop->aopu.pcop = popGetImmd(sym->usl.spillLoc->rname,0,sym->usl.spillLoc->offset); + aop->aopu.pcop = popRegFromString(sym->usl.spillLoc->rname, + getSize(sym->type), + sym->usl.spillLoc->offset); + aop->size = getSize(sym->type); - return; + return; + } } { @@ -8164,7 +8168,7 @@ static void genUnpackBits (operand *result, operand *left, char *rname, int ptyp resolvedIfx rIfx; resolveIfx(&rIfx,ifx); if (ptype == -1) /* direct */ - pcop = newpCodeOpBit(AOP(left)->aopu.pcop->name,bstr,0); + pcop = newpCodeOpBit(aopGet (AOP(left),0,FALSE,FALSE),bstr,0); else pcop = newpCodeOpBit(pc_indf.pcop.name,bstr,0); emitpcode((rIfx.condition) ? POC_BTFSC : POC_BTFSS,pcop); @@ -8172,23 +8176,32 @@ static void genUnpackBits (operand *result, operand *left, char *rname, int ptyp ifx->generated=1; } else { pCodeOp *pcop; + if (ptype == -1) /* direct */ - pcop = newpCodeOpBit(AOP(left)->aopu.pcop->name,bstr,0); + pcop = newpCodeOpBit(aopGet (AOP(left),0,FALSE,FALSE),bstr,0); else pcop = newpCodeOpBit(pc_indf.pcop.name,bstr,0); emitpcode(POC_BTFSC,pcop); - emitpcode(POC_BSF,newpCodeOpBit(AOP(result)->aopu.pcop->name,bstr,0)); - + emitpcode(POC_BSF,newpCodeOpBit(aopGet(AOP(result), 0,FALSE,FALSE),bstr,0)); if (ptype == -1) /* direct */ - pcop = newpCodeOpBit(AOP(left)->aopu.pcop->name,bstr,0); + pcop = newpCodeOpBit(aopGet(AOP(left),0,FALSE,FALSE),bstr,0); else pcop = newpCodeOpBit(pc_indf.pcop.name,bstr,0); emitpcode(POC_BTFSS,pcop); - emitpcode(POC_BCF,newpCodeOpBit(AOP(result)->aopu.pcop->name,bstr,0)); + emitpcode(POC_BCF,newpCodeOpBit(aopGet(AOP(result),0,FALSE,FALSE),bstr,0)); } return; } + { + static int has_warned=0; + if (!has_warned) + { + fprintf (stderr, "%s: bitfields with more than 1 bit are probably broken...", __FUNCTION__); + has_warned=1; + } + } + /* read the first byte */ switch (ptype) { @@ -8968,7 +8981,7 @@ static void genPackBits(sym_link *etype,operand *result,operand *right,char *rna if (p_type == -1) { pCodeOp *pcop; if (AOP(result)->type == AOP_PCODE) - pcop = newpCodeOpBit(AOP(result)->aopu.pcop->name,bstr,0); + pcop = newpCodeOpBit(aopGet(AOP(result),0,FALSE,FALSE),bstr,0); else pcop = popGet(AOP(result),0); emitpcode(lit?POC_BSF:POC_BCF,pcop); @@ -9130,13 +9143,12 @@ static void genDataPointerSet(operand *right, iCode *ic) { int size, offset = 0 ; - char *l, buffer[256]; FENTRY; DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__); aopOp(right,ic,FALSE); + aopOp(result,ic,FALSE); - l = aopGet(AOP(result),0,FALSE,TRUE); size = AOP_SIZE(right); /* if ( AOP_TYPE(result) == AOP_PCODE) { @@ -9149,11 +9161,6 @@ static void genDataPointerSet(operand *right, // tsd, was l+1 - the underline `_' prefix was being stripped while (size--) { emitpComment ("%s:%u: size=%i, offset=%i", __FILE__,__LINE__, size, offset); - if (offset) { - sprintf(buffer,"(%s + %d)",l,offset); - fprintf(stderr,"%s:%i: oops %s (%i, AOP_LIT=%i)\n",__FILE__,__LINE__,buffer, AOP_TYPE(right), AOP_LIT); - } else - sprintf(buffer,"%s",l); if (AOP_TYPE(right) == AOP_LIT) { unsigned int lit = (unsigned int) floatFromVal (AOP(IC_RIGHT(ic))->aopu.aop_lit); diff --git a/src/pic/glue.c b/src/pic/glue.c index 79184f0d..98811a19 100644 --- a/src/pic/glue.c +++ b/src/pic/glue.c @@ -100,6 +100,36 @@ int pic14aopLiteral (value *val, int offset) } +/* set of already emitted symbols; we store only pointers to the emitted + * symbol names so these MUST NO BE CHANGED afterwards... */ +static set *symbolsEmitted = NULL; + +/*-------------------------------------------------------------------*/ +/* emitSymbolToFile - write a symbol definition only if it is not */ +/* already present */ +/*-------------------------------------------------------------------*/ +void +emitSymbolToFile (FILE *of, const char *name, int size) +{ + const char *sym; + + /* check whether the symbol is already defined */ + for (sym = (const char *) setFirstItem (symbolsEmitted); + sym; + sym = (const char *) setNextItem (symbolsEmitted)) + { + if (!strcmp (sym, name)) + { + //fprintf (stderr, "%s: already emitted: %s\n", __FUNCTION__, name); + return; + } + } // for + + /* new symbol -- define it */ + //fprintf (stderr, "%s: emitting %s (%d)\n", __FUNCTION__, name, size); + fprintf (of, "%s\tres\t%d\n", name, size); + addSet (&symbolsEmitted, (void *) name); +} /*-----------------------------------------------------------------*/ /* emitRegularMap - emit code for maps with no special cases */ @@ -188,7 +218,7 @@ pic14emitRegularMap (memmap * map, bool addPublics, bool arFlag) } else { - fprintf (map->oFile, "%s\tres\t%d\n", sym->rname,getSize (sym->type) & 0xffff); + emitSymbolToFile (map->oFile, sym->rname, getSize (sym->type) & 0xffff); /* { int i, size; diff --git a/src/pic/ralloc.c b/src/pic/ralloc.c index 4d4bd48f..50e22e1a 100644 --- a/src/pic/ralloc.c +++ b/src/pic/ralloc.c @@ -371,7 +371,7 @@ static regs* newReg(short type, short pc_type, int rIdx, char *name, int size, i dReg->reglives.assignedpFlows = newSet(); hTabAddItem(&dynDirectRegNames, regname2key(name), dReg); - + return dReg; } @@ -586,10 +586,11 @@ allocNewDirReg (sym_link *symlnk,const char *name) { regs *reg; int address = 0; + sym_link *spec = getSpec (symlnk); /* if this is at an absolute address, then get the address. */ - if (SPEC_ABSA (symlnk) ) { - address = SPEC_ADDR (symlnk); + if (SPEC_ABSA (spec) ) { + address = SPEC_ADDR (spec); //fprintf(stderr,"reg %s is at an absolute address: 0x%03x\n",name,address); } @@ -602,7 +603,7 @@ allocNewDirReg (sym_link *symlnk,const char *name) } else { int idx; if (address) { - if (IS_BITVAR (symlnk)) + if (IS_BITVAR (spec)) idx = address >> 3; else idx = address; @@ -612,20 +613,20 @@ allocNewDirReg (sym_link *symlnk,const char *name) reg = newReg(REG_GPR, PO_DIR, idx, (char*)name,getSize (symlnk),0 ); debugLog (" -- added %s to hash, size = %d\n", (char*)name,reg->size); - if (SPEC_ABSA (symlnk) ) { + if (SPEC_ABSA (spec) ) { reg->type = REG_SFR; } - if (IS_BITVAR (symlnk)) { + if (IS_BITVAR (spec)) { addSet(&dynDirectBitRegs, reg); reg->isBitField = 1; } else addSet(&dynDirectRegs, reg); - if (!IS_STATIC (symlnk)) { + if (!IS_STATIC (spec)) { reg->isPublic = 1; } - if (IS_EXTERN (symlnk)) { + if (IS_EXTERN (spec)) { reg->isExtern = 1; } @@ -765,7 +766,7 @@ allocDirReg (operand *op ) debugLog (" -- and it is at a fixed address 0x%02x\n",reg->address); } } else { - allocNewDirReg (OP_SYM_ETYPE(op),name); + allocNewDirReg (OP_SYM_TYPE(op),name); } return reg; @@ -796,7 +797,7 @@ allocRegByName (char *name, int size) /* Register wasn't found in hash, so let's create * a new one and put it in the hash table AND in the * dynDirectRegNames set */ - //fprintf (stderr,"%s symbol name %s\n", __FUNCTION__,name); + //fprintf (stderr,"%s symbol name %s, size:%d\n", __FUNCTION__,name,size); reg = newReg(REG_GPR, PO_DIR, rDirectIdx++, name,size,0 ); for (sym = setFirstItem(sfr->syms); sym; sym = setNextItem(sfr->syms)) { if (strcmp(reg->name+1,sym->name)==0) { @@ -1184,6 +1185,7 @@ void writeUsedRegs(FILE *of) assignRelocatableRegisters(dynAllocRegs,0); assignRelocatableRegisters(dynStackRegs,0); + assignRelocatableRegisters(dynDirectRegs,0); /* assignRelocatableRegisters(dynDirectRegs,0); printf("assignRelocatableRegisters(dynDirectRegs,0);\n"); @@ -3407,10 +3409,22 @@ isBitwiseOptimizable (iCode * ic) static void packRegsForAccUse (iCode * ic) { - iCode *uic; + //iCode *uic; debugLog ("%s\n", __FUNCTION__); + + /* result too large for WREG? */ + if (getSize (operandType (IC_RESULT (ic))) > 1) + return; + /* We have to make sure that OP_SYMBOL(IC_RESULT(ic)) + * is never used as an operand to an instruction that + * cannot have WREG as an operand (e.g. BTFSx cannot + * operate on WREG... + * For now, store all results into proper registers. */ + return; + +#if 0 /* if this is an aggregate, e.g. a one byte char array */ if (IS_AGGREGATE(operandType(IC_RESULT(ic)))) { return; @@ -3547,8 +3561,7 @@ packRegsForAccUse (iCode * ic) accuse: debugLog ("%s - Yes we are using the accumulator\n", __FUNCTION__); OP_SYMBOL (IC_RESULT (ic))->accuse = 1; - - +#endif } /*-----------------------------------------------------------------*/