Fixed weird characters due to extra %s
[fw/sdcc] / src / SDCCmem.c
index e284d32dfa8c5aaded0c11b1258cd0c42f2c21e0..a134a4d9b9095898e79f55a602a01a214aa0f942 100644 (file)
@@ -18,6 +18,7 @@ memmap  *reg   = NULL;   /* register space              */
 memmap  *sfrbit= NULL;   /* sfr bit space               */
 memmap  *generic=NULL;   /* is a generic pointer        */
 memmap  *overlay=NULL;   /* overlay segment             */
+memmap  *eeprom =NULL;   /* eeprom location             */
 
 /* this is a set of sets each set containing
    symbols in a single overlay */
@@ -30,7 +31,7 @@ int maxRegBank = 0;
 int fatalError = 0                      ;/* fatal error flag                   */
 
 /*-----------------------------------------------------------------*/
-/* allocMap - allocates a memory map                                                      */
+/* allocMap - allocates a memory map                              */
 /*-----------------------------------------------------------------*/
 memmap *allocMap (char rspace,     /* sfr space            */
                   char farmap,     /* far or near segment  */
@@ -40,7 +41,8 @@ memmap *allocMap (char rspace,     /* sfr space            */
                  char codemap,    /* this is code space   */
                  unsigned sloc,   /* starting location    */
                  const char *name,      /* 2 character name     */
-                 char dbName     
+                 char dbName    , /* debug name                 */
+                 int  ptrType     /* pointer type for this space */
                  )
 {
        memmap *map ;
@@ -60,7 +62,8 @@ memmap *allocMap (char rspace,     /* sfr space            */
        map->sloc   =  sloc ;
        map->sname = name ;
        map->dbName = dbName ;
-       if (!(map->oFile = tmpfile())) {
+       map->ptrType= ptrType;
+       if (!(map->oFile = tempfile())) {
                werror(E_TMPFILE_FAILED);
                exit (1);
        } 
@@ -74,7 +77,6 @@ memmap *allocMap (char rspace,     /* sfr space            */
 /*-----------------------------------------------------------------*/
 void initMem ()
 {      
-       
        /* allocate all the segments */
        /* xternal stack segment ;   
                   SFRSPACE       -   NO
@@ -82,8 +84,11 @@ void initMem ()
                   PAGED          -   YES
                   DIRECT-ACCESS  -   NO
                   BIT-ACCESS     -   NO
-                  CODE-ACESS     -   NO */
-       xstack    = allocMap (0, 1, 1, 0, 0, 0, options.xstack_loc, XSTACK_NAME,'A');
+                  CODE-ACESS     -   NO 
+                  DEBUG-NAME     -   'A'
+                  POINTER-TYPE   -   FPOINTER
+       */
+       xstack    = allocMap (0, 1, 1, 0, 0, 0, options.xstack_loc, XSTACK_NAME,'A',PPOINTER);
 
        /* internal stack segment ;   
                   SFRSPACE       -   NO
@@ -91,8 +96,11 @@ void initMem ()
                   PAGED          -   NO
                   DIRECT-ACCESS  -   NO
                   BIT-ACCESS     -   NO
-                  CODE-ACESS     -   NO */
-       istack    = allocMap (0, 0, 0, 0, 0, 0,options.stack_loc, ISTACK_NAME,'B');
+                  CODE-ACESS     -   NO 
+                  DEBUG-NAME     -   'B'
+                  POINTER-TYPE   -   POINTER
+       */
+       istack    = allocMap (0, 0, 0, 0, 0, 0,options.stack_loc, ISTACK_NAME,'B',POINTER);
 
        /* code  segment ;   
                   SFRSPACE       -   NO
@@ -100,8 +108,11 @@ void initMem ()
                   PAGED          -   NO
                   DIRECT-ACCESS  -   NO
                   BIT-ACCESS     -   NO
-                  CODE-ACESS     -   YES */
-       code      = allocMap (0, 1, 0, 0, 0, 1, options.code_loc, CODE_NAME,'C');
+                  CODE-ACESS     -   YES 
+                  DEBUG-NAME     -   'C'
+                  POINTER-TYPE   -   CPOINTER
+       */
+       code      = allocMap (0, 1, 0, 0, 0, 1, options.code_loc, CODE_NAME,'C',CPOINTER);
 
        /* Static segment (code for variables );
                   SFRSPACE       -   NO
@@ -109,8 +120,11 @@ void initMem ()
                   PAGED          -   NO
                   DIRECT-ACCESS  -   NO
                   BIT-ACCESS     -   NO
-                  CODE-ACESS     -   YES */
-       statsg    = allocMap (0, 1, 0, 0, 0, 1,0, STATIC_NAME,'D');
+                  CODE-ACESS     -   YES 
+                  DEBUG-NAME     -   'D'
+                  POINTER-TYPE   -   CPOINTER
+       */
+       statsg    = allocMap (0, 1, 0, 0, 0, 1,0, STATIC_NAME,'D',CPOINTER);
 
        /* Data segment - internal storage segment ;
                   SFRSPACE       -   NO
@@ -118,8 +132,11 @@ void initMem ()
                   PAGED          -   NO
                   DIRECT-ACCESS  -   YES
                   BIT-ACCESS     -   NO
-                  CODE-ACESS     -   NO */     
-       data      = allocMap (0, 0, 0, 1, 0, 0, options.data_loc, DATA_NAME,'E');
+                  CODE-ACESS     -   NO 
+                  DEBUG-NAME     -   'E'
+                  POINTER-TYPE   -   POINTER
+       */      
+       data      = allocMap (0, 0, 0, 1, 0, 0, options.data_loc, DATA_NAME,'E',POINTER);
 
        /* overlay segment - same as internal storage segment ;
                   SFRSPACE       -   NO
@@ -127,8 +144,11 @@ void initMem ()
                   PAGED          -   NO
                   DIRECT-ACCESS  -   YES
                   BIT-ACCESS     -   NO
-                  CODE-ACESS     -   NO */     
-       overlay   = allocMap (0, 0, 0, 1, 0, 0, options.data_loc, DATA_NAME,'E');
+                  CODE-ACESS     -   NO 
+                  DEBUG-NAME     -   'E'
+                  POINTER-TYPE   -   POINTER
+       */
+       overlay   = allocMap (0, 0, 0, 1, 0, 0, options.data_loc, DATA_NAME,'E',POINTER);
 
        /* Xternal Data segment - 
                   SFRSPACE       -   NO
@@ -136,8 +156,11 @@ void initMem ()
                   PAGED          -   NO
                   DIRECT-ACCESS  -   NO
                   BIT-ACCESS     -   NO
-                  CODE-ACESS     -   NO */
-       xdata     = allocMap (0, 1, 0, 0, 0, 0, options.xdata_loc, XDATA_NAME,'F' );
+                  CODE-ACESS     -   NO 
+                  DEBUG-NAME     -   'F'
+                  POINTER-TYPE   -   FPOINTER
+       */
+       xdata     = allocMap (0, 1, 0, 0, 0, 0, options.xdata_loc, XDATA_NAME,'F',FPOINTER);
 
        /* Inderectly addressed internal data segment
                   SFRSPACE       -   NO
@@ -145,8 +168,11 @@ void initMem ()
                   PAGED          -   NO
                   DIRECT-ACCESS  -   NO
                   BIT-ACCESS     -   NO
-                  CODE-ACESS     -   NO */
-       idata     = allocMap (0, 0, 0, 0, 0, 0, options.idata_loc,IDATA_NAME,'G' );
+                  CODE-ACESS     -   NO 
+                  DEBUG-NAME     -   'G'
+                  POINTER-TYPE   -   IPOINTER
+       */
+       idata     = allocMap (0, 0, 0, 0, 0, 0, options.idata_loc,IDATA_NAME,'G',IPOINTER);
 
        /* Static segment (code for variables );
                   SFRSPACE       -   NO
@@ -154,8 +180,11 @@ void initMem ()
                   PAGED          -   NO
                   DIRECT-ACCESS  -   YES
                   BIT-ACCESS     -   YES
-                  CODE-ACESS     -   NO */
-       bit       = allocMap (0, 0, 0, 1, 1, 0,0, BIT_NAME,'H');
+                  CODE-ACESS     -   NO 
+                  DEBUG-NAME     -   'H'
+                  POINTER-TYPE   -  _NONE_
+       */
+       bit       = allocMap (0, 0, 0, 1, 1, 0,0, BIT_NAME,'H',0);
        
        /* Special function register space :-
                   SFRSPACE       -   YES
@@ -163,8 +192,11 @@ void initMem ()
                   PAGED          -   NO
                   DIRECT-ACCESS  -   YES
                   BIT-ACCESS     -   NO
-                  CODE-ACESS     -   NO */
-       sfr        = allocMap (1,0, 0, 1, 0, 0,0, REG_NAME,'I');
+                  CODE-ACESS     -   NO 
+                  DEBUG-NAME     -   'I'
+                  POINTER-TYPE   -   _NONE_
+       */
+       sfr        = allocMap (1,0, 0, 1, 0, 0,0, REG_NAME,'I',0);
 
        /* Register space ;
                   SFRSPACE       -   YES
@@ -172,8 +204,11 @@ void initMem ()
                   PAGED          -   NO
                   DIRECT-ACCESS  -   NO
                   BIT-ACCESS     -   NO
-                  CODE-ACESS     -   NO */
-       reg        = allocMap (1,0, 0, 0, 0, 0, 0,REG_NAME,' ');
+                  CODE-ACESS     -   NO 
+                  DEBUG-NAME     -   ' '
+                  POINTER-TYPE   -   _NONE_
+       */
+       reg        = allocMap (1,0, 0, 0, 0, 0, 0,REG_NAME,' ',0);
 
        /* SFR bit space 
                   SFRSPACE       -   YES
@@ -181,12 +216,27 @@ void initMem ()
                   PAGED          -   NO
                   DIRECT-ACCESS  -   YES
                   BIT-ACCESS     -   YES
-                  CODE-ACESS     -   NO */
-       sfrbit     = allocMap (1,0, 0, 1, 1, 0,0, REG_NAME,'J' );
+                  CODE-ACESS     -   NO 
+                  DEBUG-NAME     -   'J'
+                  POINTER-TYPE   -   _NONE_
+       */
+       sfrbit     = allocMap (1,0, 0, 1, 1, 0,0, REG_NAME,'J',0);
 
-       /* the unknown map */
-       generic     = allocMap (1,0, 0, 1, 1, 0,0, REG_NAME,' ' );
+       /* EEPROM bit space 
+                  SFRSPACE       -   NO
+                  FAR-SPACE      -   YES
+                  PAGED          -   NO
+                  DIRECT-ACCESS  -   NO
+                  BIT-ACCESS     -   NO
+                  CODE-ACESS     -   NO 
+                  DEBUG-NAME     -   'K'
+                  POINTER-TYPE   -   EEPPOINTER
+       */
+       eeprom     = allocMap (0,1, 0, 0, 0, 0,0, REG_NAME,'K',EEPPOINTER);
 
+       /* the unknown map */
+       generic     = allocMap (1,0, 0, 1, 1, 0,0, REG_NAME,' ',GPOINTER);
+       
 }
 
 /*-----------------------------------------------------------------*/
@@ -195,7 +245,6 @@ void initMem ()
 void allocIntoSeg (symbol *sym) 
 {
     memmap *segment = SPEC_OCLS(sym->etype);
-
     addSet (&segment->syms,sym);
 }
 
@@ -205,7 +254,7 @@ void allocIntoSeg (symbol *sym)
 void allocGlobal ( symbol *sym )
 {
     /* symbol name is internal name  */
-    sprintf (sym->rname,"_%s",sym->name);
+    sprintf (sym->rname,"%s%s", port->fun_prefix, sym->name);
     
     /* add it to the operandKey reset */
     addSet(&operKeyReset,sym);
@@ -293,7 +342,7 @@ void allocGlobal ( symbol *sym )
     if ( SPEC_SCLS(sym->etype) == S_FIXED  ||
         SPEC_SCLS(sym->etype) == S_AUTO   ) {
        /* set the output class */
-       SPEC_OCLS(sym->etype) = ( options.model  ? xdata : data ) ;
+       SPEC_OCLS(sym->etype) = port->mem.default_globl_map ;
        /* generate the symbol  */
        allocIntoSeg  (sym) ;
        return   ;
@@ -319,6 +368,12 @@ void allocGlobal ( symbol *sym )
        allocIntoSeg (sym)  ;
        return ;
     }
+
+    if ( SPEC_SCLS(sym->etype) == S_EEPROM  )    {
+       SPEC_OCLS(sym->etype) = eeprom ;
+       allocIntoSeg (sym)  ;
+       return ;
+    }
     
     return ;
 }
@@ -333,21 +388,15 @@ void allocParms ( value  *val )
 
     for ( lval = val ; lval ; lval = lval->next, pNum++ ) {
 
-       /* if this is a literal e.g. enumerated type */
-       if (IS_LITERAL(lval->etype)) {
-           SPEC_OCLS(lval->etype) = SPEC_OCLS(lval->sym->etype) = 
-               ( options.model  ? xdata : data );
-           continue;
-       }
+       /* check the declaration */
+       checkDecl (lval->sym);
+       
        /* if this a register parm then allocate
           it as a local variable by adding it
           to the first block we see in the body */
        if (IS_REGPARM(lval->etype)) 
            continue ;
 
-       /* check the declaration */
-       checkDecl (lval->sym);
-       
        /* mark it as my parameter */
        lval->sym->ismyparm = 1;
        lval->sym->localof = currFunc;
@@ -388,7 +437,7 @@ void allocParms ( value  *val )
        }
        else   {        /* allocate them in the automatic space */
            /* generate a unique name  */
-           sprintf (lval->sym->rname,"_%s_PARM_%d",currFunc->name,pNum);
+           sprintf (lval->sym->rname,"%s%s_PARM_%d", port->fun_prefix, currFunc->name,pNum);
            strcpy  (lval->name,lval->sym->rname);
            
            /* if declared in external storage */
@@ -400,7 +449,9 @@ void allocParms ( value  *val )
                   first, we will remove it from the overlay segment
                   after the overlay determination has been done */
                SPEC_OCLS(lval->etype) = SPEC_OCLS(lval->sym->etype) = 
-                   ( options.model  ? xdata : (options.noOverlay ? data :overlay ));
+                   ( options.model  ? port->mem.default_local_map : 
+                     (options.noOverlay ? port->mem.default_local_map
+                      :overlay ));
            
            allocIntoSeg(lval->sym);
        }
@@ -457,7 +508,8 @@ void allocLocal ( symbol *sym  )
 {   
     
     /* generate an unique name */
-    sprintf(sym->rname,"_%s_%s_%d_%d",
+    sprintf(sym->rname,"%s%s_%s_%d_%d",
+           port->fun_prefix,
            currFunc->name,sym->name,sym->level,sym->block);
     
     sym->islocal = 1;
@@ -465,7 +517,8 @@ void allocLocal ( symbol *sym  )
 
     /* if this is a static variable */
     if ( IS_STATIC (sym->etype)) {
-       SPEC_OCLS(sym->etype) = (options.model ? xdata : data );
+/*     SPEC_OCLS(sym->etype) = (options.model ? xdata : data ); */
+       SPEC_OCLS(sym->etype) = port->mem.default_local_map;
        allocIntoSeg (sym);
         sym->allocreq = 1;
        return   ;
@@ -556,11 +609,24 @@ void allocLocal ( symbol *sym  )
        return  ;
     }
 
+    if ( SPEC_SCLS(sym->etype) == S_DATA  ) {
+       SPEC_OCLS(sym->etype) = (options.noOverlay ? data : overlay );
+       allocIntoSeg(sym)  ;
+       return ;
+    }
+
+    if ( SPEC_SCLS(sym->etype) == S_EEPROM  ) {
+       SPEC_OCLS(sym->etype) = eeprom;
+       allocIntoSeg(sym)  ;
+       return ;
+    }
+    
     /* again note that we have put it into the overlay segment
        will remove and put into the 'data' segment if required after 
        overlay  analysis has been done */   
-    SPEC_OCLS(sym->etype) = ( options.model  ? xdata : 
-                             (options.noOverlay ? data : overlay )) ;
+    SPEC_OCLS(sym->etype) = ( options.model  ? port->mem.default_local_map : 
+                             (options.noOverlay ? port->mem.default_local_map
+                              : overlay )) ;
     allocIntoSeg (sym); 
 }