* device/lib/Makefile.in: fixed bug in target objects-pic16,
[fw/sdcc] / src / pic16 / ralloc.c
index 078774ace5e527d19697a9756e644d82101cdda4..5e94acc58c9ad723c06fda79ce162d62c116f11d 100644 (file)
@@ -48,7 +48,6 @@
 
 regs *pic16_typeRegWithIdx (int idx, int type, int fixed);
 extern void genpic16Code (iCode *);
-extern void pic16_assignConfigWordValue(int address, int value);
 
 /* Global data */
 static struct
@@ -78,6 +77,8 @@ set *pic16_dynInternalRegs=NULL;
 static hTab  *dynDirectRegNames= NULL;
 //static hTab  *regHash = NULL;    /* a hash table containing ALL registers */
 
+extern set *sectNames;
+
 set *pic16_rel_udata=NULL;     /* relocatable uninitialized registers */
 set *pic16_fix_udata=NULL;     /* absolute uninitialized registers */
 set *pic16_equ_data=NULL;      /* registers used by equates */
@@ -361,8 +362,6 @@ regs* newReg(short type, short pc_type, int rIdx, char *name, int size, int alia
 
        dReg->isFree = 0;
        dReg->wasUsed = 1;
-
-//     dReg->isMapped = 0;
        dReg->isEmitted = 0;
 
        if(type == REG_SFR) {
@@ -375,8 +374,8 @@ regs* newReg(short type, short pc_type, int rIdx, char *name, int size, int alia
                dReg->accessBank = 0;
        }
 
-//     fprintf(stderr,"newReg: %s, rIdx = 0x%02x\taccess= %d\n",dReg->name,rIdx, dReg->accessBank);
-       
+//     fprintf(stderr,"newReg: %s, rIdx = 0x%02x\taccess= %d\tregop= %p\n",dReg->name,rIdx, dReg->accessBank, refop);
+
        dReg->size = size;
        dReg->alias = alias;
        dReg->reg_alias = NULL;
@@ -384,7 +383,8 @@ regs* newReg(short type, short pc_type, int rIdx, char *name, int size, int alia
        dReg->reglives.assignedpFlows = newSet();
        dReg->regop = refop;
   
-       hTabAddItem(&dynDirectRegNames, regname2key(name), dReg);
+       if(!(type == REG_SFR && alias == 0x80))
+               hTabAddItem(&dynDirectRegNames, regname2key(name), dReg);
 
   return dReg;
 }
@@ -469,10 +469,10 @@ pic16_allocInternalRegister(int rIdx, char * name, short po_type, int alias)
 
 //  fprintf(stderr,"%s:%d: %s  %s addr =0x%x\n",__FILE__, __LINE__, __FUNCTION__, name, rIdx);
 
-  if(reg) {
-    reg->wasUsed = 0;
-    return addSet(&pic16_dynInternalRegs,reg);
-  }
+    if(reg) {
+      reg->wasUsed = 0;
+      return addSet(&pic16_dynInternalRegs,reg);
+    }
 
   return NULL;
 }
@@ -492,10 +492,17 @@ allocReg (short type)
        /* try to reuse some unused registers */
        reg = regFindFree( pic16_dynAllocRegs );
 
+       if(reg) {
+//             fprintf(stderr, "%s: found FREE register %s\n", __FILE__, reg->name);
+       }
+
        if(!reg) {
                reg = newReg(REG_GPR, PO_GPR_TEMP, dynrIdx++, NULL, 1, 0, NULL);
-               addSet(&pic16_dynAllocRegs, reg);
+//             addSet(&pic16_dynAllocRegs, reg);
        }
+
+       addSet(&pic16_dynAllocRegs, reg);
+
        reg->isFree=0;
 
 //     debugLog ("%s of type %s\n", __FUNCTION__, debugLogRegType (type));
@@ -508,8 +515,10 @@ allocReg (short type)
                reg->isLocal = 1;       /* this is a local frame register */
        }
        
-       if (currFunc)
+       if (currFunc) {
+//             fprintf(stderr, "%s:%d adding %s into function %s regsUsed\n", __FUNCTION__, __LINE__, reg->name, currFunc->name);
                currFunc->regsUsed = bitVectSetBit (currFunc->regsUsed, reg->rIdx);
+       }
  
   return (reg);                // addSet(&pic16_dynAllocRegs,reg);
 
