+ if (max == -1 || addr > max) max = addr;
+ if (min == -1 || addr < min) min = addr;
+ //fprintf (stderr, "%s: sym %s @ 0x%x\n", __FUNCTION__, sym->name, addr);
+ aliases = hTabItemWithKey (ht, addr);
+ if (aliases) {
+ /* May not use addSetHead, as we cannot update the
+ * list's head in the hastable `ht'. */
+ addSet (&aliases, sym);
+#if 0
+ fprintf( stderr, "%s: now %d aliases for %s @ 0x%x\n",
+ __FUNCTION__, elementsInSet(aliases), sym->name, addr);
+#endif
+ } else {
+ addSet (&aliases, sym);
+ hTabAddItem (&ht, addr, aliases);
+ } // if
+ } // if
+ } // for sym
+ } // for i
+
+ /* now emit definitions for all absolute symbols */
+ fprintf (ofile, "%s", iComments2);
+ fprintf (ofile, "; absolute symbol definitions\n");
+ fprintf (ofile, "%s", iComments2);
+ for (addr=min; addr <= max; addr++)
+ {
+ size = 1;
+ aliases = hTabItemWithKey (ht, addr);
+ if (aliases && elementsInSet(aliases)) {
+ fprintf (ofile, "udata_abs_%s_%x\tudata_ovr\t0x%04x",
+ moduleName, addr, addr);
+ for (sym = setFirstItem (aliases); sym;
+ sym = setNextItem (aliases))
+ {
+ /* emit STATUS as well as _STATUS, required for SFRs only */
+ fprintf (ofile, "\n%s", sym->name);
+ fprintf (ofile, "\n%s", sym->rname);
+ if (getSize(sym->type) > size) {
+ size = getSize(sym->type);
+ }
+ } // for
+ fprintf (ofile, "\tres\t%d\n", size);
+ } // if
+ } // for i
+
+ /* also emit STK symbols
+ * XXX: This is ugly and fails as soon as devices start to get
+ * differently sized sharebanks, since STK12 will be
+ * required by larger devices but only up to STK03 might
+ * be defined using smaller devices. */
+ fprintf (ofile, "\n");
+ if (!pic14_options.isLibrarySource)
+ {
+ fprintf (ofile, "\tglobal PSAVE\n");
+ fprintf (ofile, "\tglobal SSAVE\n");
+ fprintf (ofile, "\tglobal WSAVE\n");
+ for (i=pic14_getSharebankSize()-4; i >= 0; i--) {
+ fprintf (ofile, "\tglobal STK%02d\n", i);
+ } // for i
+ fprintf (ofile, "sharebank udata_ovr 0x%04x\n",
+ pic14_getSharebankAddress() - pic14_getSharebankSize() + 1);
+ fprintf (ofile, "PSAVE\tres 1\n");
+ fprintf (ofile, "SSAVE\tres 1\n");
+ fprintf (ofile, "WSAVE\tres 1\n");
+ /* fill rest of sharebank with stack STKxx .. STK00 */
+ for (i=pic14_getSharebankSize()-4; i >= 0; i--) {
+ fprintf (ofile, "STK%02d\tres 1\n", i);
+ } // for i
+ } else {
+ /* declare STKxx as extern for all files
+ * except the one containing main() */
+ fprintf (ofile, "\textern PSAVE\n");
+ fprintf (ofile, "\textern SSAVE\n");
+ fprintf (ofile, "\textern WSAVE\n");
+ for (i=pic14_getSharebankSize()-4; i >= 0; i--) {
+ fprintf (ofile, "\textern STK%02d\n", i);
+ } // for i
+ }
+}
+
+/*-----------------------------------------------------------------*/
+/* emitRegularMap - emit code for maps with no special cases */
+/*-----------------------------------------------------------------*/
+static void
+pic14emitRegularMap (memmap * map, bool addPublics, bool arFlag)
+{
+ symbol *sym;
+ int bitvars = 0;;
+
+ /* print the area name */
+ if (addPublics)
+ fprintf (map->oFile, ";\t.area\t%s\n", map->sname);
+
+ for (sym = setFirstItem (map->syms); sym;
+ sym = setNextItem (map->syms)) {
+
+ //printf("%s\n",sym->name);
+
+ /* ignore if config word */
+ if (SPEC_ABSA(sym->etype)
+ && IS_CONFIG_ADDRESS(SPEC_ADDR(sym->etype)))
+ continue;
+
+ /* 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))
+ {
+ //fprintf( stderr, "%s: made public %s\n", __FUNCTION__, sym->name );
+ addSetHead (&publics, sym);
+ }
+
+ // PIC code allocates its own registers - so ignore parameter variable generated by processFuncArgs()
+ if (sym->_isparm)
+ continue;
+ /* if extern then do nothing or is a function
+ then do nothing */
+ if (IS_FUNC (sym->type))
+ continue;
+#if 0
+ /* print extra debug info if required */
+ if (options.debug || sym->level == 0)
+ {
+ 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);
+ }
+#endif
+ /* absolute symbols are handled in pic14_constructAbsMap */
+ if (SPEC_ABSA(sym->etype) && IS_DEFINED_HERE(sym))
+ continue;
+
+ /* if it has an absolute address then generate
+ an equate for this no need to allocate space */
+ if (0 && SPEC_ABSA (sym->etype))
+ {
+ //if (options.debug || sym->level == 0)
+ //fprintf (map->oFile,"; == 0x%04x\n",SPEC_ADDR (sym->etype));
+
+ fprintf (map->oFile, "%s\tEQU\t0x%04x\n",
+ sym->rname,
+ SPEC_ADDR (sym->etype));
+ }
+ else
+ {
+ /* allocate space */
+
+ /* If this is a bit variable, then allocate storage after 8 bits have been declared */
+ /* unlike the 8051, the pic does not have a separate bit area. So we emulate bit ram */
+ /* by grouping the bits together into groups of 8 and storing them in the normal ram. */
+ if (IS_BITVAR (sym->etype))
+ {
+ bitvars++;
+ }
+ else
+ {
+ emitSymbolToFile (map->oFile,
+ sym->rname,
+ NULL,
+ getSize (sym->type) & 0xffff,
+ SPEC_ABSA(sym->etype)
+ ? SPEC_ADDR(sym->etype)
+ : -1,
+ 0,
+ 0);
+ /*
+ {
+ int i, size;
+
+ if ((size = (unsigned int) getSize (sym->type) & 0xffff) > 1)
+ {
+ for (i = 1; i < size; i++)
+ fprintf (map->oFile, "\t%s_%d\n", sym->rname, i);
+ }
+ }
+ */
+ }
+ //fprintf (map->oFile, "\t.ds\t0x%04x\n", (unsigned int)getSize (sym->type) & 0xffff);
+ }
+
+ /* if it has a 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)), RESULT_TYPE_NONE));
+ codeOutFile = statsg->oFile;
+ GcurMemmap = statsg;
+ eBBlockFromiCode (iCodeFromAst (ival));
+ sym->ival = NULL;
+ }