-
- /* print the area name */
- for (sym = setFirstItem (map->syms); sym;
- sym = setNextItem (map->syms)) {
-
- /* if extern then add it into the extern list */
- if (IS_EXTERN (sym->etype)) {
- addSetHead (&externs, sym);
- continue;
- }
-
- /* if allocation required check is needed
- then check if the symbol really requires
- allocation only for local variables */
- if (arFlag && !IS_AGGREGATE(sym->type) &&
- !(sym->_isparm && !IS_REGPARM(sym->etype)) &&
- !sym->allocreq && sym->level)
- continue ;
-
- /* if global variable & not static or extern
- and addPublics allowed then add it to the public set */
- if ((sym->level == 0 ||
- (sym->_isparm && !IS_REGPARM(sym->etype))) &&
- addPublics &&
- !IS_STATIC (sym->etype) &&
- (sym->used || sym->fbody)) {
- addSetHead (&publics, sym);
- }
-
- /* if extern then do nothing or is a function
- then do nothing */
- if (IS_FUNC (sym->type))
- continue;
-
- /* print extra debug info if required */
- if ((options.debug || sym->level == 0) && !options.nodebug) {
-
- cdbSymbol(sym,cdbFile,FALSE,FALSE);
-
- if (!sym->level) /* global */
- if (IS_STATIC(sym->etype))
- fprintf(map->oFile,"F%s$",moduleName); /* scope is file */
- else
- fprintf(map->oFile,"G$"); /* scope is global */
- else
- /* symbol is local */
- fprintf(map->oFile,"L%s$",(sym->localof ? sym->localof->name : "-null-"));
- fprintf(map->oFile,"%s$%d$%d",sym->name,sym->level,sym->block);
- }
-
- /* if is has an absolute address then generate
- an equate for this no need to allocate space */
- if (SPEC_ABSA (sym->etype)) {
- if ((options.debug || sym->level == 0) && !options.nodebug)
- fprintf (map->oFile," == 0x%04x\n",SPEC_ADDR (sym->etype));
-
- fprintf (map->oFile, "%s\t=\t0x%04x\n",
- sym->rname,
- SPEC_ADDR (sym->etype));
- }
- else {
- /* allocate space */
- if ((options.debug || sym->level == 0) && !options.nodebug)
- fprintf(map->oFile,"==.\n");
- if (IS_STATIC(sym->etype))
- tfprintf(map->oFile, "!slabeldef\n", sym->rname);
- else
- tfprintf(map->oFile, "!labeldef\n", sym->rname);
- tfprintf(map->oFile, "\t!ds\n", (unsigned int)getSize (sym->type) & 0xffff);
- }
-
- /* if it has an initial value then do it only if
- it is a global variable */
- if (sym->ival && sym->level == 0) {
- ast *ival = NULL;
-
- if (IS_AGGREGATE (sym->type))
- ival = initAggregates (sym, sym->ival, NULL);
- else
- ival = newNode ('=', newAst_VALUE(symbolVal (sym)),
- decorateType (resolveSymbols (list2expr (sym->ival))));
- codeOutFile = statsg->oFile;
- allocInfo = 0;
- eBBlockFromiCode (iCodeFromAst (ival));
- allocInfo = 1;
- sym->ival = NULL;
- }
+
+ for (sym = setFirstItem (map->syms); sym;
+ sym = setNextItem (map->syms))
+ {
+ symbol *newSym=NULL;
+
+ /* if extern then add it into the extern list */
+ if (IS_EXTERN (sym->etype))
+ {
+ addSetHead (&externs, sym);
+ continue;
+ }
+
+ /* if allocation required check is needed
+ then check if the symbol really requires
+ allocation only for local variables */
+
+ if (arFlag && !IS_AGGREGATE (sym->type) &&
+ !(sym->_isparm && !IS_REGPARM (sym->etype)) &&
+ !sym->allocreq && sym->level)
+ continue;
+
+ /* for bitvar locals and parameters */
+ if (!arFlag && !sym->allocreq && sym->level
+ && !SPEC_ABSA (sym->etype)) {
+ continue;
+ }
+
+ /* if global variable & not static or extern
+ and addPublics allowed then add it to the public set */
+ if ((sym->level == 0 ||
+ (sym->_isparm && !IS_REGPARM (sym->etype))) &&
+ addPublics &&
+ !IS_STATIC (sym->etype) &&
+ (IS_FUNC(sym->type) ? (sym->used || IFFUNC_HASBODY(sym->type)) : 1))
+ {
+ addSetHead (&publics, sym);
+ }
+
+ /* if extern then do nothing or is a function
+ then do nothing */
+ if (IS_FUNC (sym->type) && !(sym->isitmp))
+ continue;
+
+ /* print extra debug info if required */
+ if (options.debug)
+ {
+ if (!sym->level) /* global */
+ {
+ if (IS_STATIC (sym->etype))
+ fprintf (map->oFile, "F%s$", moduleName); /* scope is file */
+ else
+ fprintf (map->oFile, "G$"); /* scope is global */
+ }
+ else
+ {
+ /* symbol is local */
+ fprintf (map->oFile, "L%s$", (sym->localof ? sym->localof->name : "-null-"));
+ }
+ fprintf (map->oFile, "%s$%d$%d", sym->name, sym->level, sym->block);
+ }
+
+ /* if it has an initial value then do it only if
+ it is a global variable */
+ if (sym->ival && sym->level == 0) {
+ if (SPEC_OCLS(sym->etype)==xidata) {
+ /* create a new "XINIT (CODE)" symbol, that will be emitted later
+ in the static seg */
+ newSym=copySymbol (sym);
+ SPEC_OCLS(newSym->etype)=xinit;
+ SNPRINTF (newSym->name, sizeof(newSym->name), "__xinit_%s", sym->name);
+ SNPRINTF (newSym->rname, sizeof(newSym->rname), "__xinit_%s", sym->rname);
+ if (IS_SPEC (newSym->type))
+ SPEC_CONST (newSym->type) = 1;
+ else
+ DCL_PTR_CONST (newSym->type) = 1;
+ SPEC_STAT(newSym->etype)=1;
+ resolveIvalSym(newSym->ival, newSym->type);
+
+ // add it to the "XINIT (CODE)" segment
+ addSet(&xinit->syms, newSym);
+
+ if (!SPEC_ABSA (sym->etype))
+ {
+ FILE *tmpFile = tempfile ();
+ addSetHead (&tmpfileSet, tmpFile);
+ // before allocation we must parse the sym->ival tree
+ // but without actually generating initialization code
+ noAlloc++;
+ resolveIvalSym (sym->ival, sym->type);
+ printIval (sym, sym->type, sym->ival, tmpFile);
+ noAlloc--;
+ }
+
+ sym->ival=NULL;
+ } else {
+ if (IS_AGGREGATE (sym->type)) {
+ ival = initAggregates (sym, sym->ival, NULL);
+ } else {
+ if (getNelements(sym->type, sym->ival)>1) {
+ werrorfl (sym->fileDef, sym->lineDef, W_EXCESS_INITIALIZERS, "scalar",
+ sym->name);
+ }
+ ival = newNode ('=', newAst_VALUE (symbolVal (sym)),
+ decorateType (resolveSymbols (list2expr (sym->ival)), RESULT_TYPE_NONE));
+ }
+ codeOutFile = statsg->oFile;
+
+ if (ival) {
+ // set ival's lineno to where the symbol was defined
+ setAstLineno (ival, lineno=sym->lineDef);
+ // check if this is not a constant expression
+ if (!constExprTree(ival)) {
+ werror (E_CONST_EXPECTED, "found expression");
+ // but try to do it anyway
+ }
+ allocInfo = 0;
+ if (!astErrors(ival))
+ eBBlockFromiCode (iCodeFromAst (ival));
+ allocInfo = 1;
+ }
+ }
+ sym->ival = NULL;
+ }
+
+ /* if it has an absolute address then generate
+ an equate for this no need to allocate space */
+ if (SPEC_ABSA (sym->etype))
+ {
+ char *equ="=";
+ if (options.debug) {
+ fprintf (map->oFile, " == 0x%04x\n", SPEC_ADDR (sym->etype));
+ }
+ if (TARGET_IS_XA51) {
+ if (map==sfr) {
+ equ="sfr";
+ } else if (map==bit || map==sfrbit) {
+ equ="bit";
+ }
+ }
+ fprintf (map->oFile, "%s\t%s\t0x%04x\n",
+ sym->rname, equ,
+ SPEC_ADDR (sym->etype));
+ }
+ else {
+ int size = getAllocSize (sym->type);
+ if (size==0) {
+ werrorfl (sym->fileDef, sym->lineDef, E_UNKNOWN_SIZE, sym->name);
+ }
+ /* allocate space */
+ if (options.debug) {
+ fprintf (map->oFile, "==.\n");
+ }
+ if (IS_STATIC (sym->etype))
+ tfprintf (map->oFile, "!slabeldef\n", sym->rname);
+ else
+ tfprintf (map->oFile, "!labeldef\n", sym->rname);
+ tfprintf (map->oFile, "\t!ds\n",
+ (unsigned int) size & 0xffff);
+ }