/*-----------------------------------------------------------------*/
#include "common.h"
+#include "dbuf_string.h"
/* memory segments */
memmap *xstack = NULL; /* xternal stack data */
memmap *idata = NULL; /* internal data upto 256 */
memmap *bit = NULL; /* bit addressable space */
memmap *statsg = NULL; /* the constant data segment */
+memmap *c_abs = NULL; /* constant absolute data */
+memmap *x_abs = NULL; /* absolute xdata/pdata */
+memmap *i_abs = NULL; /* absolute idata upto 256 */
+memmap *d_abs = NULL; /* absolute data upto 128 */
memmap *sfr = NULL; /* register space */
memmap *reg = NULL; /* register space */
memmap *sfrbit = NULL; /* sfr bit space */
symbols in a single overlay */
set *ovrSetSets = NULL;
-int maxRegBank = 0;
int fatalError = 0; /* fatal error flag */
/*-----------------------------------------------------------------*/
map->sname = name;
map->dbName = dbName;
map->ptrType = ptrType;
- if (!(map->oFile = tempfile ()))
- {
- werror (E_TMPFILE_FAILED);
- exit (1);
- }
- addSetHead (&tmpfileSet, map->oFile);
map->syms = NULL;
+
+ dbuf_init(&map->oBuf, 4096);
+
return map;
}
DEBUG-NAME - 'B'
POINTER-TYPE - POINTER
*/
- if (ISTACK_NAME) {
- istack = allocMap (0, 0, 0, 0, 0, 0, options.stack_loc,
- ISTACK_NAME, 'B', POINTER);
- } else {
- istack=NULL;
- }
+ 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
DEBUG-NAME - 'C'
POINTER-TYPE - CPOINTER
*/
- home = allocMap (0, 1, 0, 0, 0, 1, options.code_loc, CODE_NAME, 'C', CPOINTER);
+ home = allocMap (0, 1, 0, 0, 0, 1, options.code_loc, HOME_NAME, 'C', CPOINTER);
/* Static segment (code for variables );
SFRSPACE - NO
*/
statsg = allocMap (0, 1, 0, 0, 0, 1, 0, STATIC_NAME, 'D', CPOINTER);
+ /* Constant Absolute Data segment (for variables );
+ SFRSPACE - NO
+ FAR-SPACE - YES
+ PAGED - NO
+ DIRECT-ACCESS - NO
+ BIT-ACCESS - NO
+ CODE-ACCESS - YES
+ DEBUG-NAME - 'D'
+ POINTER-TYPE - CPOINTER
+ */
+ c_abs = allocMap (0, 1, 0, 0, 0, 1, 0, CABS_NAME, 'D', CPOINTER);
+
/* Data segment - internal storage segment ;
SFRSPACE - NO
FAR-SPACE - NO
*/
data = allocMap (0, 0, 0, 1, 0, 0, options.data_loc, DATA_NAME, 'E', POINTER);
+ /* Absolute internal storage segment ;
+ SFRSPACE - NO
+ FAR-SPACE - NO
+ PAGED - NO
+ DIRECT-ACCESS - YES
+ BIT-ACCESS - NO
+ CODE-ACCESS - NO
+ DEBUG-NAME - 'E'
+ POINTER-TYPE - POINTER
+ */
+ if (IABS_NAME)
+ {
+ d_abs = allocMap (0, 0, 0, 1, 0, 0, options.data_loc, IABS_NAME, 'E', POINTER);
+ }
+ else
+ {
+ d_abs = NULL;
+ }
+
/* overlay segment - same as internal storage segment ;
SFRSPACE - NO
FAR-SPACE - NO
DEBUG-NAME - 'E'
POINTER-TYPE - POINTER
*/
- if (OVERLAY_NAME) {
- overlay = allocMap (0, 0, 0, 1, 0, 0, options.data_loc, DATA_NAME, 'E', POINTER);
- } else {
- overlay = NULL;
- }
+ if (OVERLAY_NAME)
+ {
+ overlay = allocMap (0, 0, 0, 1, 0, 0, options.data_loc, DATA_NAME, 'E', POINTER);
+ }
+ else
+ {
+ overlay = NULL;
+ }
/* Xternal paged segment ;
SFRSPACE - NO
DEBUG-NAME - 'P'
POINTER-TYPE - PPOINTER
*/
- if (PDATA_NAME) {
- pdata = allocMap (0, 0, 1, 0, 0, 0, options.xstack_loc, PDATA_NAME, 'P', PPOINTER);
- } else {
- pdata = NULL;
- }
+ if (PDATA_NAME)
+ {
+ pdata = allocMap (0, 0, 1, 0, 0, 0, options.xstack_loc, PDATA_NAME, 'P', PPOINTER);
+ }
+ else
+ {
+ pdata = NULL;
+ }
/* Xternal Data segment -
SFRSPACE - NO
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);
+ /* Absolute external storage segment ;
+ SFRSPACE - NO
+ FAR-SPACE - YES
+ PAGED - NO
+ DIRECT-ACCESS - NO
+ BIT-ACCESS - NO
+ CODE-ACCESS - NO
+ DEBUG-NAME - 'F'
+ POINTER-TYPE - FPOINTER
+ */
+ if (XABS_NAME)
+ {
+ x_abs = allocMap (0, 1, 0, 0, 0, 0, options.xdata_loc, XABS_NAME, 'F', FPOINTER);
+ }
+ else
+ {
+ x_abs = NULL;
+ }
+
/* Indirectly addressed internal data segment
SFRSPACE - NO
FAR-SPACE - NO
DEBUG-NAME - 'G'
POINTER-TYPE - IPOINTER
*/
- if (IDATA_NAME) {
- idata = allocMap (0, 0, 0, 0, 0, 0, options.idata_loc,
- IDATA_NAME, 'G', IPOINTER);
- } else {
- idata=NULL;
- }
+ if (IDATA_NAME)
+ {
+ idata = allocMap (0, 0, 0, 0, 0, 0, options.idata_loc, IDATA_NAME, 'G', IPOINTER);
+ }
+ else
+ {
+ idata = NULL;
+ }
+
+ /* Indirectly addressed absolute internal segment
+ SFRSPACE - NO
+ FAR-SPACE - NO
+ PAGED - NO
+ DIRECT-ACCESS - NO
+ BIT-ACCESS - NO
+ CODE-ACCESS - NO
+ DEBUG-NAME - 'E'
+ POINTER-TYPE - IPOINTER
+ */
+ if (IABS_NAME)
+ {
+ i_abs = allocMap (0, 0, 0, 0, 0, 0, options.data_loc, IABS_NAME, 'E', IPOINTER);
+ }
+ else
+ {
+ i_abs = NULL;
+ }
/* Bit space ;
SFRSPACE - NO
{
memmap *segment = SPEC_OCLS (sym->etype);
addSet (&segment->syms, sym);
+ if (segment == pdata)
+ sym->iaccess = 1;
}
/*-----------------------------------------------------------------*/
}
}
+/*-----------------------------------------------------------------*/
+/* allocDefault - assigns the output segment based on SCLASS */
+/*-----------------------------------------------------------------*/
+bool
+allocDefault (symbol * sym)
+{
+ switch (SPEC_SCLS (sym->etype))
+ {
+ case S_SFR:
+ SPEC_OCLS (sym->etype) = sfr;
+ break;
+ case S_SBIT:
+ SPEC_OCLS (sym->etype) = sfrbit;
+ break;
+ case S_CODE:
+ if (sym->_isparm)
+ return FALSE;
+ /* if code change to constant */
+ if (sym->ival && SPEC_ABSA (sym->etype))
+ {
+ SPEC_OCLS(sym->etype) = c_abs;
+ }
+ else
+ {
+ SPEC_OCLS (sym->etype) = statsg;
+ }
+ break;
+ case S_XDATA:
+ /* absolute initialized global */
+ if (sym->ival && SPEC_ABSA (sym->etype))
+ {
+ SPEC_OCLS(sym->etype) = x_abs;
+ }
+ /* or should we move this to the initialized data segment? */
+ else if (port->genXINIT && sym->ival && (sym->level==0))
+ {
+ SPEC_OCLS(sym->etype) = xidata;
+ }
+ else
+ {
+ SPEC_OCLS (sym->etype) = xdata;
+ }
+ break;
+ case S_DATA:
+ /* absolute initialized global */
+ if (sym->ival && SPEC_ABSA (sym->etype))
+ {
+ SPEC_OCLS(sym->etype) = d_abs;
+ }
+ else
+ {
+ SPEC_OCLS (sym->etype) = data;
+ }
+ break;
+ case S_IDATA:
+ /* absolute initialized global */
+ if (sym->ival && SPEC_ABSA (sym->etype))
+ {
+ SPEC_OCLS(sym->etype) = i_abs;
+ }
+ else
+ {
+ SPEC_OCLS (sym->etype) = idata;
+ }
+ sym->iaccess = 1;
+ break;
+ case S_PDATA:
+ SPEC_OCLS (sym->etype) = pdata;
+ sym->iaccess = 1;
+ break;
+ case S_BIT:
+ SPEC_OCLS (sym->etype) = bit;
+ break;
+ case S_EEPROM:
+ SPEC_OCLS (sym->etype) = eeprom;
+ break;
+ default:
+ return FALSE;
+ }
+ allocIntoSeg (sym);
+ return TRUE;
+}
/*-----------------------------------------------------------------*/
/* allocGlobal - assigns the output segment to a global var */
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)
+ if (IS_SPEC(sym->type) && SPEC_NOUN (sym->type) == V_BIT)
+ /*&& SPEC_SCLS (sym->etype) == S_BIT*/
{
- SPEC_OCLS (sym->etype) = bit;
+ SPEC_OCLS (sym->type) = bit;
allocIntoSeg (sym);
return;
}
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 ||
}
}
- /* 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;
- }
-
+ allocDefault (sym);
return;
}
for (lval = val; lval; lval = lval->next, pNum++)
{
-
/* check the declaration */
checkDecl (lval->sym, 0);
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;
"%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;
+ /* if declared in specific storage */
+ if (allocDefault (lval->sym))
+ {
+ SPEC_OCLS (lval->etype) = SPEC_OCLS (lval->sym->etype);
+ continue;
+ }
+
+ /* otherwise depending on the memory model */
+ SPEC_OCLS (lval->etype) = SPEC_OCLS (lval->sym->etype) =
+ port->mem.default_local_map;
+ if (options.model == MODEL_SMALL)
+ {
+ /* 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.noOverlay)
+ {
+ SPEC_OCLS (lval->etype) = SPEC_OCLS (lval->sym->etype) =
+ overlay;
+ }
+ }
+ else if (options.model == MODEL_MEDIUM)
+ {
+ SPEC_SCLS (lval->etype) = S_PDATA;
+ }
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;
- }
+ {
+ SPEC_SCLS (lval->etype) = S_XDATA;
+ }
allocIntoSeg (lval->sym);
}
}
-
return;
}
for (lval = val; lval; lval = lval->next)
{
-
/* unmark is myparm */
lval->sym->ismyparm = 0;
if (lval->sym->rname[0])
{
char buffer[SDCC_NAME_MAX];
+ symbol * argsym = lval->sym;
+
strncpyz (buffer, lval->sym->rname, sizeof(buffer));
lval->sym = copySymbol (lval->sym);
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));
+ /* need to keep the original name for inlining to work */
+ /*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;
- if (!isinSet (operKeyReset, lval->sym)) {
- addSet(&operKeyReset, lval->sym);
- }
- }
+ if (!isinSet (operKeyReset, lval->sym))
+ {
+ addSet(&operKeyReset, lval->sym);
+ }
+ /* restore the original symbol */
+ lval->sym = argsym;
+ }
}
-
return;
}
void
allocLocal (symbol * sym)
{
-
/* generate an unique name */
SNPRINTF (sym->rname, sizeof(sym->rname),
"%s%s_%s_%d_%d",
}
/* else depending on the storage class specified */
- if (SPEC_SCLS (sym->etype) == S_XDATA)
- {
- SPEC_OCLS (sym->etype) = xdata;
- 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;
- 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 this is a function then assign code space */
if (IS_FUNC (sym->type))
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))
+ if (IS_SPEC(sym->type) && SPEC_NOUN (sym->type) == V_BIT)
{
- SPEC_OCLS (sym->etype) = bit;
+ SPEC_SCLS (sym->type) = S_BIT;
+ SPEC_OCLS (sym->type) = bit;
allocIntoSeg (sym);
return;
}
- if (SPEC_SCLS (sym->etype) == S_DATA)
+ if ((SPEC_SCLS (sym->etype) == S_DATA) || (SPEC_SCLS (sym->etype) == S_REGISTER))
{
SPEC_OCLS (sym->etype) = (options.noOverlay ? data : overlay);
allocIntoSeg (sym);
return;
}
- if (SPEC_SCLS (sym->etype) == S_EEPROM)
+ if (allocDefault (sym))
{
- SPEC_OCLS (sym->etype) = eeprom;
- allocIntoSeg (sym);
return;
}
overlay analysis has been done */
if (options.model == MODEL_SMALL) {
SPEC_OCLS (sym->etype) =
- (options.noOverlay ? port->mem.default_local_map
- : overlay);
+ (options.noOverlay ? port->mem.default_local_map : overlay);
} else {
SPEC_OCLS (sym->etype) = port->mem.default_local_map;
}
SPEC_EXTR (sym->etype) = 0;
addSym (TypedefTab, sym, sym->name, sym->level, sym->block, 0);
- continue; /* go to the next one */
+ continue; /* go to the next one */
}
- /* make sure it already exist */
+ /* make sure it already exists */
csym = findSymWithLevel (SymbolTab, sym);
if (!csym || (csym && csym->level != sym->level))
csym = sym;
/* check the declaration */
checkDecl (csym,0);
- /* if this is a function or a pointer to function */
- /* then args processing */
+ /* if this is a function or a pointer to a */
+ /* function then do args processing */
if (funcInChain (csym->type))
{
processFuncArgs (csym);
-
- /* 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 */
- /* level to zero temporarily */
+ /* level to zero temporarily */
if (IS_EXTERN (csym->etype) || IS_FUNC (csym->type))
{
saveLevel = csym->level;
if (IS_LITERAL (sym->etype))
continue;
- /* generate the actual declaration */
+ /* generate the actual declaration */
if (csym->level)
{
allocLocal (csym);
/* printAllocInfoSeg- print the allocation for a given section */
/*-----------------------------------------------------------------*/
static void
-printAllocInfoSeg (memmap * map, symbol * func, FILE * of)
+printAllocInfoSeg (memmap * map, symbol * func, struct dbuf_s *oBuf)
{
symbol *sym;
if (sym->localof != func)
continue;
- fprintf (of, ";%-25s Allocated ", sym->name);
+ dbuf_printf (oBuf, ";%-25s Allocated ", sym->name);
/* if assigned to registers */
if (!sym->allocreq && sym->reqv)
sym = OP_SYMBOL (sym->reqv);
if (!sym->isspilt || sym->remat)
{
- fprintf (of, "to registers ");
+ dbuf_append_str (oBuf, "to registers ");
for (i = 0; i < 4 && sym->regs[i]; i++)
- fprintf (of, "%s ", port->getRegName (sym->regs[i]));
- fprintf (of, "\n");
+ dbuf_printf (oBuf, "%s ", port->getRegName (sym->regs[i]));
+ dbuf_append_char (oBuf, '\n');
continue;
}
else
/* if on stack */
if (sym->onStack)
{
- fprintf (of, "to stack - offset %d\n", sym->stack);
+ dbuf_printf (oBuf, "to stack - offset %d\n", sym->stack);
continue;
}
/* otherwise give rname */
- fprintf (of, "with name '%s'\n", sym->rname);
+ dbuf_printf (oBuf, "with name '%s'\n", sym->rname);
}
}
/* printAllocInfo - prints allocation information for a function */
/*-----------------------------------------------------------------*/
void
-printAllocInfo (symbol * func, FILE * of)
+printAllocInfo (symbol * func, struct dbuf_s * oBuf)
{
if (!func)
return;
- if (!of)
- of = stdout;
-
/* must be called after register allocation is complete */
- fprintf (of, ";------------------------------------------------------------\n");
- fprintf (of, ";Allocation info for local variables in function '%s'\n", func->name);
- fprintf (of, ";------------------------------------------------------------\n");
-
- printAllocInfoSeg (xstack, func, of);
- printAllocInfoSeg (istack, func, of);
- printAllocInfoSeg (code, func, of);
- printAllocInfoSeg (data, func, of);
- printAllocInfoSeg (xdata, func, of);
- printAllocInfoSeg (idata, func, of);
- printAllocInfoSeg (sfr, func, of);
- printAllocInfoSeg (sfrbit, func, of);
+ dbuf_append_str (oBuf, ";------------------------------------------------------------\n");
+ dbuf_printf (oBuf, ";Allocation info for local variables in function '%s'\n", func->name);
+ dbuf_append_str (oBuf, ";------------------------------------------------------------\n");
+
+ printAllocInfoSeg (xstack, func, oBuf);
+ printAllocInfoSeg (istack, func, oBuf);
+ printAllocInfoSeg (code, func, oBuf);
+ printAllocInfoSeg (data, func, oBuf);
+ printAllocInfoSeg (xdata, func, oBuf);
+ printAllocInfoSeg (idata, func, oBuf);
+ printAllocInfoSeg (sfr, func, oBuf);
+ printAllocInfoSeg (sfrbit, func, oBuf);
{
set *ovrset;
ovrset = setNextItem (ovrSetSets))
{
overlay->syms = ovrset;
- printAllocInfoSeg (overlay, func, of);
+ printAllocInfoSeg (overlay, func, oBuf);
}
overlay->syms = tempOverlaySyms;
}
- fprintf (of, ";------------------------------------------------------------\n");
+ dbuf_append_str (oBuf, ";------------------------------------------------------------\n");
}