#define STRCASECMP strcasecmp
#endif
+#ifndef debugf
+#define debugf(frm, rest) _debugf(__FILE__, __LINE__, frm, rest)
+#endif
+void _debugf(char *f, int l, char *frm, ...);
+
+
//#define USE_ONSTACK
* are used to pass and return parameters */
-
+int _inRegAllocator=0; /* flag that marks whther allocReg happens while
+ * inside the register allocator function */
+
static void spillThis (symbol *);
int pic16_ralloc_debug = 0;
return NULL;
}
+
+
/*-----------------------------------------------------------------*/
/* allocReg - allocates register of given type */
/*-----------------------------------------------------------------*/
{
regs * reg=NULL;
+#define MAX_P16_NREGS 6
+
+
#if 0
if(dynrIdx > pic16_nRegs)
return NULL;
reg = regFindFree( pic16_dynAllocRegs );
if(reg) {
-// fprintf(stderr, "%s: found FREE register %s\n", __FILE__, reg->name);
+// fprintf(stderr, "%s: [%s] found FREE register %s, rIdx: %d\n", __FILE__, (_inRegAllocator)?"ralloc":"", reg->name, reg->rIdx);
}
if(!reg) {
reg = newReg(REG_GPR, PO_GPR_TEMP, dynrIdx++, NULL, 1, 0, NULL);
+// fprintf(stderr, "%s: [%s] allocating NEW register %s, rIdx: %d\n", __FILE__, (_inRegAllocator)?"ralloc":"", reg->name, reg->rIdx);
+
+#if 1
+ if(_inRegAllocator && (dynrIdx > MAX_P16_NREGS)) {
+// debugf("allocating more registers than available\n", 0);
+// return (NULL);
+ }
+#endif
+
// addSet(&pic16_dynAllocRegs, reg);
}
/* else we assign registers to it */
_G.regAssigned = bitVectSetBit (_G.regAssigned, sym->key);
- debugLog (" %d - nRegs: %d\n", __LINE__, sym->nRegs);
if(debugF)
bitVectDebugOn(_G.regAssigned, debugF);
if (IS_AGGREGATE (sym->type) || sym->isptr)
sym->type = aggrToPtr (sym->type, FALSE);
debugLog (" %d - no reg needed - used as a return\n", __LINE__);
-
continue;
}
/* registers for true symbols we will */
/* see how things go */
sym->nRegs = 0;
+
}
}
debugLog ("\nebbs before optimizing:\n");
dumpEbbsToDebug (ebbs, count);
+ _inRegAllocator = 1;
+
setToNull ((void *) &_G.funcrUsed);
pic16_ptrRegReq = _G.stackExtend = _G.dataExtend = 0;
debugLog ("ebbs after optimizing:\n");
dumpEbbsToDebug (ebbs, count);
+ _inRegAllocator = 0;
genpic16Code (ic);
/* mark all registers as free */
pic16_freeAllRegs ();
+
debugLog ("leaving\n<><><><><><><><><><><><><><><><><>\n");
debugLogClose ();
return;