Changed /Zm1000 to /Zm1500
[fw/sdcc] / src / pic16 / glue.c
index 9b67242373ec3bacc8a955f5eb9bfad65c112c8d..673e9e8ce67627a35e320d53536b1b27740ad4b4 100644 (file)
@@ -70,6 +70,7 @@ extern DEFSETFUNC (rmTmpFiles);
 
 extern void pic16_AnalyzeBanking (void);
 extern void pic16_OptimizeJumps ();
+extern void pic16_OptimizeBanksel ();
 extern void copyFile (FILE * dest, FILE * src);
 extern void pic16_InlinepCode(void);
 extern void pic16_writeUsedRegs(FILE *);
@@ -175,12 +176,14 @@ pic16emitRegularMap (memmap * map, bool addPublics, bool arFlag)
                  
                        checkAddSym(&publics, sym);
                } else
+                        /* new version */
                        if(IS_STATIC(sym->etype)
-                               && !(sym->ival && !sym->level)
-                       ) {
+                               && !sym->ival) /* && !sym->level*/ {
                          regs *reg;
                           sectSym *ssym;
                           int found=0;
+
+//                            debugf("adding symbol %s\n", sym->name);
 #define SET_IMPLICIT   1
 
 #if SET_IMPLICIT
@@ -191,15 +194,17 @@ pic16emitRegularMap (memmap * map, bool addPublics, bool arFlag)
                                reg = pic16_allocDirReg( operandFromSymbol( sym ));
                                
                                if(reg) {
-#if 1
                                   for(ssym=setFirstItem(sectSyms); ssym; ssym=setNextItem(sectSyms)) {
                                    if(!strcmp(ssym->name, reg->name))found=1;
                                   }
-#endif
+
                                   if(!found)
                                     checkAddReg(&pic16_rel_udata, reg);
+#if 0
                                   else
-                                   checkAddSym(&publics, sym);
+                                    debugf("Did find %s in pic16_rel_udata already. Check!\n", reg->name);
+//                                 checkAddSym(&publics, sym);
+#endif
 
                                 }
                        }
@@ -214,28 +219,9 @@ pic16emitRegularMap (memmap * map, bool addPublics, bool arFlag)
                        continue;
                }
 
-#if 0
-               /* print extra debug info if required */
-               if (options.debug || sym->level == 0) {
-                       cdbWriteSymbol (sym);   //, cdbFile, FALSE, FALSE);
-
-                       if (!sym->level)        /* global */
-                               if (IS_STATIC (sym->etype))
-                                       fprintf (map->oFile, "F%s_", moduleName);               /* scope is file */
-                               else
-                                       fprintf (map->oFile, "G_");     /* scope is global */
-                       else
-                               /* symbol is local */
-                               fprintf (map->oFile, "L%s_", (sym->localof ? sym->localof->name : "-null-"));
-                       fprintf (map->oFile, "%s_%d_%d", sym->name, sym->level, sym->block);
-               }
-#endif
-
-
                /* if is has an absolute address then generate
                an equate for this no need to allocate space */
                if (SPEC_ABSA (sym->etype)) {
-//                     if (options.debug || sym->level == 0)
 //                             fprintf (stderr,"; %s == 0x%04x\t\treqv= %p nRegs= %d\n",
 //                                     sym->name, SPEC_ADDR (sym->etype), sym->reqv, sym->regType);
 
@@ -343,7 +329,9 @@ pic16emitRegularMap (memmap * map, bool addPublics, bool arFlag)
                /* if it has an initial value then do it only if
                        it is a global variable */
 
-               if (sym->ival && sym->level == 0) {
+               if (sym->ival
+                 && ((sym->level == 0)
+                     || IS_STATIC(sym->etype)) ) {
                  ast *ival = NULL;
 
 #if 0
@@ -1460,6 +1448,8 @@ pic16printPublics (FILE *afile)
        fprintf (afile, "%s", iComments2);
 
        for(sym = setFirstItem (publics); sym; sym = setNextItem (publics))
+         /* sanity check */
+         if(!IS_STATIC(sym->etype))
                fprintf(afile, "\tglobal %s\n", sym->rname);
 }
 
@@ -1545,27 +1535,6 @@ pic16emitOverlay (FILE * afile)
          if (IS_FUNC (sym->type))
            continue;
 
-#if 0
-         /* print extra debug info if required */
-         if (options.debug || sym->level == 0)
-           {
-
-             cdbSymbol (sym, cdbFile, FALSE, FALSE);
-
-             if (!sym->level)
-               {               /* global */
-                 if (IS_STATIC (sym->etype))
-                   fprintf (afile, "F%s_", moduleName);        /* scope is file */
-                 else
-                   fprintf (afile, "G_");      /* scope is global */
-               }
-             else
-               /* symbol is local */
-               fprintf (afile, "L%s_",
-                        (sym->localof ? sym->localof->name : "-null-"));
-             fprintf (afile, "%s_%d_%d", sym->name, sym->level, sym->block);
-           }
-#endif
 
          /* if is has an absolute address then generate
             an equate for this no need to allocate space */
@@ -1595,15 +1564,18 @@ pic16emitOverlay (FILE * afile)
 
 void emitStatistics(FILE *asmFile)
 {
+  unsigned long isize, udsize;
   statistics.isize = pic16_countInstructions();
+  isize = (statistics.isize >= 0) ? statistics.isize : 0;
+  udsize = (statistics.udsize >= 0) ? statistics.udsize : 0;
        
   fprintf (asmFile, "\n\n; Statistics:\n");
-  fprintf (asmFile, "; code size:\t%ld (0x%lx) bytes\n;\t\t%ld (0x%lx) words\n",
-    statistics.isize, statistics.isize,
-    statistics.isize>>1, statistics.isize>>1);
-  fprintf (asmFile, "; udata size:\t%ld (0x%lx) bytes\n", 
-    statistics.udsize, statistics.udsize);
-  fprintf (asmFile, "; access size:\t%ld (0x%lx) bytes\n",
+  fprintf (asmFile, "; code size:\t%5ld (0x%04lx) bytes (%3.2f%%)\n;           \t%5ld (0x%04lx) words\n",
+    isize, isize, (isize*100.0)/(128 << 10),
+    isize>>1, isize>>1);
+  fprintf (asmFile, "; udata size:\t%5ld (0x%04lx) bytes (%3.2f%%)\n",
+    udsize, udsize, (udsize*100.0) / ((pic16 ? pic16->RAMsize : 0x200) -256));
+  fprintf (asmFile, "; access size:\t%5ld (0x%04lx) bytes\n",
     statistics.intsize, statistics.intsize);
 
   fprintf (asmFile, "\n\n");
@@ -1735,6 +1707,11 @@ pic16glue ()
       pic16_OptimizeLocalRegs();
     }
 
+    /* remove redundant BANKSELs -- added by RN 2005-01-17 */
+    if(pic16_options.opt_banksel > 1) {
+      pic16_OptimizeBanksel();
+    }
+           
     /* turn GOTOs into BRAs -- added by RN 2004-11-16 */
     if(pic16_options.opt_flags & OF_OPTIMIZE_GOTO) {
       pic16_OptimizeJumps();