X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2FSDCCmem.c;h=b2a8c7b5dfca427c88d4b93cb97839ee1f3e7356;hb=3ac096b235fc76e2c6087708b2361fa21ee12b14;hp=29fcc84093ee7fb5892fd63f5271e9cfcad77669;hpb=9790d1ca81de1512cd77ec2840bb9ac513e0d991;p=fw%2Fsdcc diff --git a/src/SDCCmem.c b/src/SDCCmem.c index 29fcc840..b2a8c7b5 100644 --- a/src/SDCCmem.c +++ b/src/SDCCmem.c @@ -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 @@ -268,7 +282,20 @@ allocIntoSeg (symbol * sym) } /*-----------------------------------------------------------------*/ -/* allocGlobal - aassigns the output segment to a global var */ +/* 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 */ /*-----------------------------------------------------------------*/ void allocGlobal (symbol * sym) @@ -276,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 */ @@ -295,9 +325,9 @@ 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 + && (FUNC_INTNO (sym->type) != INTNO_UNSPEC)) { - if (interrupts[FUNC_INTNO (sym->type)]) werror (E_INT_DEFINED, FUNC_INTNO (sym->type), @@ -321,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); @@ -353,6 +375,7 @@ allocGlobal (symbol * sym) return; } + if(!TARGET_IS_PIC16 || (TARGET_IS_PIC16 && sym->level)) /* register storage class ignored changed to FIXED */ if (SPEC_SCLS (sym->etype) == S_REGISTER) SPEC_SCLS (sym->etype) = S_FIXED; @@ -368,16 +391,20 @@ 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) - { + (TARGET_IS_PIC16 && (SPEC_SCLS (sym->etype) == S_REGISTER) && (sym->level==0)) || + 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) { @@ -388,7 +415,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; } @@ -482,8 +515,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) @@ -524,16 +558,16 @@ 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; - werror (W_NO_REFERENCE, currFunc->name, - "function argument", lval->sym->name); + lval->sym->allocreq = 0; + werror (W_NO_REFERENCE, + currFunc ? currFunc->name : "(unknown)", + "function argument", lval->sym->name); } /* move the rname if any to the name for both val & sym */ @@ -541,14 +575,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); + } } } @@ -564,9 +601,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; @@ -640,15 +678,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); @@ -683,11 +712,11 @@ allocLocal (symbol * sym) will remove and put into the 'data' segment if required after overlay analysis has been done */ if (options.model == MODEL_SMALL) { - SPEC_OCLS (sym->etype) = - (options.noOverlay ? port->mem.default_local_map - : overlay); + SPEC_OCLS (sym->etype) = + (options.noOverlay ? port->mem.default_local_map + : overlay); } else { - SPEC_OCLS (sym->etype) = port->mem.default_local_map; + SPEC_OCLS (sym->etype) = port->mem.default_local_map; } allocIntoSeg (sym); } @@ -702,7 +731,7 @@ deallocLocal (symbol * csym) for (sym = csym; sym; sym = sym->next) { - if (sym->_isparm) + if (sym->_isparm) continue; /* if it is on the stack */ @@ -715,7 +744,8 @@ deallocLocal (symbol * csym) } /* if not used give a warning */ if (!sym->isref && !IS_STATIC (sym->etype)) - werror (W_NO_REFERENCE, currFunc->name, + werror (W_NO_REFERENCE, + currFunc ? currFunc->name : "(unknown)", "local variable", sym->name); /* now delete it from the symbol table */ deleteSym (SymbolTab, sym, sym->name); @@ -738,7 +768,7 @@ overlay2data () allocIntoSeg (sym); } - setToNull ((void **) &overlay->syms); + setToNull ((void *) &overlay->syms); } @@ -759,7 +789,7 @@ overlay2Set () addSet (&oset, sym); } - setToNull ((void **) &overlay->syms); + setToNull ((void *) &overlay->syms); addSet (&ovrSetSets, oset); } @@ -788,6 +818,7 @@ allocVariables (symbol * symChain) if (csym && csym->level == sym->level) werror (E_DUPLICATE_TYPEDEF, sym->name); + SPEC_EXTR (sym->etype) = 0; addSym (TypedefTab, sym, sym->name, sym->level, sym->block, 0); continue; /* go to the next one */ } @@ -803,12 +834,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 */ @@ -933,18 +965,6 @@ redoStackOffsets (void) xsPtr += size; } - /* if the debug option is set then output the - symbols to the map file */ - if (options.debug) - { - for (sym = setFirstItem (istack->syms); sym; - sym = setNextItem (istack->syms)) - cdbSymbol (sym, cdbFile, FALSE, FALSE); - - for (sym = setFirstItem (xstack->syms); sym; - sym = setNextItem (xstack->syms)) - cdbSymbol (sym, cdbFile, FALSE, FALSE); - } } /*-----------------------------------------------------------------*/ @@ -959,7 +979,7 @@ printAllocInfoSeg (memmap * map, symbol * func, FILE * of) return; if (!map->syms) return; - + for (sym = setFirstItem (map->syms); sym; sym = setNextItem (map->syms)) { @@ -968,29 +988,38 @@ printAllocInfoSeg (memmap * map, symbol * func, FILE * of) continue; if (sym->localof != func) continue; - fprintf (of, ";%-25s Allocated to ", sym->name); + + fprintf (of, ";%-25s Allocated ", sym->name); /* if assigned to registers */ if (!sym->allocreq && sym->reqv) { int i; + sym = OP_SYMBOL (sym->reqv); - fprintf (of, "registers "); - for (i = 0; i < 4 && sym->regs[i]; i++) - fprintf (of, "%s ", port->getRegName (sym->regs[i])); - fprintf (of, "\n"); - continue; + if (!sym->isspilt || sym->remat) + { + fprintf (of, "to registers "); + for (i = 0; i < 4 && sym->regs[i]; i++) + fprintf (of, "%s ", port->getRegName (sym->regs[i])); + fprintf (of, "\n"); + continue; + } + else + { + sym = sym->usl.spillLoc; + } } /* if on stack */ if (sym->onStack) { - fprintf (of, "stack - offset %d\n", sym->stack); + fprintf (of, "to stack - offset %d\n", sym->stack); continue; } /* otherwise give rname */ - fprintf (of, "in memory with name '%s'\n", sym->rname); + fprintf (of, "with name '%s'\n", sym->rname); } } @@ -1013,6 +1042,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++) @@ -1039,6 +1071,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 @@ -1060,6 +1096,9 @@ doOverlays (eBBlock ** ebbs, int count) void printAllocInfo (symbol * func, FILE * of) { + if (!func) + return; + if (!of) of = stdout; @@ -1076,4 +1115,20 @@ printAllocInfo (symbol * func, FILE * of) printAllocInfoSeg (idata, func, of); printAllocInfoSeg (sfr, func, of); printAllocInfoSeg (sfrbit, func, of); + + { + set *ovrset; + set *tempOverlaySyms = overlay->syms; + + /* search the set of overlay sets for local variables/parameters */ + for (ovrset = setFirstItem (ovrSetSets); ovrset; + ovrset = setNextItem (ovrSetSets)) + { + overlay->syms = ovrset; + printAllocInfoSeg (overlay, func, of); + } + overlay->syms = tempOverlaySyms; + } + + fprintf (of, ";------------------------------------------------------------\n"); }