2004-11-04 Vangelis Rokas <vrokas AT otenet.gr>
[fw/sdcc] / src / pic16 / device.c
index 3f730a81984b03e050341fed666b7006040e5672..9420f969fc3feb439416df66f214cc1062c7e57e 100644 (file)
@@ -461,6 +461,8 @@ static PIC16_device Pics16[] = {
 
 static int num_of_supported_PICS = sizeof(Pics16)/sizeof(PIC16_device);
 
+stats_t statistics = { 0, 0, 0, 0 };
+
 #define DEFAULT_PIC "452"
 
 PIC16_device *pic16=NULL;
@@ -514,6 +516,7 @@ void pic16_dump_access(FILE *of, set *section)
        fprintf(of, "\tudata_acs\n");
        for(; r; r = setNextItem(section)) {
                fprintf(of, "%s\tres\t%d\n", r->name, r->size);
+               statistics.adsize += r->size;
        }
 }
 
@@ -562,7 +565,7 @@ void pic16_dump_usection(FILE *of, set *section, int fix)
 {
   static int abs_usection_no=0;
   regs *r, *rprev;
-  int init_addr, i;
+  unsigned int init_addr, i;
   regs **rlist;
   regs *r1;
 
@@ -582,12 +585,23 @@ void pic16_dump_usection(FILE *of, set *section, int fix)
        qsort(rlist, i  /*elementsInSet(section)*/, sizeof(regs *), regCompare);
        
        if(!fix) {
+
+#define EMIT_SINGLE_UDATA_SECTION      0
+#if EMIT_SINGLE_UDATA_SECTION
                fprintf(of, "\n\n\tudata\n");
                for(r = setFirstItem(section); r; r = setNextItem(section)) {
                        fprintf(of, "%s\tres\t%d\n", r->name, r->size);
+                       statistics.udsize += r->size;
+               }
+#else
+               for(r = setFirstItem(section); r; r = setNextItem(section)) {
+                       fprintf(of, "\nudata_%s_%s\tudata\n", moduleName, r->name);
+                       fprintf(of, "%s\tres\t%d\n", r->name, r->size);
+                       statistics.udsize += r->size;
                }
+#endif
        } else {
-         int j=0;
+         unsigned int j=0;
          int deb_addr=0;
 
                rprev = NULL;
@@ -611,6 +625,7 @@ void pic16_dump_usection(FILE *of, set *section, int fix)
                        } else {
                                fprintf(of, "%s\tres\t%d\n", r->name, r->size);
                                deb_addr += r->size;
+                               statistics.udsize += r->size;
                        }
                        
                        rprev = r;
@@ -625,6 +640,7 @@ void pic16_dump_gsection(FILE *of, set *sections)
   sectName *sname;
 
        for(sname = setFirstItem(sections); sname; sname = setNextItem(sections)) {
+               if(!strcmp(sname->name, "access"))continue;
                fprintf(of, "\n\n%s\tudata\n", sname->name);
 
                for(r=setFirstItem(sname->regsSet); r; r=setNextItem(sname->regsSet)) {
@@ -633,6 +649,7 @@ void pic16_dump_gsection(FILE *of, set *sections)
                                r->name, sname->name, sname);
 #endif
                        fprintf(of, "%s\tres\t%d\n", r->name, r->size);
+                       statistics.udsize += r->size;
                }
        }
 }
@@ -646,7 +663,7 @@ void pic16_dump_isection(FILE *of, set *section, int fix)
 {
   static int abs_isection_no=0;
   symbol *s, *sprev;
-  int init_addr, i;
+  unsigned int init_addr, i;
   symbol **slist;
 
        /* put all symbols in an array */
@@ -687,7 +704,7 @@ void pic16_dump_isection(FILE *of, set *section, int fix)
                                
                }
        } else {
-         int j=0;
+         unsigned int j=0;
          symbol *s1;
          
                sprev = NULL;
@@ -751,8 +768,10 @@ void pic16_dump_int_registers(FILE *of, set *section)
        fprintf(of, "\n\n; Internal registers\n");
        
        fprintf(of, "%s\tudata_ovr\t0x0000\n", ".registers");
-       for(r = setFirstItem(section); r; r = setNextItem(section))
+       for(r = setFirstItem(section); r; r = setNextItem(section)) {
                fprintf(of, "%s\tres\t%d\n", r->name, r->size);
+               statistics.intsize += r->size;
+       }
 
        free(rlist);
 }
@@ -1020,8 +1039,15 @@ void pic16_groupRegistersInSection(set *regset)
                                if(!strcmp(ssym->name, reg->name)) {
 //                                     fprintf(stderr, "%s:%d section found %s (%p) with var %s\n",
 //                                                     __FILE__, __LINE__, ssym->section->name, ssym->section, ssym->name);
-                                       addSet(&ssym->section->regsSet, reg);
-                                       docontinue=1;
+                                       if(strcmp(ssym->section->name, "access")) {
+                                               addSet(&ssym->section->regsSet, reg);
+                                               docontinue=1;
+                                               break;
+                                       } else {
+                                               docontinue=0;
+                                               reg->accessBank = 1;
+                                               break;
+                                       }
                                }
                        }
 
@@ -1040,7 +1066,8 @@ void pic16_groupRegistersInSection(set *regset)
                                        checkAddReg(&pic16_int_regs, reg);
                                else {
                                        if(reg->accessBank) {
-                                               checkAddReg(&pic16_acs_udata, reg);
+                                               if(reg->alias != 0x40)
+                                                       checkAddReg(&pic16_acs_udata, reg);
                                        } else
                                                checkAddReg(&pic16_rel_udata, reg);
                                }