X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2FSDCCmem.c;h=613de3e200c8b067c76dc30f4183c54bbd74b833;hb=92c02b20c217e7cf8cc20d667816fdc4c71b9e99;hp=cb1ecb0e94950563d2718c0cc3d4ac5ee01e95f7;hpb=29779804200986ce903b5086441b49265a122dc5;p=fw%2Fsdcc diff --git a/src/SDCCmem.c b/src/SDCCmem.c index cb1ecb0e..613de3e2 100644 --- a/src/SDCCmem.c +++ b/src/SDCCmem.c @@ -46,7 +46,7 @@ allocMap (char rspace, /* sfr space */ { memmap *map; - if (!(map = calloc (sizeof (memmap), 1))) + if (!(map = Safe_alloc (sizeof (memmap)))) { werror (E_OUT_OF_MEM, __FILE__, sizeof (memmap)); exit (1); @@ -291,19 +291,19 @@ allocGlobal (symbol * sym) SPEC_OCLS (sym->etype) = code; /* if this is an interrupt service routine then put it in the interrupt service array */ - if (IS_ISR (sym->etype)) + if (FUNC_ISISR (sym->type)) { - if (interrupts[SPEC_INTN (sym->etype)]) + if (interrupts[FUNC_INTNO (sym->type)]) werror (E_INT_DEFINED, - SPEC_INTN (sym->etype), - interrupts[SPEC_INTN (sym->etype)]->name); + FUNC_INTNO (sym->type), + interrupts[FUNC_INTNO (sym->type)]->name); else - interrupts[SPEC_INTN (sym->etype)] = sym; + interrupts[FUNC_INTNO (sym->type)] = sym; /* automagically extend the maximum interrupts */ - if (SPEC_INTN (sym->etype) >= maxInterrupts) - maxInterrupts = SPEC_INTN (sym->etype) + 1; + if (FUNC_INTNO (sym->type) >= maxInterrupts) + maxInterrupts = FUNC_INTNO (sym->type) + 1; } /* if it is not compiler defined */ if (!sym->cdef) @@ -376,13 +376,11 @@ allocGlobal (symbol * sym) } /* if code change to constant */ - if (SPEC_SCLS (sym->etype) == S_CODE || - SPEC_SCLS (sym->etype) == S_CONSTANT) - { - SPEC_OCLS (sym->etype) = statsg; - allocIntoSeg (sym); - return; - } + if (SPEC_SCLS (sym->etype) == S_CODE) { + SPEC_OCLS (sym->etype) = statsg; + allocIntoSeg (sym); + return; + } if (SPEC_SCLS (sym->etype) == S_XDATA) { @@ -422,7 +420,7 @@ allocParms (value * val) { /* check the declaration */ - checkDecl (lval->sym); + checkDecl (lval->sym, 0); /* if this a register parm then allocate it as a local variable by adding it @@ -436,7 +434,7 @@ allocParms (value * val) /* if automatic variables r 2b stacked */ - if (options.stackAuto || IS_RENT (currFunc->etype)) + if (options.stackAuto || IFFUNC_ISREENT (currFunc->type)) { if (lval->sym) @@ -458,9 +456,9 @@ allocParms (value * val) if (port->stack.direction > 0) { SPEC_STAK (lval->etype) = SPEC_STAK (lval->sym->etype) = lval->sym->stack = - stackPtr - (SPEC_BANK (currFunc->etype) ? port->stack.bank_overhead : 0) - + stackPtr - (FUNC_REGBANK (currFunc->type) ? port->stack.bank_overhead : 0) - getSize (lval->type) - - (IS_ISR (currFunc->etype) ? port->stack.isr_overhead : 0); + (FUNC_ISISR (currFunc->type) ? port->stack.isr_overhead : 0); stackPtr -= getSize (lval->type); } else @@ -469,8 +467,8 @@ allocParms (value * val) /* PENDING: isr, bank overhead, ... */ SPEC_STAK (lval->etype) = SPEC_STAK (lval->sym->etype) = lval->sym->stack = stackPtr + - (IS_BANKEDCALL (currFunc->etype) ? port->stack.banked_overhead : 0) + - (IS_ISR (currFunc->etype) ? port->stack.isr_overhead : 0) + + ((IFFUNC_ISBANKEDCALL (currFunc->type) && !SPEC_STAT(getSpec(currFunc->etype)))? port->stack.banked_overhead : 0) + + (FUNC_ISISR (currFunc->type) ? port->stack.isr_overhead : 0) + 0; stackPtr += getSize (lval->type); } @@ -478,11 +476,11 @@ allocParms (value * val) allocIntoSeg (lval->sym); } else - { /* allocate them in the automatic space */ + { /* 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); - + /* if declared in external storage */ if (SPEC_SCLS (lval->etype) == S_XDATA) SPEC_OCLS (lval->etype) = SPEC_OCLS (lval->sym->etype) = xdata; @@ -491,18 +489,17 @@ allocParms (value * val) note here that we put it into the overlay segment first, we will remove it from the overlay segment after the overlay determination has been done */ - if (options.model == MODEL_SMALL) - { - SPEC_OCLS (lval->etype) = SPEC_OCLS (lval->sym->etype) = - (options.model == MODEL_SMALL ? port->mem.default_local_map : - (options.noOverlay ? port->mem.default_local_map - : overlay)); - } - else - { - SPEC_SCLS (lval->etype) = S_XDATA; - SPEC_OCLS (lval->etype) = SPEC_OCLS (lval->sym->etype) = xdata; - } + if (options.model == MODEL_SMALL) + { + SPEC_OCLS (lval->etype) = SPEC_OCLS (lval->sym->etype) = + (options.noOverlay ? port->mem.default_local_map + : overlay); + } + else + { + SPEC_SCLS (lval->etype) = S_XDATA; + SPEC_OCLS (lval->etype) = SPEC_OCLS (lval->sym->etype) = xdata; + } allocIntoSeg (lval->sym); } } @@ -545,7 +542,7 @@ deallocParms (value * val) strcpy (lval->sym->rname, buffer); strcpy (lval->name, strcpy (lval->sym->name, lval->sym->rname)); addSym (SymbolTab, lval->sym, lval->sym->name, - lval->sym->level, lval->sym->block); + lval->sym->level, lval->sym->block, 1); lval->sym->_isparm = 1; addSet (&operKeyReset, lval->sym); } @@ -585,35 +582,27 @@ allocLocal (symbol * sym) /* this is automatic */ /* if it to be placed on the stack */ - if (options.stackAuto || reentrant) - { - - sym->onStack = 1; - if (options.useXstack) - { - /* PENDING: stack direction for xstack */ - SPEC_OCLS (sym->etype) = xstack; - SPEC_STAK (sym->etype) = sym->stack = (xstackPtr + 1); - xstackPtr += getSize (sym->type); - } - else - { - SPEC_OCLS (sym->etype) = istack; - if (port->stack.direction > 0) - { - SPEC_STAK (sym->etype) = sym->stack = (stackPtr + 1); - stackPtr += getSize (sym->type); - } - else - { - stackPtr -= getSize (sym->type); - SPEC_STAK (sym->etype) = sym->stack = stackPtr; - } - } - allocIntoSeg (sym); - return; + if (options.stackAuto || reentrant) { + sym->onStack = 1; + if (options.useXstack) { + /* PENDING: stack direction for xstack */ + SPEC_OCLS (sym->etype) = xstack; + SPEC_STAK (sym->etype) = sym->stack = (xstackPtr + 1); + xstackPtr += getSize (sym->type); + } else { + SPEC_OCLS (sym->etype) = istack; + if (port->stack.direction > 0) { + SPEC_STAK (sym->etype) = sym->stack = (stackPtr + 1); + stackPtr += getSize (sym->type); + } else { + stackPtr -= getSize (sym->type); + SPEC_STAK (sym->etype) = sym->stack = stackPtr; + } } - + allocIntoSeg (sym); + return; + } + /* else depending on the storage class specified */ if (SPEC_SCLS (sym->etype) == S_XDATA) { @@ -622,15 +611,12 @@ allocLocal (symbol * sym) return; } - if ((SPEC_SCLS (sym->etype) == S_CODE || - SPEC_SCLS (sym->etype) == S_CONSTANT) && - !sym->_isparm) - { - SPEC_OCLS (sym->etype) = statsg; - allocIntoSeg (sym); - return; - } - + if (SPEC_SCLS (sym->etype) == S_CODE && !sym->_isparm) { + SPEC_OCLS (sym->etype) = statsg; + allocIntoSeg (sym); + return; + } + if (SPEC_SCLS (sym->etype) == S_IDATA) { SPEC_OCLS (sym->etype) = idata; @@ -692,9 +678,13 @@ allocLocal (symbol * sym) /* 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 == MODEL_SMALL ? port->mem.default_local_map : - (options.noOverlay ? port->mem.default_local_map - : overlay)); + if (options.model == MODEL_SMALL) { + SPEC_OCLS (sym->etype) = + (options.noOverlay ? port->mem.default_local_map + : overlay); + } else { + SPEC_OCLS (sym->etype) = port->mem.default_local_map; + } allocIntoSeg (sym); } @@ -794,7 +784,7 @@ allocVariables (symbol * symChain) if (csym && csym->level == sym->level) werror (E_DUPLICATE_TYPEDEF, sym->name); - addSym (TypedefTab, sym, sym->name, sym->level, sym->block); + addSym (TypedefTab, sym, sym->name, sym->level, sym->block, 0); continue; /* go to the next one */ } /* make sure it already exist */ @@ -803,17 +793,18 @@ allocVariables (symbol * symChain) csym = sym; /* check the declaration */ - checkDecl (csym); + checkDecl (csym,0); /* if this is a function or a pointer to function */ /* then args processing */ if (funcInChain (csym->type)) { - - processFuncArgs (csym, 1); +#if 1 // jwk: TODO should have been done already in addDecl() (oclass????) + processFuncArgs (csym); +#endif /* if register bank specified then update maxRegBank */ - if (maxRegBank < SPEC_BANK (csym->etype)) - maxRegBank = SPEC_BANK (csym->etype); + if (maxRegBank < FUNC_REGBANK (csym->type)) + maxRegBank = FUNC_REGBANK (csym->type); } /* if this is a extern variable then change the */ @@ -940,7 +931,7 @@ redoStackOffsets (void) /* if the debug option is set then output the symbols to the map file */ - if (options.debug && !options.nodebug) + if (options.debug) { for (sym = setFirstItem (istack->syms); sym; sym = setNextItem (istack->syms)) @@ -1012,8 +1003,8 @@ canOverlayLocals (eBBlock ** ebbs, int count) if (options.noOverlay || options.stackAuto || (currFunc && - (IS_RENT (currFunc->etype) || - IS_ISR (currFunc->etype))) || + (IFFUNC_ISREENT (currFunc->type) || + FUNC_ISISR (currFunc->type))) || elementsInSet (overlay->syms) == 0) return FALSE;