* src/pic16/device.c (checkAddSym): NEW, adds a symbol to set while
authorvrokas <vrokas@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Tue, 2 Mar 2004 13:50:29 +0000 (13:50 +0000)
committervrokas <vrokas@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Tue, 2 Mar 2004 13:50:29 +0000 (13:50 +0000)
checking if symbol is already in set,
* src/pic16/device.h: prototype for checkAddSym,
* src/pic16/gen.c: (_G): added entry interruptvector,
* (assignResultValue): removed some commented out lines,
* (genFunction): check for ISR via sym->type, absolute section for
interrupt code is created via a new pBlock, the goto instruction is
placed now correctly at the interrupt vector position, changed all
references from ivec to _G.interruptvector,
* WREG,STATUS,BSR are not saved in stack upon an entry to interrupt
is the interrupt is a high priority one, same for return from ISR,
* src/pic16/glue.c: changed all calls of addSetHead for publics and
externs to calls of checkAddSym,
* src/pic16/pcode.c (pic16_pBlockConvert2*): emit warning when
pic16_pcode_verbose flag is set,
* src/pic16/pcode.h: extern to pic16_pcode_verbose,
* src/pic16/pcoderegs.c: message about how many registers are saved
will only be emitted if pic16_pcode_verbose flag is set,

git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@3241 4a8a32a2-be11-0410-ad9d-d568d2c75423

ChangeLog
src/pic16/device.c
src/pic16/device.h
src/pic16/gen.c
src/pic16/glue.c
src/pic16/pcode.c
src/pic16/pcode.h
src/pic16/pcoderegs.c

index ff929c693642d939af1be745a686490e2d3676ad..fe4b2e0ad0a30f77ef0d32d0f4d6f56d0a16fcd9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,24 @@
+2004-03-02 Vangelis Rokas <vrokas AT otenet.gr>
+
+       * src/pic16/device.c (checkAddSym): NEW, adds a symbol to set while
+       checking if symbol is already in set,
+       * src/pic16/device.h: prototype for checkAddSym,
+       * src/pic16/gen.c: (_G): added entry interruptvector,
+       * (assignResultValue): removed some commented out lines,
+       * (genFunction): check for ISR via sym->type, absolute section for
+       interrupt code is created via a new pBlock, the goto instruction is
+       placed now correctly at the interrupt vector position, changed all
+       references from ivec to _G.interruptvector,
+       * WREG,STATUS,BSR are not saved in stack upon an entry to interrupt
+       is the interrupt is a high priority one, same for return from ISR,
+       * src/pic16/glue.c: changed all calls of addSetHead for publics and
+       externs to calls of checkAddSym,
+       * src/pic16/pcode.c (pic16_pBlockConvert2*): emit warning when
+       pic16_pcode_verbose flag is set,
+       * src/pic16/pcode.h: extern to pic16_pcode_verbose,
+       * src/pic16/pcoderegs.c: message about how many registers are saved
+       will only be emitted if pic16_pcode_verbose flag is set,
+
 2004-03-02 Erik Petrich <epetrich AT ivorytower.norman.ok.us>
 
        * src/ds390/ralloc.h,
@@ -26,7 +47,7 @@
        * (print_idataType, print_idata): NEW to create idata sections
        * src/pic16/device.h: idataSymSet new variable
        * src/pic16/gen.c (genFunction): fixed some bugs in string
-       comparing, improved the aboslute section creation for ISRs,
+       comparing, improved the absolute section creation for ISRs,
        added FSR0L/FSR0H in registers that are saved in an ISR,
        * (genInline): fixed the processing of inline snippets,
        now they undergo no process by the peephole optimizer
index a9f5dfb3d630c4ce60bed85667e2c724a67ec564..14fe64df26be2362cc8850bc24090f9b9635f4f0 100644 (file)
@@ -625,6 +625,23 @@ int checkAddReg(set **set, regs *reg)
   return 0;
 }
 
