* sim/ucsim/mkecho: inserted #!/bin/sh for Cygwin, so that it's executable
[fw/sdcc] / src / SDCCmem.c
index 7e6c60b7349601954f95e6d2e08b3501a2fe88b5..0c05b2322e73f2dc728af5c66d714b162ecd27ef 100644 (file)
@@ -104,7 +104,12 @@ initMem ()
      DEBUG-NAME     -   'B'
      POINTER-TYPE   -   POINTER
    */
-  istack = allocMap (0, 0, 0, 0, 0, 0, options.stack_loc, ISTACK_NAME, 'B', POINTER);
+  if (ISTACK_NAME) {
+    istack = allocMap (0, 0, 0, 0, 0, 0, options.stack_loc, 
+                      ISTACK_NAME, 'B', POINTER);
+  } else {
+    istack=NULL;
+  }
 
   /* code  segment ;   
      SFRSPACE       -   NO
@@ -164,7 +169,11 @@ initMem ()
      DEBUG-NAME     -   'E'
      POINTER-TYPE   -   POINTER
    */
-  overlay = allocMap (0, 0, 0, 1, 0, 0, options.data_loc, DATA_NAME, 'E', POINTER);
+  if (OVERLAY_NAME) {
+    overlay = allocMap (0, 0, 0, 1, 0, 0, options.data_loc, DATA_NAME, 'E', POINTER);
+  } else {
+    overlay = NULL;
+  }
 
   /* Xternal Data segment - 
      SFRSPACE       -   NO
@@ -190,7 +199,12 @@ initMem ()
      DEBUG-NAME     -   'G'
      POINTER-TYPE   -   IPOINTER
    */
-  idata = allocMap (0, 0, 0, 0, 0, 0, options.idata_loc, IDATA_NAME, 'G', IPOINTER);
+  if (IDATA_NAME) {
+    idata = allocMap (0, 0, 0, 0, 0, 0, options.idata_loc, 
+                     IDATA_NAME, 'G', IPOINTER);
+  } else {
+    idata=NULL;
+  }
 
   /* Static segment (code for variables );
      SFRSPACE       -   NO
@@ -264,14 +278,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       */
 /*-----------------------------------------------------------------*/
@@ -300,7 +322,7 @@ allocGlobal (symbol * sym)
       SPEC_OCLS (sym->etype) = code;
       /* if this is an interrupt service routine
          then put it in the interrupt service array */
-      if (FUNC_ISISR (sym->type))
+      if (FUNC_ISISR (sym->type) && !options.noiv)
        {
 
          if (interrupts[FUNC_INTNO (sym->type)])
@@ -373,16 +395,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) {
@@ -393,7 +418,13 @@ 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;
+      } else {
+       SPEC_OCLS (sym->etype) = xdata;
+      }
       allocIntoSeg (sym);
       return;
     }
@@ -529,14 +560,13 @@ deallocParms (value * val)
 
       /* unmark is myparm */
       lval->sym->ismyparm = 0;
-      /* if on stack then depending on which stack */
 
       /* delete it from the symbol table  */
       deleteSym (SymbolTab, lval->sym, lval->sym->name);
 
       if (!lval->sym->isref)
        {
-         lval->sym->allocreq = 1;
+         lval->sym->allocreq = 0;
          werror (W_NO_REFERENCE, currFunc->name,
                  "function argument", lval->sym->name);
        }
@@ -707,7 +737,7 @@ deallocLocal (symbol * csym)
 
   for (sym = csym; sym; sym = sym->next)
     {
-      if (sym->_isparm)
+      if (sym->_isparm) 
        continue;
 
       /* if it is on the stack */
@@ -814,6 +844,8 @@ allocVariables (symbol * symChain)
          /* if register bank specified then update maxRegBank */
          if (maxRegBank < FUNC_REGBANK (csym->type))
            maxRegBank = FUNC_REGBANK (csym->type);
+         /*JCF: Mark the register bank as used*/
+      RegBankUsed[FUNC_REGBANK(csym->type)]=1;
        }
 
       /* if this is a extern variable then change the */
@@ -1018,6 +1050,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++)
@@ -1044,6 +1079,10 @@ canOverlayLocals (eBBlock ** ebbs, int count)
 void 
 doOverlays (eBBlock ** ebbs, int count)
 {
+  if (!overlay) {
+    return;
+  }
+
   /* check if the parameters and local variables
      of this function can be put in the overlay segment
      This check is essentially to see if the function
@@ -1081,4 +1120,5 @@ printAllocInfo (symbol * func, FILE * of)
   printAllocInfoSeg (idata, func, of);
   printAllocInfoSeg (sfr, func, of);
   printAllocInfoSeg (sfrbit, func, of);
+  fprintf (of, ";------------------------------------------------------------\n");
 }