/*-----------------------------------------------------------------*/
extern void genpic14Code (iCode *);
+extern void assignConfigWordValue(int address, int value);
/* Global data */
static struct
int pic14_ptrRegReq; /* one byte pointer register required */
-static set *dynAllocRegs=NULL;
-static set *dynStackRegs=NULL;
-static set *dynProcessorRegs=NULL;
-static set *dynDirectRegs=NULL;
-static set *dynDirectBitRegs=NULL;
-static set *dynInternalRegs=NULL;
+set *dynAllocRegs=NULL;
+set *dynStackRegs=NULL;
+set *dynProcessorRegs=NULL;
+set *dynDirectRegs=NULL;
+set *dynDirectBitRegs=NULL;
+set *dynInternalRegs=NULL;
static hTab *dynDirectRegNames= NULL;
+// static hTab *regHash = NULL; /* a hash table containing ALL registers */
static int dynrIdx=0x20;
static int rDirectIdx=0;
//char *bufferP=buffer;
va_list ap;
- if (!debug || !srcFileName)
+ if (!debug || !dstFileName)
return;
if (!debugF)
{
/* create the file name */
- strcpy (buffer, srcFileName);
+ strcpy (buffer, dstFileName);
strcat (buffer, ".d");
if (!(debugF = fopen (buffer, (append ? "a+" : "w"))))
return "REG_CND";
}
- sprintf (buffer, "unkown reg type %d", type);
+ sprintf (buffer, "unknown reg type %d", type);
return buffer;
}
+/*-----------------------------------------------------------------*/
+/*-----------------------------------------------------------------*/
+static int regname2key(char const *name)
+{
+ int key = 0;
+
+ if(!name)
+ return 0;
+
+ while(*name) {
+
+ key += (*name++) + 1;
+
+ }
+
+ return ( (key + (key >> 4) + (key>>8)) & 0x3f);
+
+}
+
/*-----------------------------------------------------------------*/
/* newReg - allocate and init memory for a new register */
/*-----------------------------------------------------------------*/
//fprintf(stderr,"newReg: %s, rIdx = 0x%02x\n",dReg->name,rIdx);
dReg->isFree = 0;
dReg->wasUsed = 1;
- dReg->isFixed = 0;
+ if(type == REG_SFR)
+ dReg->isFixed = 1;
+ else
+ dReg->isFixed = 0;
+
dReg->isMapped = 0;
dReg->isEmitted = 0;
dReg->address = 0;
dReg->size = size;
dReg->alias = alias;
dReg->reg_alias = NULL;
+ dReg->reglives.usedpFlows = newSet();
+ dReg->reglives.assignedpFlows = newSet();
+
+ hTabAddItem(&dynDirectRegNames, regname2key(name), dReg);
return dReg;
}
int i;
Gstack_base_addr = base_address;
+ //fprintf(stderr,"initStack");
+
for(i = 0; i<size; i++)
addSet(&dynStackRegs,newReg(REG_STK, PO_GPR_TEMP,base_address++,NULL,1,0));
}
+/*-----------------------------------------------------------------*
+ *-----------------------------------------------------------------*/
regs *
allocProcessorRegister(int rIdx, char * name, short po_type, int alias)
{
+
+ //fprintf(stderr,"allocProcessorRegister %s addr =0x%x\n",name,rIdx);
return addSet(&dynProcessorRegs,newReg(REG_SFR, po_type, rIdx, name,1,alias));
}
+/*-----------------------------------------------------------------*
+ *-----------------------------------------------------------------*/
+
regs *
allocInternalRegister(int rIdx, char * name, short po_type, int alias)
{
- regs * reg = newReg(REG_SFR, po_type, rIdx, name,1,alias);
+ regs * reg = newReg(REG_GPR, po_type, rIdx, name,1,alias);
+ //fprintf(stderr,"allocInternalRegister %s addr =0x%x\n",name,rIdx);
if(reg) {
reg->wasUsed = 0;
return addSet(&dynInternalRegs,reg);
{
debugLog ("%s of type %s\n", __FUNCTION__, debugLogRegType (type));
+ //fprintf(stderr,"allocReg\n");
return addSet(&dynAllocRegs,newReg(REG_GPR, PO_GPR_TEMP,dynrIdx++,NULL,1,0));
}
-/*-----------------------------------------------------------------*/
-/*-----------------------------------------------------------------*/
-static int regname2key(char const *name)
-{
- int key = 0;
-
- if(!name)
- return 0;
-
- while(*name) {
-
- key += (*name++) + 1;
-
- }
-
- return ( (key + (key >> 4) + (key>>8)) & 0x3f);
-
-}
/*-----------------------------------------------------------------*/
/* dirregWithName - search for register by name */
return NULL; // name wasn't found in the hash table
}
+int IS_CONFIG_ADDRESS(int address)
+{
+
+ return address == 0x2007;
+}
+
/*-----------------------------------------------------------------*/
/* allocDirReg - allocates register of given type */
/*-----------------------------------------------------------------*/
return NULL;
/* First, search the hash table to see if there is a register with this name */
- reg = dirregWithName(name);
+ if (SPEC_ABSA ( OP_SYM_ETYPE(op)) && !(IS_BITVAR (OP_SYM_ETYPE(op))) ) {
+ reg = regWithIdx (dynProcessorRegs, SPEC_ADDR ( OP_SYM_ETYPE(op)), 1);
+/*
+ if(!reg)
+ fprintf(stderr,"ralloc %s is at fixed address but not a processor reg, addr=0x%x\n",
+ name, SPEC_ADDR ( OP_SYM_ETYPE(op)));
+ else
+ fprintf(stderr,"ralloc %s at fixed address has already been declared, addr=0x%x\n",
+ name, SPEC_ADDR ( OP_SYM_ETYPE(op)));
+*/
+ } else {
+ //fprintf(stderr,"ralloc:%d %s \n", __LINE__,name);
+
+ reg = dirregWithName(name);
+ }
if(!reg) {
+ int address = 0;
+
+ /* if this is at an absolute address, then get the address. */
+ if (SPEC_ABSA ( OP_SYM_ETYPE(op)) ) {
+ address = SPEC_ADDR ( OP_SYM_ETYPE(op));
+ //fprintf(stderr,"reg %s is at an absolute address: 0x%03x\n",name,address);
+ }
/* 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 */
+ if(!IS_CONFIG_ADDRESS(address)) {
+ //fprintf(stderr,"allocating new reg %s\n",name);
- reg = newReg(REG_GPR, PO_DIR, rDirectIdx++, name,getSize (OP_SYMBOL (op)->type),0 );
- debugLog (" -- added %s to hash, size = %d\n", name,reg->size);
+ reg = newReg(REG_GPR, PO_DIR, rDirectIdx++, name,getSize (OP_SYMBOL (op)->type),0 );
+ debugLog (" -- added %s to hash, size = %d\n", name,reg->size);
+
+ //hTabAddItem(&dynDirectRegNames, regname2key(name), reg);
+
+ if (SPEC_ABSA ( OP_SYM_ETYPE(op)) ) {
+
+ //fprintf(stderr, " ralloc.c at fixed address: %s - changing to REG_SFR\n",name);
+ reg->type = REG_SFR;
+ }
+
+ if (IS_BITVAR (OP_SYM_ETYPE(op))) {
+ addSet(&dynDirectBitRegs, reg);
+ reg->isBitField = 1;
+ } else
+ addSet(&dynDirectRegs, reg);
+
+ } else {
+ debugLog (" -- %s is declared at address 0x2007\n",name);
- if (SPEC_ABSA ( OP_SYM_ETYPE(op)) ) {
- reg->isFixed = 1;
- reg->address = SPEC_ADDR ( OP_SYM_ETYPE(op));
- debugLog (" -- and it is at a fixed address 0x%02x\n",reg->address);
}
+ }
- hTabAddItem(&dynDirectRegNames, regname2key(name), reg);
- if (IS_BITVAR (OP_SYM_ETYPE(op)))
- addSet(&dynDirectBitRegs, reg);
- else
- addSet(&dynDirectRegs, reg);
+ if (SPEC_ABSA ( OP_SYM_ETYPE(op)) ) {
+ reg->isFixed = 1;
+ reg->address = SPEC_ADDR ( OP_SYM_ETYPE(op));
+ debugLog (" -- and it is at a fixed address 0x%02x\n",reg->address);
}
return reg;
exit(1);
}
- debugLog ("%s symbol name %s\n", __FUNCTION__,name);
-
/* First, search the hash table to see if there is a register with this name */
reg = dirregWithName(name);
/* 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);
reg = newReg(REG_GPR, PO_DIR, rDirectIdx++, name,size,0 );
debugLog (" -- added %s to hash, size = %d\n", name,reg->size);
- hTabAddItem(&dynDirectRegNames, regname2key(name), reg);
+ //hTabAddItem(&dynDirectRegNames, regname2key(name), reg);
addSet(&dynDirectRegs, reg);
}
/*-----------------------------------------------------------------*/
/* RegWithIdx - returns pointer to register with index number */
/*-----------------------------------------------------------------*/
-static regs *
+regs *
typeRegWithIdx (int idx, int type, int fixed)
{
debugLog ("%s - requesting index = 0x%x\n", __FUNCTION__,idx);
- if( (dReg = regWithIdx ( dynAllocRegs, idx, fixed)) != NULL) {
+ switch (type) {
+
+ case REG_GPR:
+ if( (dReg = regWithIdx ( dynAllocRegs, idx, fixed)) != NULL) {
- debugLog ("Found a Dynamic Register!\n");
- return dReg;
- }
+ debugLog ("Found a Dynamic Register!\n");
+ return dReg;
+ }
+ if( (dReg = regWithIdx ( dynDirectRegs, idx, fixed)) != NULL ) {
+ debugLog ("Found a Direct Register!\n");
+ return dReg;
+ }
- if( (dReg = regWithIdx ( dynStackRegs, idx, fixed)) != NULL ) {
- debugLog ("Found a Stack Register!\n");
- return dReg;
- }
+ break;
+ case REG_STK:
+ if( (dReg = regWithIdx ( dynStackRegs, idx, fixed)) != NULL ) {
+ debugLog ("Found a Stack Register!\n");
+ return dReg;
+ }
+ break;
+ case REG_SFR:
+ if( (dReg = regWithIdx ( dynProcessorRegs, idx, fixed)) != NULL ) {
+ debugLog ("Found a Processor Register!\n");
+ return dReg;
+ }
- if( (dReg = regWithIdx ( dynDirectRegs, idx, fixed)) != NULL ) {
- debugLog ("Found a Direct Register!\n");
- return dReg;
+ case REG_CND:
+ case REG_PTR:
+ default:
+ break;
}
- if( (dReg = regWithIdx ( dynProcessorRegs, idx, fixed)) != NULL ) {
- debugLog ("Found a Processor Register!\n");
- return dReg;
- }
-/*
- if( (dReg = regWithIdx ( dynDirectBitRegs, idx, fixed)) != NULL ) {
- debugLog ("Found a bit Register!\n");
- return dReg;
- }
-*/
-/*
- fprintf(stderr,"%s %d - requested register: 0x%x\n",__FUNCTION__,__LINE__,idx);
- werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
- "regWithIdx not found");
- exit (1);
-*/
+
return NULL;
}
regs *
pic14_regWithIdx (int idx)
{
+ regs *dReg;
+
+ if( (dReg = typeRegWithIdx(idx,REG_GPR,0)) != NULL)
+ return dReg;
+
+ if( (dReg = typeRegWithIdx(idx,REG_SFR,0)) != NULL)
+ return dReg;
- return typeRegWithIdx(idx,-1,0);
+ if( (dReg = typeRegWithIdx(idx,REG_STK,0)) != NULL)
+ return dReg;
+
+ return NULL;
}
/*-----------------------------------------------------------------*/
debugLog ("Dynamic Register not found\n");
- fprintf(stderr,"%s %d - requested register: 0x%x\n",__FUNCTION__,__LINE__,idx);
+ //fprintf(stderr,"%s %d - requested register: 0x%x\n",__FUNCTION__,__LINE__,idx);
werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
"regWithIdx not found");
exit (1);
case REG_GPR:
if((dReg = regFindFree(dynAllocRegs)) != NULL)
return dReg;
-
return addSet(&dynAllocRegs,newReg(REG_GPR, PO_GPR_TEMP,dynrIdx++,NULL,1,0));
case REG_STK:
return nFreeRegs (type);
}
-//<<<<<<< ralloc.c
void writeSetUsedRegs(FILE *of, set *dRegs)
{
int byte_no=-1;
char buffer[20];
+
for (regset = bregs ; regset ;
regset = regset->next) {
if(!bitfield) {
sprintf (buffer, "fbitfield%02x", breg->address);
//fprintf(stderr,"new bit field\n");
- bitfield = newReg(REG_GPR, PO_GPR_BIT,breg->address,buffer,1,0);
+ bitfield = newReg(REG_SFR, PO_GPR_BIT,breg->address,buffer,1,0);
bitfield->isBitField = 1;
bitfield->isFixed = 1;
bitfield->address = breg->address;
addSet(&dynDirectRegs,bitfield);
- hTabAddItem(&dynDirectRegNames, regname2key(buffer), bitfield);
+ //hTabAddItem(&dynDirectRegNames, regname2key(buffer), bitfield);
} else {
//fprintf(stderr," which is occupied by %s (addr = %d)\n",bitfield->name,bitfield->address);
;
relocbitfield = newReg(REG_GPR, PO_GPR_BIT,rDirectIdx++,buffer,1,0);
relocbitfield->isBitField = 1;
addSet(&dynDirectRegs,relocbitfield);
- hTabAddItem(&dynDirectRegNames, regname2key(buffer), relocbitfield);
+ //hTabAddItem(&dynDirectRegNames, regname2key(buffer), relocbitfield);
}
}
}
-void aliasEQUs(FILE *of, set *fregs)
+void aliasEQUs(FILE *of, set *fregs, int use_rIdx)
{
regs *reg;
for (reg = setFirstItem(fregs) ; reg ;
reg = setNextItem(fregs)) {
- if(!reg->isEmitted)
- fprintf (of, "%s\tEQU\t0x%03x\n",
- reg->name,
- reg->address);
+ if(!reg->isEmitted && reg->wasUsed) {
+ if(use_rIdx)
+ fprintf (of, "%s\tEQU\t0x%03x\n",
+ reg->name,
+ reg->rIdx);
+ else
+ fprintf (of, "%s\tEQU\t0x%03x\n",
+ reg->name,
+ reg->address);
+ }
}
}
{
packBits(dynDirectBitRegs);
+
assignFixedRegisters(dynAllocRegs);
assignFixedRegisters(dynStackRegs);
assignFixedRegisters(dynDirectRegs);
- assignRelocatableRegisters(dynInternalRegs,1);
+ assignRelocatableRegisters(dynInternalRegs,0);
assignRelocatableRegisters(dynAllocRegs,0);
assignRelocatableRegisters(dynStackRegs,0);
assignRelocatableRegisters(dynDirectRegs,0);
dump_cblock(of);
bitEQUs(of,dynDirectBitRegs);
- aliasEQUs(of,dynAllocRegs);
- aliasEQUs(of,dynDirectRegs);
- aliasEQUs(of,dynStackRegs);
+ aliasEQUs(of,dynAllocRegs,0);
+ aliasEQUs(of,dynDirectRegs,0);
+ aliasEQUs(of,dynStackRegs,0);
+ aliasEQUs(of,dynProcessorRegs,1);
}
+
#if 0
/*-----------------------------------------------------------------*/
/* allDefsOutOfRange - all definitions are out of a range */
return TRUE;
}
#endif
-//=======
-//>>>>>>> 1.28
+
/*-----------------------------------------------------------------*/
/* computeSpillable - given a point find the spillable live ranges */
/*-----------------------------------------------------------------*/
debugLog ("%s\n", __FUNCTION__);
- printf ("%s\n", s);
+ //printf ("%s\n", s);
/* if plus or minus print the right hand side */
(int) operandLitValue (IC_RIGHT (ic)));
- fprintf(stderr, "ralloc.c:%d OOPS %s\n",__LINE__,s);
+ //fprintf(stderr, "ralloc.c:%d OOPS %s\n",__LINE__,s);
psym = newSymbol (OP_SYMBOL (IC_LEFT (ric))->rname, 1);
psym->offset = (int) operandLitValue (IC_RIGHT (ic));
sprintf (s, "%s", OP_SYMBOL (IC_LEFT (ic))->rname);
psym = newSymbol (OP_SYMBOL (IC_LEFT (ic))->rname, 1);
- printf ("%s\n", buffer);
+ //printf ("ralloc.c:%d %s\n", __LINE__,buffer);
return psym;
}
//s += strlen(s);
//ic = OP_SYMBOL(IC_LEFT(ic))->rematiCode;
//continue ;
- fprintf(stderr, "ralloc.c:%d OOPS %s\n",__LINE__,s);
+ //fprintf(stderr, "ralloc.c:%d OOPS %s\n",__LINE__,s);
return buffer;
}
DEFSETFUNC (deallocReg)
{
+ fprintf(stderr,"deallocting register %s\n",((regs *)item)->name);
((regs *)item)->isFree = 1;
((regs *)item)->wasUsed = 0;
debugAopGet (" left:", IC_LEFT (ic));
debugAopGet (" right:", IC_RIGHT (ic));
+ /* if this is at an absolute address, then get the address. */
+ if (SPEC_ABSA ( OP_SYM_ETYPE(IC_RESULT(ic))) ) {
+ if(IS_CONFIG_ADDRESS( SPEC_ADDR ( OP_SYM_ETYPE(IC_RESULT(ic))))) {
+ debugLog (" %d - found config word declaration\n", __LINE__);
+ if(IS_VALOP(IC_RIGHT(ic))) {
+ debugLog (" setting config word to %x\n",
+ (int) floatFromVal (IC_RIGHT(ic)->operand.valOperand));
+ assignConfigWordValue( SPEC_ADDR ( OP_SYM_ETYPE(IC_RESULT(ic))),
+ (int) floatFromVal (IC_RIGHT(ic)->operand.valOperand));
+ }
+
+ /* remove the assignment from the iCode chain. */
+
+ remiCodeFromeBBlock (ebp, ic);
+ bitVectUnSetBit(OP_SYMBOL(IC_RESULT(ic))->defs,ic->key);
+ hTabDeleteItem (&iCodehTab, ic->key, ic, DELETE_ITEM, NULL);
+
+ return 1;
+
+ }
+ }
+
if (!IS_ITEMP (IC_RESULT (ic))) {
allocDirReg(IC_RESULT (ic));
debugLog (" %d - result is not temp\n", __LINE__);
if (IS_AGGREGATE(operandType(IC_RESULT(ic)))) {
return;
}
+ debugLog (" %s:%d\n", __FUNCTION__,__LINE__);
/* if + or - then it has to be one byte result */
if ((ic->op == '+' || ic->op == '-')
&& getSize (operandType (IC_RESULT (ic))) > 1)
return;
+ debugLog (" %s:%d\n", __FUNCTION__,__LINE__);
/* if shift operation make sure right side is not a literal */
if (ic->op == RIGHT_OP &&
(isOperandLiteral (IC_RIGHT (ic)) ||
bitVectFirstBit (OP_USES (IC_RESULT (ic))))))
return;
+ debugLog (" %s:%d\n", __FUNCTION__,__LINE__);
if (ic->next != uic)
return;
getSize (aggrToPtr (operandType (IC_RESULT (uic)), FALSE)) > 1)
return;
+ debugLog (" %s:%d\n", __FUNCTION__,__LINE__);
if (uic->op != '=' &&
!IS_ARITHMETIC_OP (uic) &&
!IS_BITWISE_OP (uic) &&
uic->op != RIGHT_OP)
return;
+ debugLog (" %s:%d\n", __FUNCTION__,__LINE__);
/* if used in ^ operation then make sure right is not a
literl */
if (uic->op == '^' && isOperandLiteral (IC_RIGHT (uic)))
IC_LEFT (uic)->key != IC_RESULT (ic)->key)
return;
+ debugLog (" %s:%d\n", __FUNCTION__,__LINE__);
/* if one of them is a literal then we can */
- if ((IC_LEFT (uic) && IS_OP_LITERAL (IC_LEFT (uic))) ||
- (IC_RIGHT (uic) && IS_OP_LITERAL (IC_RIGHT (uic))))
+ if ( ((IC_LEFT (uic) && IS_OP_LITERAL (IC_LEFT (uic))) ||
+ (IC_RIGHT (uic) && IS_OP_LITERAL (IC_RIGHT (uic)))) &&
+ (getSize (operandType (IC_RESULT (uic))) <= 1))
{
OP_SYMBOL (IC_RESULT (ic))->accuse = 1;
return;
}
+ debugLog (" %s:%d\n", __FUNCTION__,__LINE__);
/* if the other one is not on stack then we can */
if (IC_LEFT (uic)->key == IC_RESULT (ic)->key &&
(IS_ITEMP (IC_RIGHT (uic)) ||
}
+/*-----------------------------------------------------------------*/
+/* some debug code to print the symbol S_TYPE. Note that
+ * the function checkSClass in src/SDCCsymt.c dinks with
+ * the S_TYPE in ways the PIC port doesn't fully like...*/
+/*-----------------------------------------------------------------*/
+void isData(sym_link *sl)
+{
+ FILE *of = stderr;
+
+ if(!sl)
+ return;
+
+ if(debugF)
+ of = debugF;
+
+ for ( ; sl; sl=sl->next) {
+ if(!IS_DECL(sl) ) {
+ switch (SPEC_SCLS(sl)) {
+
+ case S_DATA: fprintf (of, "data "); break;
+ case S_XDATA: fprintf (of, "xdata "); break;
+ case S_SFR: fprintf (of, "sfr "); break;
+ case S_SBIT: fprintf (of, "sbit "); break;
+ case S_CODE: fprintf (of, "code "); break;
+ case S_IDATA: fprintf (of, "idata "); break;
+ case S_PDATA: fprintf (of, "pdata "); break;
+ case S_LITERAL: fprintf (of, "literal "); break;
+ case S_STACK: fprintf (of, "stack "); break;
+ case S_XSTACK: fprintf (of, "xstack "); break;
+ case S_BIT: fprintf (of, "bit "); break;
+ case S_EEPROM: fprintf (of, "eeprom "); break;
+ default: break;
+ }
+
+ }
+
+ }
+
+}
/*-----------------------------------------------------------------*/
/* packRegisters - does some transformations to reduce register */
/* pressure */
for (ic = ebp->sch; ic; ic = ic->next) {
if(IS_SYMOP ( IC_LEFT(ic))) {
- //sym_link *etype = getSpec (operandType (IC_LEFT (ic)));
+ sym_link *etype = getSpec (operandType (IC_LEFT (ic)));
debugAopGet (" left:", IC_LEFT (ic));
if(IS_PTR_CONST(OP_SYMBOL(IC_LEFT(ic))->type))
- debugLog (" is a pointer");
+ debugLog (" is a pointer\n");
+
+ if(IS_OP_VOLATILE(IC_LEFT(ic)))
+ debugLog (" is volatile\n");
+
+ isData(etype);
printSymType(" ", OP_SYMBOL(IC_LEFT(ic))->type);
}
setToNull ((void **) &_G.stackSpil);
setToNull ((void **) &_G.spiltSet);
/* mark all registers as free */
- pic14_freeAllRegs ();
+ //pic14_freeAllRegs ();
debugLog ("leaving\n<><><><><><><><><><><><><><><><><>\n");
debugLogClose ();