+int checkAddSym(set **set, symbol *sym)
+{
+  symbol *tmp;
+
+       for(tmp = setFirstItem( *set ); tmp; tmp = setNextItem(*set)) {
+               if(!strcmp(tmp->name, sym->name))break;
+       }
+       
+       if(!tmp) {
+               addSet(set, sym);
+               return 1;
+       }
+
+  return 0;
+}
+
+
 /*-----------------------------------------------------------------*
  * void pic16_groupRegistersInSection - add each register to its   *
  *     corresponding section                                      *
index cd115fbb174cb0da039aa78676ccf6a257a82447..62c5fef2503ad906f0f7f0358bdcde6604d0e4f7 100644 (file)
@@ -80,6 +80,6 @@ int pic16_REGallBanks(regs *reg);
 void pic16_setMaxRAM(int size);
 
 int checkAddReg(set **set, regs *reg);
-
+int checkAddSym(set **set, symbol *reg);
 
 #endif  /* __DEVICE_H__ */
index 1d43e8884c5917a07b057b4e3da7079c83feac72..60e92e4f7672e4388260afaf384ba870231e2bf9 100644 (file)
@@ -122,6 +122,7 @@ static struct {
     short debugLine;
     short nRegsSaved;
     set *sendSet;
+    int interruptvector;
 } _G;
 
 /* Resolved ifx structure. This structure stores information
@@ -2425,24 +2426,16 @@ static void assignResultValue(operand * oper, int rescall)
                        if(size>1) {
                                /* 16-bits, result in PRODL:WREG */
                                pic16_loadFromReturn(oper, 1, pic16_popCopyReg(&pic16_pc_prodl));
