* sim/ucsim/cmd.src/cmdutil.cc: NUL device is detected as CG_FILE type
[fw/sdcc] / src / pic / ralloc.c
index cf27a62342619527c7843747f11c6240d1c43fc6..d51dca63908cc3bbd70662d61bd533b44c9ae55c 100644 (file)
 
 #include "common.h"
 #include "ralloc.h"
+#include "device.h"
 #include "pcode.h"
 #include "gen.h"
 
 
-#if defined(__BORLANDC__) || defined(_MSC_VER)
-#define STRCASECMP stricmp
 #define FENTRY2                        1 ? (void)0 : printf 
-#else
-#define STRCASECMP strcasecmp
-//#define FENTRY2(fmt,...)     do { fprintf (stderr, "%s:%d: called.\n", __FUNCTION__, __LINE__); fprintf (stderr, fmt, ## __VA_ARGS__); } while (0)
-#define FENTRY2                        1 ? (void)0 : printf 
-#endif
 
 /* this should go in SDCCicode.h, but it doesn't. */
 #define IS_REF(op)       (IS_SYMOP(op) && op->operand.symOperand->isref == 1)
@@ -171,7 +165,7 @@ static void
 static char *
        debugAopGet (char *str, operand * op)
 {
-       if (str)
+        if (str)
                debugLog (str);
 
        printOperand (op, debugF);
@@ -256,7 +250,6 @@ static char *
        case STRUCT:                    return "STRUCT";
        case UNION:                     return "UNION";
        case ENUM:                      return "ENUM";
-       case ELIPSIS:                   return "ELIPSIS";
        case RANGE:                     return "RANGE";
        case FAR:                       return "FAR";
        case CASE:                      return "CASE";
@@ -487,11 +480,13 @@ regFindFree (set *dRegs)
 /*-----------------------------------------------------------------*/
 /* initStack - allocate registers for a pseudo stack               */
 /*-----------------------------------------------------------------*/
-void initStack(int base_address, int size)
+void initStack(int base_address, int size, int shared)
 {
        
        int i;
-       
+       PIC_device *pic;
+
+       pic = pic14_getPIC();
        Gstack_base_addr = base_address;
        Gstack_size = size;
        //fprintf(stderr,"initStack [base:0x%02x, size:%d]\n", base_address, size);
@@ -500,9 +495,9 @@ void initStack(int base_address, int size)
                char buffer[16];
                regs *r;
                SNPRINTF(&buffer[0], 16, "STK%02d", i);
-               // Trying to use shared memory for pseudo stack
-               r = newReg(REG_STK, PO_GPR_TEMP, base_address--, buffer, 1, 0x180);
-               r->isFixed = 0; // fixed location no longer required
+               // multi-bank device, sharebank prohibited by user
+               r = newReg(REG_STK, PO_GPR_TEMP, base_address--, buffer, 1, shared ? (pic ? pic->bankMask : 0x180) : 0x0);
+               r->isFixed = 1;
                r->isPublic = 1;
                r->isEmitted = 1;
                //r->name[0] = 's';
@@ -898,6 +893,10 @@ typeRegWithIdx (int idx, int type, int fixed)
                if( (dReg = regWithIdx ( dynStackRegs, idx, 0)) != NULL ) {
                        debugLog ("Found a Stack Register!\n");
                        return dReg;
+               } else
+               if( (dReg = regWithIdx ( dynStackRegs, idx, 1)) != NULL ) {
+                       debugLog ("Found a Stack Register!\n");
+                       return dReg;
                }
                else {
                  werror (E_STACK_OUT, "Register");
@@ -1068,10 +1067,7 @@ void writeSetUsedRegs(FILE *of, set *dRegs)
        }
        
 }
-extern void assignFixedRegisters(set *regset);
-extern void assignRelocatableRegisters(set *regset,int used);
 extern void dump_map(void);
-extern void dump_sfr(FILE *of);
 
 void packBits(set *bregs)
 {
@@ -1170,6 +1166,7 @@ void bitEQUs(FILE *of, set *bregs)
        }
        
 }
+
 void aliasEQUs(FILE *of, set *fregs, int use_rIdx)
 {
        regs *reg;
@@ -1195,62 +1192,13 @@ void aliasEQUs(FILE *of, set *fregs, int use_rIdx)
 
 void writeUsedRegs(FILE *of) 
 {
-       packBits(dynDirectBitRegs);
        
-       assignFixedRegisters(dynInternalRegs);
-       assignFixedRegisters(dynAllocRegs);
-       assignFixedRegisters(dynStackRegs);
-       assignFixedRegisters(dynDirectRegs);
-       
-       assignRelocatableRegisters(dynInternalRegs,0);
-       assignRelocatableRegisters(dynAllocRegs,0);
-       assignRelocatableRegisters(dynStackRegs,0);
+       packBits(dynDirectBitRegs);
        
-       assignRelocatableRegisters(dynDirectRegs,0);
-       /*
-       assignRelocatableRegisters(dynDirectRegs,0);
-       printf("assignRelocatableRegisters(dynDirectRegs,0);\n");
-       */
        //dump_map();
        
-       dump_sfr(of);
        bitEQUs(of,dynDirectBitRegs);
-       /*
-       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          */
-/*-----------------------------------------------------------------*/
-static bool
-allDefsOutOfRange (bitVect * defs, int fseq, int toseq)
-{
-       int i;
-       
-       debugLog ("%s\n", __FUNCTION__);
-       if (!defs)
-               return TRUE;
-       
-       for (i = 0; i < defs->size; i++)
-       {
-               iCode *ic;
-               
-               if (bitVectBitValue (defs, i) &&
-                       (ic = hTabItemWithKey (iCodehTab, i)) &&
-                       (ic->seq >= fseq && ic->seq <= toseq))
-                       
-                       return FALSE;
-               
-       }
-       
-       return TRUE;
 }
-#endif
 
 /*-----------------------------------------------------------------*/
 /* computeSpillable - given a point find the spillable live ranges */