some small fixes
[fw/sdcc] / src / SDCCmem.c
index 7e6c60b7349601954f95e6d2e08b3501a2fe88b5..f369a04fda8efd3580aff192be37d82f3efbe3e3 100644 (file)
@@ -264,14 +264,22 @@ void
 allocIntoSeg (symbol * sym)
 {
   memmap *segment = SPEC_OCLS (sym->etype);
-  // should we move this to the initialized data segment?
-  if (port->genXINIT && segment==xdata &&
-      sym->ival && sym->level==0 && !SPEC_ABSA(sym->etype)) {
-    segment=SPEC_OCLS(sym->etype)=xidata;
-  }
   addSet (&segment->syms, sym);
 }
 
+/*-----------------------------------------------------------------*/
+/* deleteFromSeg - deletes a symbol from segment used when a var   */
+/*                firest declared as "extern" then no extern      */
+/*-----------------------------------------------------------------*/
+void deleteFromSeg(symbol *sym)
+{
+    if (SPEC_OCLS(sym->etype)) {
+       memmap *segment = SPEC_OCLS (sym->etype);       
+       deleteSetItem(&segment->syms,sym);
+    }
+}
+
+
 /*-----------------------------------------------------------------*/
 /* allocGlobal - assigns the output segment to a global var       */
 /*-----------------------------------------------------------------*/
@@ -373,16 +381,19 @@ allocGlobal (symbol * sym)
     }
 
   /* if it is fixed, then allocate depending on the  */
-  /* current memory model,same for automatics        */
+  /* current memory model, same for automatics        */
   if (SPEC_SCLS (sym->etype) == S_FIXED ||
-      SPEC_SCLS (sym->etype) == S_AUTO)
-    {
+      SPEC_SCLS (sym->etype) == S_AUTO) {
+    if (port->mem.default_globl_map != xdata) {
       /* set the output class */
       SPEC_OCLS (sym->etype) = port->mem.default_globl_map;
       /* generate the symbol  */
       allocIntoSeg (sym);
       return;
+    } else {
+      SPEC_SCLS (sym->etype) = S_XDATA;
     }
+  }
 
   /* if code change to constant */
   if (SPEC_SCLS (sym->etype) == S_CODE) {
@@ -394,6 +405,12 @@ allocGlobal (symbol * sym)
   if (SPEC_SCLS (sym->etype) == S_XDATA)
     {
       SPEC_OCLS (sym->etype) = xdata;
+      // should we move this to the initialized data segment?
+      if (port->genXINIT &&
+         sym->ival && (sym->level==0) && !SPEC_ABSA(sym->etype)) {
+       SPEC_OCLS(sym->etype)=xidata;
+       addSet(&xidata->syms, sym);
+      }
       allocIntoSeg (sym);
       return;
     }
@@ -1018,6 +1035,9 @@ canOverlayLocals (eBBlock ** ebbs, int count)
 
     return FALSE;
 
+  /* if this is a forces overlay */
+  if (IFFUNC_ISOVERLAY(currFunc->type)) return TRUE;
+
   /* otherwise do thru the blocks and see if there
      any function calls if found then return false */
   for (i = 0; i < count; i++)