X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2FSDCCmem.c;h=ba185d241e3da2d5a2e5e95dcc43c705040ada54;hb=3976668708c9048775d0146c285d7ac88608d250;hp=36edd0f8f262693f22d07754325ddbd9301ee560;hpb=df203a96d87ea3322e836e3dd980f64b80b234e7;p=fw%2Fsdcc diff --git a/src/SDCCmem.c b/src/SDCCmem.c index 36edd0f8..ba185d24 100644 --- a/src/SDCCmem.c +++ b/src/SDCCmem.c @@ -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,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) && !options.noiv) + 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), @@ -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,7 +513,8 @@ 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); + 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 */ @@ -567,8 +563,9 @@ deallocParms (value * val) if (!lval->sym->isref) { lval->sym->allocreq = 0; - werror (W_NO_REFERENCE, currFunc->name, - "function argument", lval->sym->name); + 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 */ @@ -584,7 +581,9 @@ deallocParms (value * val) 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); + } } } @@ -600,9 +599,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; @@ -676,15 +676,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); @@ -719,11 +710,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); } @@ -751,7 +742,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); @@ -774,7 +766,7 @@ overlay2data () allocIntoSeg (sym); } - setToNull ((void **) &overlay->syms); + setToNull ((void *) &overlay->syms); } @@ -795,7 +787,7 @@ overlay2Set () addSet (&oset, sym); } - setToNull ((void **) &overlay->syms); + setToNull ((void *) &overlay->syms); addSet (&ovrSetSets, oset); } @@ -839,9 +831,8 @@ 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); @@ -971,18 +962,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); - } } /*-----------------------------------------------------------------*/ @@ -997,7 +976,7 @@ printAllocInfoSeg (memmap * map, symbol * func, FILE * of) return; if (!map->syms) return; - + for (sym = setFirstItem (map->syms); sym; sym = setNextItem (map->syms)) { @@ -1006,14 +985,16 @@ 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 "); + fprintf (of, "to registers "); for (i = 0; i < 4 && sym->regs[i]; i++) fprintf (of, "%s ", port->getRegName (sym->regs[i])); fprintf (of, "\n"); @@ -1023,12 +1004,12 @@ printAllocInfoSeg (memmap * map, symbol * func, FILE * of) /* 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); } } @@ -1105,6 +1086,9 @@ doOverlays (eBBlock ** ebbs, int count) void printAllocInfo (symbol * func, FILE * of) { + if (!func) + return; + if (!of) of = stdout; @@ -1121,5 +1105,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"); }