-//                             pic16_emitpcode(POC_MOVFF,
-//                                     pic16_popGet2p(pic16_popCopyReg(&pic16_pc_prodl), pic16_popGet(AOP(oper), 1)));
                        }
                        
                        if(size>2) {
                                /* 24-bits, result in PRODH:PRODL:WREG */
                                pic16_loadFromReturn(oper, 2, pic16_popCopyReg(&pic16_pc_prodh)); // patch 14
-
-//                             pic16_emitpcode(POC_MOVFF,
-//                                     pic16_popGet2p(pic16_popCopyReg(&pic16_pc_prodh), pic16_popGet(AOP(oper), 2)));
                        }
                        
                        if(size>3) {
                                /* 32-bits, result in FSR0L:PRODH:PRODL:WREG */
                                pic16_loadFromReturn(oper, 3, pic16_popCopyReg(&pic16_pc_fsr0l)); // patch14
-
-//                             pic16_emitpcode(POC_MOVFF,
-//                                     pic16_popGet2p(pic16_popCopyReg(&pic16_pc_fsr0l), pic16_popGet(AOP(oper), 3)));
                        }
                } else {
                        /* >32-bits, result on stack, and FSR0 points to beginning.
@@ -3155,7 +3148,7 @@ static void genFunction (iCode *ic)
 {
   symbol *sym;
   sym_link *ftype;
-
+  
        DEBUGpic16_emitcode ("; ***","%s  %d curr label offset=%dprevious max_key=%d ",__FUNCTION__,__LINE__,labelOffset,max_key);
 
        labelOffset += (max_key+4);
@@ -3166,20 +3159,18 @@ static void genFunction (iCode *ic)
        ftype = operandType(IC_LEFT(ic));
        sym = OP_SYMBOL(IC_LEFT(ic));
 
-       if(/*!IFFUNC_ISNAKED(ftype) &&*/ IFFUNC_ISISR(ftype)) {
+       if(IFFUNC_ISISR(sym->type /*ftype*/)) {
                /* create an absolute section at the interrupt vector:
-                * that is 0x0008 for interrupt 1, 0x0018 interrupt 2 */
-         int ivec;
+                * that is 0x0008 for interrupt 1 (high), 0x0018 interrupt 2 (low) */
          symbol *asym;
          char asymname[128];
-         
+         pBlock *apb;
+
                {
                  int i, found=-1;
 
                        sym = OP_SYMBOL( IC_LEFT(ic));
                        for(i=0;i<=2;i++) {
-//                             fprintf(stderr, "comparing name int %d\t%s with %s\n",
-//                                             i, interrupts[i]->name, sym->name);
                                if(interrupts[i]->name
                                        && !STRCASECMP(interrupts[i]->name, sym->name)) {
                                        found = i;
@@ -3190,23 +3181,28 @@ static void genFunction (iCode *ic)
                        if(found == -1) {
                                fprintf(stderr, "PIC16 port: %s:%d: interrupt function but cannot locate symbol (%s)\n",
                                        __FILE__, __LINE__, sym->name);
-                               exit(-1);
+                               assert( 0 );
                        }
-                       ivec = found;
+                       _G.interruptvector = found;
                }
-               sprintf(asymname, "ivec_%d_%s", ivec, sym->name);
+
+               sprintf(asymname, "ivec_%d_%s", _G.interruptvector, sym->name);
                asym = newSymbol(asymname, 0);
-               pic16_emitcode(";","-----------------------------------------");
-               pic16_emitcode(";"," interrupt vector %d for function %s", ivec, sym->name);
-               pic16_emitcode(";","-----------------------------------------");
 
-               pic16_addpCode2pBlock(pb, pic16_newpCodeFunction(moduleName, asym->name));
-               pic16_pBlockConvert2Absolute(pb);
+               apb = pic16_newpCodeChain(NULL, 'A', pic16_newpCodeCharP("; Starting pCode block for absolute section"));
+               pic16_addpBlock( apb );
+
+               pic16_addpCode2pBlock(apb,
+                       pic16_newpCodeCharP(";-----------------------------------------"));
 
-               pic16_emitpcode(POC_GOTO, pic16_popGetWithString( sym->rname ));
+
+               pic16_addpCode2pBlock(apb, pic16_newpCodeFunction(moduleName, asym->name));
+
+               pic16_addpCode2pBlock(apb,
+                       pic16_newpCode(POC_GOTO, pic16_popGetWithString( sym->rname )));
                
                /* mark the end of this tiny function */
-               pic16_addpCode2pBlock(pb,pic16_newpCodeFunction(NULL,NULL));
+               pic16_addpCode2pBlock(apb,pic16_newpCodeFunction(NULL,NULL));
 
                {
                  absSym *abSym;
@@ -3214,7 +3210,7 @@ static void genFunction (iCode *ic)
                        abSym = Safe_calloc(1, sizeof(absSym));
                        abSym->name = Safe_strdup( asymname );
 
-                       switch( ivec ) {
+                       switch( _G.interruptvector ) {
                                case 0: abSym->address = 0x000000; break;
                                case 1: abSym->address = 0x000008; break;
                                case 2: abSym->address = 0x000018; break;
@@ -3233,6 +3229,7 @@ static void genFunction (iCode *ic)
        pic16_emitcode("","%s:",sym->rname);
        pic16_addpCode2pBlock(pb,pic16_newpCodeFunction(moduleName,sym->rname));
 
+
        {
          absSym *ab;
 
@@ -3241,7 +3238,7 @@ static void genFunction (iCode *ic)
                                pic16_pBlockConvert2Absolute(pb);
                                break;
                        }
-               
+
        }
 
 
@@ -3259,15 +3256,22 @@ static void genFunction (iCode *ic)
        if (IFFUNC_ISISR(sym->type)) {
          int i;
                /* an ISR should save: WREG, STATUS, BSR, PRODL, PRODH, FSR0L, FSR0H */
-               pic16_pushpCodeOp( pic16_popCopyReg( &pic16_pc_wreg ));
-               pic16_pushpCodeOp( pic16_popCopyReg( &pic16_pc_status ));
-               pic16_pushpCodeOp( pic16_popCopyReg( &pic16_pc_bsr ));
+               if(!(_G.interruptvector == 1)) {
+
+                       /* do not save WREG,STATUS,BSR for high priority interrupts
+                        * because they are stored in the hardware shadow registers already */
+                        
+                       pic16_pushpCodeOp( pic16_popCopyReg( &pic16_pc_wreg ));
+                       pic16_pushpCodeOp( pic16_popCopyReg( &pic16_pc_status ));
+                       pic16_pushpCodeOp( pic16_popCopyReg( &pic16_pc_bsr ));
+               }
+
                pic16_pushpCodeOp( pic16_popCopyReg( &pic16_pc_prodl ));
                pic16_pushpCodeOp( pic16_popCopyReg( &pic16_pc_prodh ));
                pic16_pushpCodeOp( pic16_popCopyReg( &pic16_pc_fsr0l ));
                pic16_pushpCodeOp( pic16_popCopyReg( &pic16_pc_fsr0h ));
 
-                pic16_pBlockConvert2ISR(pb);
+//                pic16_pBlockConvert2ISR(pb);
                 
                /* if any registers used */
                if (sym->regsUsed) {
@@ -3312,14 +3316,17 @@ static void genFunction (iCode *ic)
                                DEBUGpic16_emitcode("; **", "Saving used registers in stack");
                                for ( i = 0 ; i < sym->regsUsed->size ; i++) {
                                        if (bitVectBitValue(sym->regsUsed,i)) {
+
 //                                             fprintf(stderr, "%s:%d function %s uses register %s\n",
 //                                                             __FILE__, __LINE__, OP_SYMBOL(IC_LEFT(ic))->name,
 //                                                             pic16_regWithIdx(i)->name);
 
                                                pic16_pushpCodeOp( pic16_popRegFromIdx(i) );
+
 //                                             pic16_emitpcode(POC_MOVFF, pic16_popCombine2(
 //                                                     PCOR(pic16_popCopyReg( PCOR(pic16_popRegFromIdx(i)))),
 //                                                     &pic16_pc_postdec1, 0));
+
                                                _G.nRegsSaved++;
                                        }
                                }
@@ -3449,10 +3456,20 @@ static void genEndFunction (iCode *ic)
                pic16_poppCodeOp( pic16_popCopyReg( &pic16_pc_fsr0l));
                pic16_poppCodeOp( pic16_popCopyReg( &pic16_pc_prodh ));
                pic16_poppCodeOp( pic16_popCopyReg( &pic16_pc_prodl ));
-               pic16_poppCodeOp( pic16_popCopyReg( &pic16_pc_bsr ));
-               pic16_poppCodeOp( pic16_popCopyReg( &pic16_pc_status ));
-               pic16_poppCodeOp( pic16_popCopyReg( &pic16_pc_wreg ));
+
+               if(!(_G.interruptvector == 1)) {
+                       /* do not restore interrupt vector for WREG,STATUS,BSR
+                        * for high priority interrupt, see genFunction */
+                        
+                       pic16_poppCodeOp( pic16_popCopyReg( &pic16_pc_bsr ));
+                       pic16_poppCodeOp( pic16_popCopyReg( &pic16_pc_status ));
+                       pic16_poppCodeOp( pic16_popCopyReg( &pic16_pc_wreg ));
+               }
        
+               _G.interruptvector = 0;         /* sanity check */
+
+//             pic16_pBlockConvert2ISR(pb);
+
 
                /* if debug then send end of function */
 /*     if (options.debug && currFunc)  */
@@ -9478,9 +9495,10 @@ static void genDataPointerSet(operand *right,
     pic16_aopOp(right,ic,FALSE);
 
     size = AOP_SIZE(right);
-       fprintf(stderr, "%s:%d size= %d\n", __FILE__, __LINE__, size);
 
-#if 1
+//     fprintf(stderr, "%s:%d size= %d\n", __FILE__, __LINE__, size);
+
+#if 0
     if ( AOP_TYPE(result) == AOP_PCODE) {
       fprintf(stderr,"genDataPointerSet   %s, %d\n",
              AOP(result)->aopu.pcop->name,
index 935d183b484d8867728b61ade7b20fbf25c48687..72037fe2f642bcf812f33927d63c13fd476dcca0 100644 (file)
@@ -130,7 +130,8 @@ pic16emitRegularMap (memmap * map, bool addPublics, bool arFlag)
                /* if extern then add to externs */
                if (IS_EXTERN (sym->etype)) {
 //                     if(sym->used)                           // fixme
-                               addSetHead(&externs, sym);
+                               checkAddSym(&externs, sym);
+//                             addSetHead(&externs, sym);
                        continue;
                }
                
@@ -154,7 +155,8 @@ pic16emitRegularMap (memmap * map, bool addPublics, bool arFlag)
                        !IS_STATIC (sym->etype) && !IS_FUNC(sym->type)) {
 //               regs *reg;
                  
-                       addSetHead (&publics, sym);
+                       checkAddSym(&publics, sym);
+//                     addSetHead(&publics, sym);
 
 //                     reg = pic16_allocRegByName(sym->name, sym->size);       //( operandFromSymbol( sym ));
 //                     checkAddReg(&pic16_rel_udata, reg);
@@ -177,7 +179,8 @@ pic16emitRegularMap (memmap * map, bool addPublics, bool arFlag)
                if (IS_FUNC (sym->type) && !IS_STATIC(sym->etype)) {
                        if(SPEC_OCLS(sym->etype) == code) {
 //                             fprintf(stderr, "%s:%d: symbol added: %s\n", __FILE__, __LINE__, sym->rname);
-                               addSetHead(&publics, sym);
+                               checkAddSym(&publics, sym);
+//                             addSetHead(&publics, sym);
                        }
                        continue;
                }
@@ -550,14 +553,17 @@ pic16emitStaticSeg (memmap * map)
 
       /* if it is "extern" then do nothing */
       if (IS_EXTERN (sym->etype)) {
-       addSetHead(&externs, sym);
+       checkAddSym(&externs, sym);
+//     addSetHead(&externs, sym);
        continue;
       }
 
       /* if it is not static add it to the public
          table */
-      if (!IS_STATIC (sym->etype))
-       addSetHead (&publics, sym);
+      if (!IS_STATIC (sym->etype)) {
+        checkAddSym(&publics, sym);
+//     addSetHead (&publics, sym);
+      }
 
 #if 0
       /* print extra debug info if required */
@@ -781,8 +787,10 @@ pic16emitOverlay (FILE * afile)
          /* if global variable & not static or extern
             and addPublics allowed then add it to the public set */
          if ((sym->_isparm && !IS_REGPARM (sym->etype))
-             && !IS_STATIC (sym->etype))
-           addSetHead (&publics, sym);
+             && !IS_STATIC (sym->etype)) {
+             checkAddSym(&publics, sym);
+//         addSetHead (&publics, sym);
+         }
 
          /* if extern then do nothing or is a function
             then do nothing */
index 72b9df106c82489979cc8d73800eedb9cf0671b2..1c445ca72d33e41c30d3f91e64fd6780b948b954 100644 (file)
@@ -3121,13 +3121,14 @@ static char getpBlock_dbName(pBlock *pb)
 }
 void pic16_pBlockConvert2ISR(pBlock *pb)
 {
-  if(!pb)
-    return;
+       if(!pb)return;
 
-  if(pb->cmemmap)
-    pb->cmemmap = NULL;
+       if(pb->cmemmap)pb->cmemmap = NULL;
+
+       pb->dbName = 'I';
 
-  pb->dbName = 'I';
+       if(pic16_pcode_verbose)
+               fprintf(stderr, "%s:%d converting to 'I'interrupt pBlock\n", __FILE__, __LINE__);
 }
 
 void pic16_pBlockConvert2Absolute(pBlock *pb)
@@ -3136,6 +3137,9 @@ void pic16_pBlockConvert2Absolute(pBlock *pb)
        if(pb->cmemmap)pb->cmemmap = NULL;
        
        pb->dbName = 'A';
+       
+       if(pic16_pcode_verbose)
+               fprintf(stderr, "%s:%d converting to 'A'bsolute pBlock\n", __FILE__, __LINE__);
 }
   
 /*-----------------------------------------------------------------*/
@@ -4179,27 +4183,17 @@ void pic16_printpBlock(FILE *of, pBlock *pb)
 
        if(!of)of=stderr;
 
-#if 0
-       if(pb->dbName == 'A') {
-         absSym *ab;
-
-               PCF(pb->pcHead)->
-               for(ab=setFirstItem(absSymSet); ab; ab=setNextItem(absSymSet))
-                       if(strcmp(ab->name, 
-//             fprintf(of, "%s\tcode\t%d"
-       }
-#endif
-
        for(pc = pb->pcHead; pc; pc = pc->next) {
                if(isPCF(pc) && PCF(pc)->fname) {
                        fprintf(of, "S_%s_%s\tcode", PCF(pc)->modname, PCF(pc)->fname);
                        if(pb->dbName == 'A') {
                          absSym *ab;
-                               for(ab=setFirstItem(absSymSet); ab; ab=setNextItem(absSymSet))
+                               for(ab=setFirstItem(absSymSet); ab; ab=setNextItem(absSymSet)) {
                                        if(!strcmp(ab->name, PCF(pc)->fname)) {
-                                               fprintf(of, "\t0X%06X", ab->address);
+                                               fprintf(of, "\t0X%06X\n", ab->address);
                                                break;
                                        }
+                               }
                        }
                        fprintf(of, "\n");
                }
index 1b93a49ecc3006ca15ca2a127ae93ed97eaa47b9..c41ddc58c8a9967b4326a7d2583e3c84f159c758 100644 (file)
@@ -930,6 +930,8 @@ struct regs * pic16_getRegFromInstruction2(pCode *pc);
 
 extern void pic16_pcode_test(void);
 extern int pic16_debug_verbose;
+extern int pic16_pcode_verbose;
+
 /*-----------------------------------------------------------------*
  * pCode objects.
  *-----------------------------------------------------------------*/
index a4b5b25955b9116a83964370a5d9627516f65330..2c66a5527205a3da6cd4282fdee6415e950cc6cb 100644 (file)
@@ -387,7 +387,8 @@ void pic16_RemoveUnusedRegisters(void)
   */
   RemoveRegsFromSet(pic16_dynDirectBitRegs);
 
-  if(total_registers_saved) fprintf(stderr, " *** Saved %d registers ***\n", total_registers_saved);
+  if(total_registers_saved && pic16_pcode_verbose)
+       fprintf(stderr, " *** Saved %d registers ***\n", total_registers_saved);
 }
 
 
@@ -819,7 +820,8 @@ void pic16_pCodeRegOptimizeRegUsage(int level)
     OptimizeRegUsage(pic16_dynStackRegs,level, (OPT_PASSES-passes));
     OptimizeRegUsage(pic16_dynDirectRegs,0, (OPT_PASSES-passes));
 
-    if(total_registers_saved != saved)
+    if((total_registers_saved != saved)
+       && (pic16_pcode_verbose))
       fprintf(stderr, " *** pass %d, Saved %d registers, total saved %d ***\n", 
              (1+OPT_PASSES-passes),total_registers_saved-saved,total_registers_saved);