X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2FSDCCmem.c;h=7e6c60b7349601954f95e6d2e08b3501a2fe88b5;hb=63177e2f4a9a0cb897997b0da23cf4f5fe6209f4;hp=5a447ccc2777dbb1d04d084dd1e94d68b64fe91a;hpb=6812b951155467655aaaccb587131b8a403d2988;p=fw%2Fsdcc diff --git a/src/SDCCmem.c b/src/SDCCmem.c index 5a447ccc..7e6c60b7 100644 --- a/src/SDCCmem.c +++ b/src/SDCCmem.c @@ -5,14 +5,16 @@ #include "common.h" /* memory segments */ -memmap *xstack = NULL; /* xternal stack data */ -memmap *istack = NULL; /* internal stack */ -memmap *code = NULL; /* code segment */ -memmap *data = NULL; /* internal data upto 128 */ -memmap *xdata = NULL; /* external data */ -memmap *idata = NULL; /* internal data upto 256 */ -memmap *bit = NULL; /* bit addressable space */ -memmap *statsg = NULL; /* the constant data segment */ +memmap *xstack = NULL; /* xternal stack data */ +memmap *istack = NULL; /* internal stack */ +memmap *code = NULL; /* code segment */ +memmap *data = NULL; /* internal data upto 128 */ +memmap *xdata = NULL; /* external data */ +memmap *xidata = NULL; /* the initialized xdata */ +memmap *xinit = NULL; /* the initializers for xidata */ +memmap *idata = NULL; /* internal data upto 256 */ +memmap *bit = NULL; /* bit addressable space */ +memmap *statsg = NULL; /* the constant data segment */ memmap *sfr = NULL; /* register space */ memmap *reg = NULL; /* register space */ memmap *sfrbit = NULL; /* sfr bit space */ @@ -46,7 +48,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); @@ -175,6 +177,8 @@ initMem () POINTER-TYPE - FPOINTER */ xdata = allocMap (0, 1, 0, 0, 0, 0, options.xdata_loc, XDATA_NAME, 'F', FPOINTER); + xidata = allocMap (0, 1, 0, 0, 0, 0, 0, XIDATA_NAME, 'F', FPOINTER); + xinit = allocMap (0, 1, 0, 0, 0, 1, 0, XINIT_NAME, 'C', CPOINTER); /* Inderectly addressed internal data segment SFRSPACE - NO @@ -260,11 +264,16 @@ void allocIntoSeg (symbol * sym) { memmap *segment = SPEC_OCLS (sym->etype); + // should we move this to the initialized data segment? + if (port->genXINIT && segment==xdata && + sym->ival && sym->level==0 && !SPEC_ABSA(sym->etype)) { + segment=SPEC_OCLS(sym->etype)=xidata; + } addSet (&segment->syms, sym); } /*-----------------------------------------------------------------*/ -/* allocGlobal - aassigns the output segment to a global var */ +/* allocGlobal - assigns the output segment to a global var */ /*-----------------------------------------------------------------*/ void allocGlobal (symbol * sym) @@ -291,19 +300,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) @@ -420,7 +429,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 @@ -434,7 +443,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) @@ -456,9 +465,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 @@ -467,8 +476,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); } @@ -793,17 +802,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 */ @@ -930,7 +940,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)) @@ -1002,8 +1012,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; @@ -1015,8 +1025,13 @@ canOverlayLocals (eBBlock ** ebbs, int count) iCode *ic; for (ic = ebbs[i]->sch; ic; ic = ic->next) - if (ic && (ic->op == CALL || ic->op == PCALL)) - return FALSE; + if (ic) { + if (ic->op == CALL) { + sym_link *ftype = operandType(IC_LEFT(ic)); + /* builtins only can use overlays */ + if (!IFFUNC_ISBUILTIN(ftype)) return FALSE; + } else if (ic->op == PCALL) return FALSE; + } } /* no function calls found return TRUE */