- value *lval ;
- int pNum = 1;
-
- for ( lval = val ; lval ; lval = lval->next, pNum++ ) {
-
- /* 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 ;
-
- /* mark it as my parameter */
- lval->sym->ismyparm = 1;
- lval->sym->localof = currFunc;
-
-
- /* if automatic variables r 2b stacked */
- if ( options.stackAuto || IS_RENT(currFunc->etype)) {
-
- if (lval->sym)
- lval->sym->onStack = 1;
-
- /* choose which stack 2 use */
- /* use xternal stack */
- if ( options.useXstack ) {
- /* PENDING: stack direction support */
- SPEC_OCLS(lval->etype) = SPEC_OCLS(lval->sym->etype) = xstack ;
- SPEC_STAK(lval->etype) = SPEC_STAK(lval->sym->etype) = lval->sym->stack =
- xstackPtr - getSize(lval->type);
- xstackPtr -= getSize (lval->type);
- }
- else { /* use internal stack */
- SPEC_OCLS(lval->etype) = SPEC_OCLS(lval->sym->etype) = istack ;
- 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) -
- getSize(lval->type) -
- (IS_ISR(currFunc->etype) ? port->stack.isr_overhead : 0);
- stackPtr -= getSize (lval->type);
- }
- else {
- /* This looks like the wrong order but it turns out OK... */
- /* PENDING: isr, bank overhead, ... */
- SPEC_STAK(lval->etype) = SPEC_STAK(lval->sym->etype) = lval->sym->stack =
- stackPtr +
- (IS_BANKED(currFunc->etype) ? port->stack.banked_overhead : 0) +
- (IS_ISR(currFunc->etype) ? port->stack.isr_overhead : 0) +
- 0;
- stackPtr += getSize (lval->type);
- }
- }
- allocIntoSeg(lval->sym);
- }
- 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);
-
- /* if declared in external storage */
- if (SPEC_SCLS(lval->etype) == S_XDATA)
- SPEC_OCLS(lval->etype) = SPEC_OCLS(lval->sym->etype) = xdata;
- else
- /* other wise depending on the memory model
- 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 */
- SPEC_OCLS(lval->etype) = SPEC_OCLS(lval->sym->etype) =
- ( options.model ? port->mem.default_local_map :
- (options.noOverlay ? port->mem.default_local_map
- :overlay ));
-
- allocIntoSeg(lval->sym);
- }
- }
-
- return ;
+
+ /* symbol name is internal name */
+ if (!sym->level) /* local statics can come here */
+ SNPRINTF (sym->rname, sizeof(sym->rname),
+ "%s%s", port->fun_prefix, sym->name);
+
+ /* add it to the operandKey reset */
+ if (!isinSet (operKeyReset, sym)) {
+ addSet(&operKeyReset, sym);
+ }
+
+ /* if this is a literal e.g. enumerated type */
+ /* put it in the data segment & do nothing */
+ if (IS_LITERAL (sym->etype))
+ {
+ SPEC_OCLS (sym->etype) = data;
+ return;
+ }
+
+ /* if this is a function then assign code space */
+ if (IS_FUNC (sym->type))
+ {
+ 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
+ && (FUNC_INTNO (sym->type) != INTNO_UNSPEC))
+ {
+ if (interrupts[FUNC_INTNO (sym->type)])
+ werror (E_INT_DEFINED,
+ FUNC_INTNO (sym->type),
+ interrupts[FUNC_INTNO (sym->type)]->name);
+ else
+ interrupts[FUNC_INTNO (sym->type)] = sym;
+
+ /* automagically extend the maximum interrupts */
+ if (FUNC_INTNO (sym->type) >= maxInterrupts)
+ maxInterrupts = FUNC_INTNO (sym->type) + 1;
+ }
+ /* if it is not compiler defined */
+ if (!sym->cdef)
+ allocIntoSeg (sym);
+
+ return;
+ }
+
+ /* if this is a SFR or SBIT */
+ if (SPEC_SCLS (sym->etype) == S_SFR ||
+ SPEC_SCLS (sym->etype) == S_SBIT)
+ {
+
+ SPEC_OCLS (sym->etype) =
+ (SPEC_SCLS (sym->etype) == S_SFR ? sfr : sfrbit);
+
+ allocIntoSeg (sym);
+ return;
+ }
+
+ /* if this is a bit variable and no storage class */
+ if (SPEC_NOUN (sym->etype) == V_BIT
+ && SPEC_SCLS (sym->etype) == S_BIT)
+ {
+ SPEC_OCLS (sym->etype) = bit;
+ allocIntoSeg (sym);
+ return;
+ }
+
+ /* if bit storage class */
+ if (SPEC_SCLS (sym->etype) == S_SBIT)
+ {
+ SPEC_OCLS (sym->etype) = bit;
+ allocIntoSeg (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;
+
+ /* if data specified then */
+ if (SPEC_SCLS (sym->etype) == S_DATA)
+ {
+ /* set the output class */
+ SPEC_OCLS (sym->etype) = data;
+ /* generate the symbol */
+ allocIntoSeg (sym);
+ return;
+ }
+
+ /* if it is fixed, then allocate depending on the */
+ /* current memory model, same for automatics */
+ if (SPEC_SCLS (sym->etype) == S_FIXED ||
+ (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) {
+ SPEC_OCLS (sym->etype) = statsg;
+ allocIntoSeg (sym);
+ return;
+ }
+
+ if (SPEC_SCLS (sym->etype) == S_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;
+ }
+
+ if (SPEC_SCLS (sym->etype) == S_IDATA)
+ {
+ SPEC_OCLS (sym->etype) = idata;
+ sym->iaccess = 1;
+ allocIntoSeg (sym);
+ return;
+ }
+
+ if (SPEC_SCLS (sym->etype) == S_PDATA)
+ {
+ SPEC_OCLS (sym->etype) = pdata;
+ sym->iaccess = 1;
+ allocIntoSeg (sym);
+ return;
+ }
+
+ if (SPEC_SCLS (sym->etype) == S_EEPROM)
+ {
+ SPEC_OCLS (sym->etype) = eeprom;
+ allocIntoSeg (sym);
+ return;
+ }
+
+ return;
+}
+
+/*-----------------------------------------------------------------*/
+/* allocParms - parameters are always passed on stack */
+/*-----------------------------------------------------------------*/
+void
+allocParms (value * val)
+{
+ value *lval;
+ int pNum = 1;
+
+ for (lval = val; lval; lval = lval->next, pNum++)
+ {
+
+ /* check the declaration */
+ checkDecl (lval->sym, 0);
+
+ /* 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;
+
+ /* mark it as my parameter */
+ lval->sym->ismyparm = 1;
+ lval->sym->localof = currFunc;
+
+
+ /* if automatic variables r 2b stacked */
+ if (options.stackAuto || IFFUNC_ISREENT (currFunc->type))
+ {
+
+ if (lval->sym)
+ lval->sym->onStack = 1;
+
+ /* choose which stack 2 use */
+ /* use xternal stack */
+ if (options.useXstack)
+ {
+ /* PENDING: stack direction support */
+ SPEC_OCLS (lval->etype) = SPEC_OCLS (lval->sym->etype) = xstack;
+ SPEC_STAK (lval->etype) = SPEC_STAK (lval->sym->etype) = lval->sym->stack =
+ xstackPtr - getSize (lval->type);
+ xstackPtr -= getSize (lval->type);
+ }
+ else
+ { /* use internal stack */
+ SPEC_OCLS (lval->etype) = SPEC_OCLS (lval->sym->etype) = istack;
+ if (port->stack.direction > 0)
+ {
+ SPEC_STAK (lval->etype) = SPEC_STAK (lval->sym->etype) = lval->sym->stack =
+ stackPtr - (FUNC_REGBANK (currFunc->type) ? port->stack.bank_overhead : 0) -
+ getSize (lval->type) -
+ (FUNC_ISISR (currFunc->type) ? port->stack.isr_overhead : 0);
+ stackPtr -= getSize (lval->type);
+ }
+ else
+ {
+ /* This looks like the wrong order but it turns out OK... */
+ /* PENDING: isr, bank overhead, ... */
+ SPEC_STAK (lval->etype) = SPEC_STAK (lval->sym->etype) = lval->sym->stack =
+ stackPtr +
+ ((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);
+ }
+ }
+ allocIntoSeg (lval->sym);
+ }
+ else
+ { /* allocate them in the automatic space */
+ /* generate a unique name */
+ 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)
+ SPEC_OCLS (lval->etype) = SPEC_OCLS (lval->sym->etype) = xdata;
+ else if (SPEC_SCLS (lval->etype) == S_BIT)
+ SPEC_OCLS (lval->etype) = SPEC_OCLS (lval->sym->etype) = bit;
+ else
+ /* otherwise depending on the memory model
+ 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.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);
+ }
+ }
+
+ return;