An sfr/sbit can have an "at #" AND an initializer
[fw/sdcc] / src / SDCCmem.c
index c98b2bd0f9ab538305821005d907fb901e95be15..40d422b12d38b430da755a18f82340f36930d57b 100644 (file)
@@ -303,10 +303,13 @@ allocGlobal (symbol * sym)
 
   /* symbol name is internal name  */
   if (!sym->level)             /* local statics can come here */
-    sprintf (sym->rname, "%s%s", port->fun_prefix, sym->name);
+    SNPRINTF (sym->rname, sizeof(sym->rname), 
+             "%s%s", port->fun_prefix, sym->name);
 
   /* add it to the operandKey reset */
-  addSet (&operKeyReset, sym);
+  if (!isinSet (operKeyReset, sym)) {
+    addSet(&operKeyReset, sym);
+  }
 
   /* if this is a literal e.g. enumerated type */
   /* put it in the data segment & do nothing   */
@@ -322,7 +325,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)])
@@ -348,14 +351,6 @@ allocGlobal (symbol * sym)
       SPEC_SCLS (sym->etype) == S_SBIT)
     {
 
-      /* if both absolute address & initial  */
-      /* value specified then error        */
-      if (IS_ABSOLUTE (sym->etype) && sym->ival)
-       {
-         werror (E_SFR_INIT, sym->name);
-         sym->ival = NULL;
-       }
-
       SPEC_OCLS (sym->etype) =
        (SPEC_SCLS (sym->etype) == S_SFR ? sfr : sfrbit);
 
@@ -518,8 +513,9 @@ allocParms (value * val)
       else
        { /* allocate them in the automatic space */
          /* generate a unique name  */
-         sprintf (lval->sym->rname, "%s%s_PARM_%d", port->fun_prefix, currFunc->name, pNum);
-         strcpy (lval->name, lval->sym->rname);
+         SNPRINTF (lval->sym->rname, sizeof(lval->sym->rname),
+                   "%s%s_PARM_%d", port->fun_prefix, currFunc->name, pNum);
+         strncpyz (lval->name, lval->sym->rname, sizeof(lval->name));
          
          /* if declared in external storage */
          if (SPEC_SCLS (lval->etype) == S_XDATA)
@@ -576,14 +572,17 @@ deallocParms (value * val)
       if (lval->sym->rname[0])
        {
          char buffer[SDCC_NAME_MAX];
-         strcpy (buffer, lval->sym->rname);
+         strncpyz (buffer, lval->sym->rname, sizeof(buffer));
          lval->sym = copySymbol (lval->sym);
-         strcpy (lval->sym->rname, buffer);
-         strcpy (lval->name, strcpy (lval->sym->name, lval->sym->rname));
+         strncpyz (lval->sym->rname, buffer, sizeof(lval->sym->rname));
+         strncpyz (lval->sym->name, buffer, sizeof(lval->sym->name));
+         strncpyz (lval->name, buffer, sizeof(lval->name)); 
          addSym (SymbolTab, lval->sym, lval->sym->name,
                  lval->sym->level, lval->sym->block, 1);
          lval->sym->_isparm = 1;
-         addSet (&operKeyReset, lval->sym);
+         if (!isinSet (operKeyReset, lval->sym)) {
+           addSet(&operKeyReset, lval->sym);
+         }
        }
 
     }
@@ -599,9 +598,10 @@ allocLocal (symbol * sym)
 {
 
   /* generate an unique name */
-  sprintf (sym->rname, "%s%s_%s_%d_%d",
-          port->fun_prefix,
-          currFunc->name, sym->name, sym->level, sym->block);
+  SNPRINTF (sym->rname, sizeof(sym->rname), 
+           "%s%s_%s_%d_%d",
+           port->fun_prefix,
+           currFunc->name, sym->name, sym->level, sym->block);
 
   sym->islocal = 1;
   sym->localof = currFunc;
@@ -675,15 +675,6 @@ allocLocal (symbol * sym)
   if (SPEC_SCLS (sym->etype) == S_SFR ||
       SPEC_SCLS (sym->etype) == S_SBIT)
     {
-
-      /* if both absolute address & initial  */
-      /* value specified then error        */
-      if (IS_ABSOLUTE (sym->etype) && sym->ival)
-       {
-         werror (E_SFR_INIT, sym->name);
-         sym->ival = NULL;
-       }
-
       SPEC_OCLS (sym->etype) =
        (SPEC_SCLS (sym->etype) == S_SFR ? sfr : sfrbit);
 
@@ -838,12 +829,13 @@ allocVariables (symbol * symChain)
       /* then args  processing  */
       if (funcInChain (csym->type))
        {
-#if 1 // jwk: TODO should have been done already in addDecl() (oclass????)
          processFuncArgs (csym);
-#endif
+
          /* 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 */
@@ -1009,6 +1001,7 @@ printAllocInfoSeg (memmap * map, symbol * func, FILE * of)
       if (!sym->allocreq && sym->reqv)
        {
          int i;
+
          sym = OP_SYMBOL (sym->reqv);
          fprintf (of, "registers ");
          for (i = 0; i < 4 && sym->regs[i]; i++)