@@ -549,11 +558,6 @@ pic16_dirregWithName (char *name)
   return NULL; // name wasn't found in the hash table
 }
 
-static int IS_CONFIG_ADDRESS(int address)
-{
-
-  return address >= 0x300000 && address <= 0x300000d;
-}
 
 /*-----------------------------------------------------------------*/
 /* pic16_allocDirReg - allocates register of given type                  */
@@ -566,12 +570,22 @@ pic16_allocDirReg (operand *op )
 
        if(!IS_SYMOP(op)) {
                debugLog ("%s BAD, op is NULL\n", __FUNCTION__);
+//             fprintf(stderr, "%s BAD, op is NULL\n", __FUNCTION__);
          return NULL;
        }
 
        name = OP_SYMBOL (op)->rname[0] ? OP_SYMBOL (op)->rname : OP_SYMBOL (op)->name;
 
-       debugLog ("%s symbol name %s\n", __FUNCTION__,name);
+       if(!SPEC_OCLS( OP_SYM_ETYPE(op))) {
+               if(pic16_debug_verbose)
+               {
+                       fprintf(stderr, "%s:%d symbol %s(r:%s) is not assigned to a memmap\n", __FILE__, __LINE__,
+                               OP_SYMBOL(op)->name, OP_SYMBOL(op)->rname);
+               }
+               return NULL;
+       }
+
+       debugLog ("%s:%d symbol name %s\n", __FUNCTION__, __LINE__, name);
 //     fprintf(stderr, "%s symbol name %s\n", __FUNCTION__,name);
 
        {
@@ -635,21 +649,47 @@ pic16_allocDirReg (operand *op )
                 * a new one and put it in the hash table AND in the 
                 * dynDirectRegNames set */
                if(IN_CODESPACE( SPEC_OCLS( OP_SYM_ETYPE(op)))) {
-                       if(pic16_debug_verbose)
-                               fprintf(stderr, "%s:%d symbol %s in codespace\n", __FILE__, __LINE__,
-                                       OP_SYMBOL(op)->name);
+
+//                     if(pic16_debug_verbose)
+//                             fprintf(stderr, "%s:%d symbol %s in codespace\n", __FILE__, __LINE__,
+//                                     OP_SYMBOL(op)->name);
+
+                       debugLog("%s:%d sym: %s in codespace\n", __FUNCTION__, __LINE__, OP_SYMBOL(op)->name);
                  return NULL;
                }
 
-               if(!IS_CONFIG_ADDRESS(address)) {
+               if(1) { //!PIC16_IS_CONFIG_ADDRESS(address)) 
 //                     fprintf(stderr,"%s:allocating new reg %s\n",__FUNCTION__, name);
 
-                       if(SPEC_SCLS(OP_SYM_ETYPE(op)))regtype = REG_SFR;
-       
+                       /* this is an error, why added? -- VR */
+//                     if(SPEC_SCLS(OP_SYM_ETYPE(op)))regtype = REG_SFR;
+
+                       if(OP_SYMBOL(op)->onStack) {
+                               fprintf(stderr, "%s:%d onStack %s\n", __FILE__, __LINE__, OP_SYMBOL(op)->name);
+//                             OP_SYMBOL(op)->onStack = 0;
+                               SPEC_OCLS(OP_SYM_ETYPE(op)) = data;
+                               regtype = REG_GPR;
+                       }
+
+                       if(!IN_DIRSPACE( SPEC_OCLS( OP_SYM_ETYPE(op)))) {                                               // patch 13
+                               if(pic16_debug_verbose)                                                                 //
+                               {                                                                                       //
+                                       fprintf(stderr, "dispace:%d farspace:%d codespace:%d regspace:%d stack:%d eeprom: %d\n",
+                                               IN_DIRSPACE( SPEC_OCLS( OP_SYM_ETYPE(op))),
+                                               IN_FARSPACE( SPEC_OCLS( OP_SYM_ETYPE(op))),
+                                               IN_CODESPACE( SPEC_OCLS( OP_SYM_ETYPE(op))),
+                                               IN_REGSP( SPEC_OCLS( OP_SYM_ETYPE(op))),
+                                               IN_STACK( OP_SYM_ETYPE(op)),
+                                               SPEC_OCLS(OP_SYM_ETYPE(op)) == eeprom);
+
+                                       fprintf(stderr, "%s:%d symbol %s NOT in dirspace\n", __FILE__, __LINE__,        //
+                                               OP_SYMBOL(op)->name);                                                   //
+                               }                                                                                       //
+                       }                                                                                               // patch 13
+
                        reg = newReg(regtype, PO_DIR, rDirectIdx++, name,getSize (OP_SYMBOL (op)->type),0, op);
                        debugLog ("%d  -- added %s to hash, size = %d\n", __LINE__, name,reg->size);
 
-//                     hTabAddItem(&dynDirectRegNames, regname2key(name), reg);        /* commented out */
 
 //                     if (SPEC_ABSA ( OP_SYM_ETYPE(op)) ) {
 //                             fprintf(stderr, " ralloc.c at fixed address: %s - changing to REG_SFR\n",name);
@@ -662,12 +702,12 @@ pic16_allocDirReg (operand *op )
                                reg->isBitField = 1;
                        } else {
 //                             fprintf(stderr, "%s:%d adding %s in direct registers\n", __FILE__, __LINE__, reg->name);
+//                             addSet(&pic16_dynDirectRegs, reg);
                                checkAddReg(&pic16_dynDirectRegs, reg);
                        }
        
                } else {
                        debugLog ("  -- %s is declared at address 0x30000x\n",name);
-                       fprintf(stderr, "  -- %s is declared at address 0x30000x\n",name);
        
                  return NULL;
                }
@@ -676,6 +716,12 @@ pic16_allocDirReg (operand *op )
        if (SPEC_ABSA ( OP_SYM_ETYPE(op)) ) {
                reg->isFixed = 1;
                reg->address = SPEC_ADDR ( OP_SYM_ETYPE(op));
+
+               /* work around for user defined registers in access bank */
+               if((reg->address>= 0x00 && reg->address < 0x80)
+                       || (reg->address >= 0xf80 && reg->address <= 0xfff))
+                       reg->accessBank = 1;
+               
                debugLog ("  -- and it is at a fixed address 0x%02x\n",reg->address);
        }
 
@@ -686,7 +732,7 @@ pic16_allocDirReg (operand *op )
 /* pic16_allocRegByName - allocates register of given type                  */
 /*-----------------------------------------------------------------*/
 regs *
-pic16_allocRegByName (char *name, int size)
+pic16_allocRegByName (char *name, int size, operand *op)
 {
 
   regs *reg;
@@ -704,11 +750,13 @@ pic16_allocRegByName (char *name, int size)
     /* 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, NULL);
+
+//     fprintf (stderr,"%s:%d symbol name %s\tregop= %p\n", __FUNCTION__, __LINE__, name, op);
+
+    reg = newReg(REG_GPR, PO_DIR, rDirectIdx++, name,size,0, op);
 
     debugLog ("%d  -- added %s to hash, size = %d\n", __LINE__, name,reg->size);
-    //fprintf(stderr, "  -- added %s to hash, size = %d\n", name,reg->size);
+       //fprintf(stderr, "  -- added %s to hash, size = %d\n", name,reg->size);
 
     //hTabAddItem(&dynDirectRegNames, regname2key(name), reg); /* initially commented out */
     addSet(&pic16_dynDirectRegs, reg);
@@ -726,6 +774,7 @@ regs *pic16_typeRegWithIdx (int idx, int type, int fixed)
   regs *dReg;
 
   debugLog ("%s - requesting index = 0x%x\n", __FUNCTION__,idx);
+//  fprintf(stderr, "%s - requesting index = 0x%x\n", __FUNCTION__, idx);
 
   switch (type) {
 
@@ -793,6 +842,7 @@ pic16_allocWithIdx (int idx)
   regs *dReg;
 
   debugLog ("%s - allocating with index = 0x%x\n", __FUNCTION__,idx);
+//  fprintf(stderr, "%s - allocating with index = 0x%x\n", __FUNCTION__,idx);
 
   if( (dReg = regWithIdx ( pic16_dynAllocRegs, idx,0)) != NULL) {
 
@@ -926,8 +976,12 @@ extern void pic16_groupRegistersInSection(set *regset);
 
 extern void pic16_dump_equates(FILE *of, set *equs);
 //extern void pic16_dump_map(void);
-extern void pic16_dump_section(FILE *of, set *section, int fix);
+extern void pic16_dump_usection(FILE *of, set *section, int fix);
+extern void pic16_dump_isection(FILE *of, set *section, int fix);
 extern void pic16_dump_int_registers(FILE *of, set *section);
+extern void pic16_dump_idata(FILE *of, set *idataSymSet);
+
+extern void pic16_dump_gsection(FILE *of, set *sections);
 
 static void packBits(set *bregs)
 {
@@ -991,66 +1045,6 @@ static void packBits(set *bregs)
       
 }
 
-
-
-#if 0
-static void bitEQUs(FILE *of, set *bregs)
-{
-  regs *breg,*bytereg;
-  int bit_no=0;
-
-  //fprintf(stderr," %s\n",__FUNCTION__);
-  for (breg = setFirstItem(bregs) ; breg ;
-       breg = setNextItem(bregs)) {
-
-    //fprintf(stderr,"bit reg: %s\n",breg->name);
-
-    bytereg = breg->reg_alias;
-    if(bytereg)
-      fprintf (of, "%s\tEQU\t( (%s<<3)+%d)\n",
-              breg->name,
-              bytereg->name,
-              breg->rIdx & 0x0007);
-
-    else {
-      fprintf(stderr, "bit field is not assigned to a register\n");
-      fprintf (of, "%s\tEQU\t( (bitfield%d<<3)+%d)\n",
-              breg->name,
-              bit_no>>3,
-              bit_no & 0x0007);
-
-      bit_no++;
-    }
-  }
-      
-}
-
-static void aliasEQUs(FILE *of, set *fregs, int use_rIdx)
-{
-  regs *reg;
-
-
-  for (reg = setFirstItem(fregs) ; reg ;
-       reg = setNextItem(fregs)) {
-
-    if(!reg->isEmitted && reg->wasUsed) {
-      if(use_rIdx) {
-        if (reg->type != REG_SFR) {
-         fprintf (of, "%s\tEQU\t0x%03x\n",
-                  reg->name,
-                  reg->rIdx);
-        }
-      }
-      else
-       fprintf (of, "%s\tEQU\t0x%03x\n",
-                reg->name,
-                reg->address);
-    }
-  }
-      
-}
-#endif
-
 void pic16_writeUsedRegs(FILE *of) 
 {
        packBits(pic16_dynDirectBitRegs);
@@ -1063,62 +1057,28 @@ void pic16_writeUsedRegs(FILE *of)
        pic16_groupRegistersInSection(pic16_dynProcessorRegs);
        
        
-#if 0
-       pic16_assignFixedRegisters(pic16_dynAllocRegs);
-       pic16_assignFixedRegisters(pic16_dynStackRegs);
-       pic16_assignFixedRegisters(pic16_dynDirectRegs);
-       pic16_assignFixedRegisters(pic16_dynProcessorRegs);
-
-       pic16_assignRelocatableRegisters(pic16_dynDirectBitRegs, 0);
-       pic16_assignRelocatableRegisters(pic16_dynInternalRegs,0);
-       pic16_assignRelocatableRegisters(pic16_dynAllocRegs,0);
-       pic16_assignRelocatableRegisters(pic16_dynStackRegs,0);
-       pic16_assignRelocatableRegisters(pic16_dynDirectRegs,0);
-#endif
-
-//     pic16_dump_map();
-//     pic16_dump_cblock(of);
-
        /* dump equates */
        pic16_dump_equates(of, pic16_equ_data);
-       
+
+//     pic16_dump_esection(of, pic16_rel_eedata, 0);
+//     pic16_dump_esection(of, pic16_fix_eedata, 0);
+
+       /* dump initialised data */
+       pic16_dump_isection(of, rel_idataSymSet, 0);
+       pic16_dump_isection(of, fix_idataSymSet, 1);
+
        /* dump internal registers */
        pic16_dump_int_registers(of, pic16_int_regs);
        
-       /* dump other variables */
-       pic16_dump_section(of, pic16_rel_udata, 0);
-       pic16_dump_section(of, pic16_fix_udata, 1);
+       /* dump generic section variables */
+       pic16_dump_gsection(of, sectNames);
 
+       /* dump other variables */
+       pic16_dump_usection(of, pic16_rel_udata, 0);
+       pic16_dump_usection(of, pic16_fix_udata, 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 */
@@ -2058,6 +2018,15 @@ serialRegAssign (eBBlock ** ebbs, int count)
 
          debugLog ("  op: %s\n", decodeOp (ic->op));
 
+               if(IC_RESULT(ic) && !IS_ITEMP( IC_RESULT(ic)))
+                       pic16_allocDirReg(IC_RESULT(ic));
+
+               if(IC_LEFT(ic) && !IS_ITEMP( IC_LEFT(ic)))
+                       pic16_allocDirReg(IC_LEFT(ic));
+
+               if(IC_RIGHT(ic) && !IS_ITEMP( IC_RIGHT(ic)))
+                       pic16_allocDirReg(IC_RIGHT(ic));
+
          /* if this is an ipop that means some live
             range will have to be assigned again */
          if (ic->op == IPOP)
@@ -2123,6 +2092,17 @@ serialRegAssign (eBBlock ** ebbs, int count)
 
                }
 
+             /* If the live range preceeds the point of definition 
+                then ideally we must take into account registers that 
+                have been allocated after sym->liveFrom but freed
+                before ic->seq. This is complicated, so spill this
+                symbol instead and let fillGaps handle the allocation. */
+             if (sym->liveFrom < ic->seq)
+               {
+                   spillThis (sym);
+                   continue;                 
+               }
+
              /* if it has a spillocation & is used less than
                 all other live ranges then spill this */
                if (willCS) {
@@ -2526,21 +2506,21 @@ regTypeNum ()
          (ic = hTabItemWithKey (iCodehTab,
                                 bitVectFirstBit (sym->defs))) &&
          POINTER_GET (ic) &&
-         !sym->noSpilLoc &&
-         !IS_BITVAR (sym->etype)) {
-       
-
-       debugLog ("  %d - \n", __LINE__);
-
-       /* if remat in data space */
-       if (OP_SYMBOL (IC_LEFT (ic))->remat &&
-           DCL_TYPE (aggrToPtr (sym->type, FALSE)) == POINTER) {
+         !IS_BITVAR (sym->etype) &&
+         (aggrToPtrDclType (operandType (IC_LEFT (ic)), FALSE) == POINTER)) {
 
+       if (ptrPseudoSymSafe (sym, ic)) {
+          
+         symbol *psym;
+         
+         debugLog ("  %d - \n", __LINE__);
+             
          /* create a psuedo symbol & force a spil */
          //X symbol *psym = newSymbol (rematStr (OP_SYMBOL (IC_LEFT (ic))), 1);
-         symbol *psym = rematStr (OP_SYMBOL (IC_LEFT (ic)));
+         psym = rematStr (OP_SYMBOL (IC_LEFT (ic)));
          psym->type = sym->type;
          psym->etype = sym->etype;
+         psym->psbase = ptrBaseRematSym (OP_SYMBOL (IC_LEFT (ic)));
          strcpy (psym->rname, psym->name);
          sym->isspilt = 1;
          sym->usl.spillLoc = psym;
@@ -2563,8 +2543,9 @@ regTypeNum ()
 #else
     if(IS_CODEPTR (sym->type)) {
 #endif
-      debugLog ("  %d const pointer type requires %d registers, changing to 2\n",__LINE__,sym->nRegs);
-      sym->nRegs = 2;
+      // what IS this ???? (HJD)
+      debugLog ("  %d const pointer type requires %d registers, changing to 3\n",__LINE__,sym->nRegs); // patch 14
+      sym->nRegs = 3; // patch 14
     }
 
       if (sym->nRegs > 4) {
@@ -2727,15 +2708,20 @@ packRegsForAssign (iCode * ic, eBBlock * ebp)
   debugAopGet ("  left:", IC_LEFT (ic));
   debugAopGet ("  right:", IC_RIGHT (ic));
 
+//     fprintf(stderr, "%s:%d symbol = %s\n", __FILE__, __LINE__, OP_SYMBOL( IC_RESULT(ic))->name);
+
+#if 0
   /* 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))))) {
+    if(PIC16_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));
-       fprintf(stderr, "  setting config word to %x\n", 
+
+       fprintf(stderr, "%s:%d  setting config word to %x\n", __FILE__, __LINE__, 
                  (int) floatFromVal (IC_RIGHT(ic)->operand.valOperand));
+
        pic16_assignConfigWordValue(  SPEC_ADDR ( OP_SYM_ETYPE(IC_RESULT(ic))),
                                (int) floatFromVal (IC_RIGHT(ic)->operand.valOperand));
       }
@@ -2753,6 +2739,7 @@ packRegsForAssign (iCode * ic, eBBlock * ebp)
 
     }
   }
+#endif
        debugLog(" %d - actuall processing\n", __LINE__ );
 
   if (!IS_ITEMP (IC_RESULT (ic))) {
@@ -2760,12 +2747,6 @@ packRegsForAssign (iCode * ic, eBBlock * ebp)
     debugLog ("  %d - result is not temp\n", __LINE__);
   }
 
-#if 0
-  if (IC_LEFT (ic) && !IS_ITEMP (IC_LEFT (ic))) {
-    debugLog ("  %d - left is not temp, allocating\n", __LINE__);
-    pic16_allocDirReg(IC_LEFT (ic));
-  }
-#endif
 
 /* See BUGLOG0001 - VR */
 #if 1
@@ -2817,21 +2798,6 @@ packRegsForAssign (iCode * ic, eBBlock * ebp)
 
        debugLog("%d\tSearching for iTempNN\n", __LINE__);
 
-#if 0
-       if(IS_TRUE_SYMOP( IC_RESULT(dic))) {
-               debugLog("%d - dic result is a TRUE_SYMOP\n", __LINE__);
-               debugAopGet(" result is ", IC_RESULT(dic));
-       }
-       if(IS_TRUE_SYMOP( IC_LEFT(dic))) {
-               debugLog("%d - dic left is a SYMOP\n", __LINE__);
-               debugAopGet("   left is ", IC_LEFT(dic));
-       }
-       if(IS_TRUE_SYMOP( IC_RIGHT(dic))) {
-               debugLog("%d - dic right is a SYMOP\n", __LINE__);
-               debugAopGet("  right is ", IC_RIGHT(dic));
-       }
-#endif
-
       if (IS_TRUE_SYMOP (IC_RESULT (dic)) &&
          IS_OP_VOLATILE (IC_RESULT (dic)))
        {
@@ -2840,27 +2806,6 @@ packRegsForAssign (iCode * ic, eBBlock * ebp)
          break;
        }
 
-#if 0
-      if (IS_TRUE_SYMOP( IC_RIGHT (dic)) &&
-               IS_OP_VOLATILE (IC_RIGHT(dic)))
-       {
-         debugLog ("  %d - dic right is VOLATILE\n", __LINE__);
-         dic = NULL;
-         break;
-       }
-#endif
-
-#if 0
-      if (IS_TRUE_SYMOP( IC_LEFT (dic)) &&
-               IS_OP_VOLATILE (IC_LEFT(dic)))
-       {
-         debugLog ("  %d - dic left is VOLATILE\n", __LINE__);
-         dic = NULL;
-         break;
-       }
-#endif
-
-
 #if 1
       if( IS_SYMOP( IC_RESULT(dic)) &&
        IS_BITFIELD( OP_SYMBOL(IC_RESULT(dic))->etype ) ) {
@@ -2939,6 +2884,13 @@ packRegsForAssign (iCode * ic, eBBlock * ebp)
       OP_SYMBOL (IC_RESULT (ic))->iaccess)
     {
 
+#if 0
+       /* clear the onStack flag, the port doesn't support it yet! FIXME */
+       if(OP_SYMBOL(IC_RESULT(ic))->onStack)
+               OP_SYMBOL(IC_RESULT(ic))->onStack = 0;
+#endif
+       
+
       /* the operation has only one symbol
          operator then we can pack */
       if ((IC_LEFT (dic) && !IS_SYMOP (IC_LEFT (dic))) ||
@@ -2985,6 +2937,17 @@ pack:
 
 }
 
+#if 1
+
+#define NO_packRegsForAccUse
+#define NO_packRegsForSupport
+#define NO_packRegsForOneuse
+#define NO_cast_peep
+
+#endif
+
+
+#ifndef NO_packRegsForSupport
 /*-----------------------------------------------------------------*/
 /* findAssignToSym : scanning backwards looks for first assig found */
 /*-----------------------------------------------------------------*/
@@ -3025,6 +2988,11 @@ findAssignToSym (operand * op, iCode * ic)
              OP_SYMBOL (IC_RIGHT (dic))->onStack)
            {
 
+#if 0
+               if(OP_SYMBOL(IC_RESULT(ic))->onStack)
+                       OP_SYMBOL(IC_RESULT(ic))->onStack = 0;
+#endif
+
              if (IC_RESULT (ic)->key != IC_RIGHT (dic)->key &&
                  IC_LEFT (ic)->key != IC_RIGHT (dic)->key &&
                  IC_RIGHT (ic)->key != IC_RIGHT (dic)->key)
@@ -3062,7 +3030,10 @@ findAssignToSym (operand * op, iCode * ic)
 
 
 }
+#endif
 
+
+#ifndef NO_packRegsForSupport
 /*-----------------------------------------------------------------*/
 /* packRegsForSupport :- reduce some registers for support calls   */
 /*-----------------------------------------------------------------*/
@@ -3140,10 +3111,12 @@ right:
 
   return change;
 }
+#endif
 
-#define IS_OP_RUONLY(x) (x && IS_SYMOP(x) && OP_SYMBOL(x)->ruonly)
 
+#define IS_OP_RUONLY(x) (x && IS_SYMOP(x) && OP_SYMBOL(x)->ruonly)
 
+#ifndef NO_packRegsForOneuse
 /*-----------------------------------------------------------------*/
 /* packRegsForOneuse : - will reduce some registers for single Use */
 /*-----------------------------------------------------------------*/
@@ -3273,6 +3246,8 @@ packRegsForOneuse (iCode * ic, operand * op, eBBlock * ebp)
   return sic;
 
 }
+#endif
+
 
 /*-----------------------------------------------------------------*/
 /* isBitwiseOptimizable - requirements of JEAN LOUIS VERN          */
@@ -3304,11 +3279,12 @@ isBitwiseOptimizable (iCode * ic)
     return FALSE;
 }
 
+
+#ifndef NO_packRegsForAccUse
+
 /*-----------------------------------------------------------------*/
 /* packRegsForAccUse - pack registers for acc use                  */
 /*-----------------------------------------------------------------*/
-#if 0
-
 static void
 packRegsForAccUse (iCode * ic)
 {
@@ -3464,6 +3440,7 @@ accuse:
 }
 #endif
 
+
 /*-----------------------------------------------------------------*/
 /* packForPush - hueristics to reduce iCode for pushing            */
 /*-----------------------------------------------------------------*/
@@ -3582,14 +3559,6 @@ static void isData(sym_link *sl)
 }
 
 
-/* set if conditional to 1 to disable optimizations */
-
-#define NO_packRegsForAccUse
-#if 0
-#define NO_packRegsForSupport
-#define NO_packRegsForOneuse
-//#define NO_cast_peep
-#endif
 /*--------------------------------------------------------------------*/
 /* pic16_packRegisters - does some transformations to reduce          */
 /*                   register pressure                                */
@@ -3616,7 +3585,8 @@ pic16_packRegisters (eBBlock * ebp)
 //             debugLog("%d\n", __LINE__);
        /* find assignment of the form TrueSym := iTempNN:1 */
        /* see BUGLOG0001 for workaround with the CAST - VR */
-       if ((ic->op == '=' || ic->op == CAST) && !POINTER_SET (ic))
+//     if ( (ic->op == '=' || ic->op == CAST) && !POINTER_SET (ic) ) // patch 11
+       if ( (ic->op == '=') && !POINTER_SET (ic) ) // patch 11
          change += packRegsForAssign (ic, ebp);
        /* debug stuff */
        if (ic->op == '=')
@@ -4040,6 +4010,10 @@ pic16_assignRegisters (eBBlock ** ebbs, int count)
   /* and serially allocate registers */
   serialRegAssign (ebbs, count);
 
+//  debugLog ("ebbs after serialRegAssign:\n");
+//  dumpEbbsToDebug (ebbs, count);
+
+
   //pic16_freeAllRegs();
 
   /* if stack was extended then tell the user */