* src/pic/pcode.c (pciTRIS): fixed typo,
[fw/sdcc] / src / pic / ralloc.c
index 5e385a07b8c1ca0ddb909efe668a56a5c347079a..7d58ccbdf2300e38ddabe24fcdad0c53d71f03ad 100644 (file)
@@ -335,6 +335,7 @@ static int regname2key(char const *name)
        
 }
 
+static regs *regWithIdx (set *dRegs, int idx, int fixed);
 /*-----------------------------------------------------------------*/
 /* newReg - allocate and init memory for a new register            */
 /*-----------------------------------------------------------------*/
@@ -342,6 +343,20 @@ static regs* newReg(short type, short pc_type, int rIdx, char *name, int size, i
 {
        
        regs *dReg;
+
+       /* check whether a matching register already exists */
+       dReg = dirregWithName( name );
+       if (dReg) {
+         //printf( "%s: already present: %s\n", __FUNCTION__, name );
+         return (dReg);
+       }
+       dReg = regWithIdx( dynDirectRegs, rIdx, 0 );
+       if (!dReg) dReg = regWithIdx( dynDirectRegs, rIdx, 1 );
+       if (dReg)
+       {
+         //printf(  "%s: already present %s (idx:%d/%x)", __FUNCTION__, name, rIdx, rIdx );
+         return (dReg);
+       }
        
        dReg = Safe_calloc(1,sizeof(regs));
        dReg->type = type;
@@ -484,7 +499,7 @@ void initStack(int base_address, int size)
        
        for(i = 0; i<size; i++) {
                char buffer[16];
-        regs *r;
+               regs *r;
                SNPRINTF(&buffer[0], 16, "STK%02d", i);
                r = newReg(REG_STK, PO_GPR_TEMP,base_address,buffer,1,0);
                r->address = base_address; // Pseudo stack needs a fixed location that can be known by all modules