+2005-07-22 Raphael Neider <rneider AT web.de>
+
+ * 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 <sourceforge.brock AT dse.nl>
* as/mcs51/lkarea.c: enlarged codemap for banked memory
* device/lib/mcs51/crtbank.asm: added # to 0x0F
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;
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;
}
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;
}
/* 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;
+ }
}
{
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);
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) {
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);
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) {
// 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);
}
+/* 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 */
}
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;
dReg->reglives.assignedpFlows = newSet();
hTabAddItem(&dynDirectRegNames, regname2key(name), dReg);
-
+
return dReg;
}
{
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);
}
} else {
int idx;
if (address) {
- if (IS_BITVAR (symlnk))
+ if (IS_BITVAR (spec))
idx = address >> 3;
else
idx = address;
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;
}
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;
/* 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) {
assignRelocatableRegisters(dynAllocRegs,0);
assignRelocatableRegisters(dynStackRegs,0);
+ assignRelocatableRegisters(dynDirectRegs,0);
/*
assignRelocatableRegisters(dynDirectRegs,0);
printf("assignRelocatableRegisters(dynDirectRegs,0);\n");
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;
accuse:
debugLog ("%s - Yes we are using the accumulator\n", __FUNCTION__);
OP_SYMBOL (IC_RESULT (ic))->accuse = 1;
-
-
+#endif
}
/*-----------------------------------------------------------------*/