/*-----------------------------------------------------------------*/
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;
*buffer = 's';
dReg->name = Safe_strdup(buffer);
}
- //fprintf(stderr,"newReg: %s\n",dReg->name);
+ //fprintf(stderr,"newReg: %s, rIdx = 0x%02x\n",dReg->name,rIdx);
dReg->isFree = 0;
dReg->wasUsed = 1;
dReg->isFixed = 0;
dReg->size = size;
dReg->alias = alias;
dReg->reg_alias = NULL;
+ dReg->reglives.usedpFlows = newSet();
+ dReg->reglives.assignedpFlows = newSet();
return dReg;
}
/* dirregWithName - search for register by name */
/*-----------------------------------------------------------------*/
regs *
-dirregWithName (char *name )
+dirregWithName (char *name)
{
int hkey;
regs *reg;
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 */
/*-----------------------------------------------------------------*/
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));
+ }
/* 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)) {
+ 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);
+/*
+ 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);
+ } else {
+ debugLog (" -- %s is declared at address 0x2007\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);
-
- 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;
/* allocDirReg - allocates register of given type */
/*-----------------------------------------------------------------*/
regs *
-allocRegByName (char *name )
+allocRegByName (char *name, int size)
{
regs *reg;
* a new one and put it in the hash table AND in the
* dynDirectRegNames set */
- reg = newReg(REG_GPR, PO_DIR, rDirectIdx++, name,1,0 );
+ reg = newReg(REG_GPR, PO_DIR, rDirectIdx++, name,size,0 );
debugLog (" -- added %s to hash, size = %d\n", name,reg->size);
/*-----------------------------------------------------------------*/
/* 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);
+ switch (type) {
+
+ case REG_GPR:
+ if( (dReg = regWithIdx ( dynAllocRegs, idx, fixed)) != NULL) {
+
+ debugLog ("Found a Dynamic Register!\n");
+ return dReg;
+ }
+ if( (dReg = regWithIdx ( dynDirectRegs, idx, fixed)) != NULL ) {
+ debugLog ("Found a Direct 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;
+ }
+
+ case REG_CND:
+ case REG_PTR:
+ default:
+ break;
+ }
+
+#if 0
+
if( (dReg = regWithIdx ( dynAllocRegs, idx, fixed)) != NULL) {
debugLog ("Found a Dynamic Register!\n");
debugLog ("Found a Processor Register!\n");
return dReg;
}
-/*
- if( (dReg = regWithIdx ( dynDirectBitRegs, idx, fixed)) != NULL ) {
+#endif
+
+ /*
+ 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 ("Found a Stack Register!\n");
} else if( (dReg = regWithIdx ( dynProcessorRegs, idx,0)) != NULL ) {
debugLog ("Found a Processor Register!\n");
+ } else if( (dReg = regWithIdx ( dynInternalRegs, idx,0)) != NULL ) {
+ debugLog ("Found an Internal Register!\n");
} else {
debugLog ("Dynamic Register not found\n");
if((dReg = regFindFree(dynAllocRegs)) != NULL)
return dReg;
- return addSet(&dynAllocRegs,newReg(REG_GPR, PO_GPR_TEMP,dynrIdx++,NULL,0,0));
+ return addSet(&dynAllocRegs,newReg(REG_GPR, PO_GPR_TEMP,dynrIdx++,NULL,1,0));
case REG_STK:
}
extern void assignFixedRegisters(set *regset);
-extern void assignRelocatableRegisters(set *regset);
+extern void assignRelocatableRegisters(set *regset,int used);
extern void dump_map(void);
extern void dump_cblock(FILE *of);
for (reg = setFirstItem(fregs) ; reg ;
reg = setNextItem(fregs)) {
- if(!reg->isEmitted)
+ if(!reg->isEmitted && reg->wasUsed)
fprintf (of, "%s\tEQU\t0x%03x\n",
reg->name,
reg->address);
assignFixedRegisters(dynStackRegs);
assignFixedRegisters(dynDirectRegs);
- assignRelocatableRegisters(dynAllocRegs);
- assignRelocatableRegisters(dynStackRegs);
- assignRelocatableRegisters(dynDirectRegs);
+ assignRelocatableRegisters(dynInternalRegs,0);
+ assignRelocatableRegisters(dynAllocRegs,0);
+ assignRelocatableRegisters(dynStackRegs,0);
+ assignRelocatableRegisters(dynDirectRegs,0);
//dump_map();
aliasEQUs(of,dynStackRegs);
}
+
#if 0
/*-----------------------------------------------------------------*/
/* allDefsOutOfRange - all definitions are out of a range */
}
}
+/*-----------------------------------------------------------------*/
+/* rematStr - returns the rematerialized string for a remat var */
+/*-----------------------------------------------------------------*/
+static symbol *
+rematStr (symbol * sym)
+{
+ char *s = buffer;
+ iCode *ic = sym->rematiCode;
+ symbol *psym = NULL;
+
+ debugLog ("%s\n", __FUNCTION__);
+
+ //printf ("%s\n", s);
+
+ /* if plus or minus print the right hand side */
+
+ if (ic->op == '+' || ic->op == '-') {
+
+ iCode *ric = OP_SYMBOL (IC_LEFT (ic))->rematiCode;
+
+ sprintf (s, "(%s %c 0x%04x)",
+ OP_SYMBOL (IC_LEFT (ric))->rname,
+ ic->op,
+ (int) operandLitValue (IC_RIGHT (ic)));
+
+
+ //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));
+
+ return psym;
+ }
+
+ sprintf (s, "%s", OP_SYMBOL (IC_LEFT (ic))->rname);
+ psym = newSymbol (OP_SYMBOL (IC_LEFT (ic))->rname, 1);
+
+ //printf ("ralloc.c:%d %s\n", __LINE__,buffer);
+ return psym;
+}
+
+#if 0
/*-----------------------------------------------------------------*/
/* rematStr - returns the rematerialized string for a remat var */
/*-----------------------------------------------------------------*/
//s += strlen(s);
//ic = OP_SYMBOL(IC_LEFT(ic))->rematiCode;
//continue ;
+ fprintf(stderr, "ralloc.c:%d OOPS %s\n",__LINE__,s);
return buffer;
}
printf ("%s\n", buffer);
return buffer;
}
+#endif
/*-----------------------------------------------------------------*/
/* regTypeNum - computes the type & number of registers required */
DCL_TYPE (aggrToPtr (sym->type, FALSE)) == POINTER) {
/* create a psuedo symbol & force a spil */
- symbol *psym = newSymbol (rematStr (OP_SYMBOL (IC_LEFT (ic))), 1);
+ //X symbol *psym = newSymbol (rematStr (OP_SYMBOL (IC_LEFT (ic))), 1);
+ symbol *psym = rematStr (OP_SYMBOL (IC_LEFT (ic)));
psym->type = sym->type;
psym->etype = sym->etype;
strcpy (psym->rname, psym->name);
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)) ||
setToNull ((void **) &_G.stackSpil);
setToNull ((void **) &_G.spiltSet);
/* mark all registers as free */
- pic14_freeAllRegs ();
+ //pic14_freeAllRegs ();
debugLog ("leaving\n<><><><><><><><><><><><><><><><><>\n");
debugLogClose ();