+
+/*-----------------------------------------------------------------*/
+/* printAllocInfoSeg- print the allocation for a given section */
+/*-----------------------------------------------------------------*/
+static void printAllocInfoSeg ( memmap *map, symbol *func, FILE *of)
+{
+ symbol *sym;
+
+ if (!map) return;
+ if (!map->syms) return;
+
+ for (sym = setFirstItem(map->syms); sym;
+ sym = setNextItem(map->syms)) {
+
+ if (sym->level == 0) continue;
+ if (sym->localof != func) continue ;
+ fprintf(of,";%-25s Allocated to ",sym->name);
+
+ /* if assigned to registers */
+ if (!sym->allocreq && sym->reqv) {
+ int i;
+ sym = OP_SYMBOL(sym->reqv);
+ fprintf(of,"registers ");
+ for (i = 0 ; i < 4 && sym->regs[i] ; i++)
+ fprintf(of,"%s ",port->getRegName(sym->regs[i]));
+ fprintf(of,"\n");
+ continue ;
+ }
+
+ /* if on stack */
+ if (sym->onStack) {
+ fprintf(of,"stack - offset %d\n",sym->stack);
+ continue;
+ }
+
+ /* otherwise give rname */
+ fprintf(of,"in memory with name '%s'\n",sym->rname);
+ }
+}
+
+/*-----------------------------------------------------------------*/
+/* canOverlayLocals - returns true if the local variables can overlayed */
+/*-----------------------------------------------------------------*/
+static bool canOverlayLocals (eBBlock **ebbs, int count)
+{
+ int i;
+ /* if staticAuto is in effect or the current function
+ being compiled is reentrant or the overlay segment
+ is empty or no overlay option is in effect then */
+ if (options.noOverlay ||
+ options.stackAuto ||
+ (currFunc &&
+ (IS_RENT(currFunc->etype) ||
+ IS_ISR(currFunc->etype))) ||
+ elementsInSet(overlay->syms) == 0)
+
+ return FALSE;
+
+ /* otherwise do thru the blocks and see if there
+ any function calls if found then return false */
+ for (i = 0; i < count ; i++ ) {
+ iCode *ic;
+
+ for (ic = ebbs[i]->sch; ic ; ic = ic->next)
+ if (ic && ( ic->op == CALL || ic->op == PCALL))
+ return FALSE;
+ }
+
+ /* no function calls found return TRUE */
+ return TRUE;
+}
+
+/*-----------------------------------------------------------------*/
+/* doOverlays - move the overlay segment to appropriate location */
+/*-----------------------------------------------------------------*/
+void doOverlays( eBBlock **ebbs, int count)
+{
+ /* check if the parameters and local variables
+ of this function can be put in the overlay segment
+ This check is essentially to see if the function
+ calls any other functions if yes then we cannot
+ overlay */
+ if (canOverlayLocals(ebbs,count))
+ /* if we can then put the parameters &
+ local variables in the overlay set */
+ overlay2Set();
+ else
+ /* otherwise put them into data where
+ they belong */
+ overlay2data();
+}
+
+/*-----------------------------------------------------------------*/
+/* printAllocInfo - prints allocation information for a function */
+/*-----------------------------------------------------------------*/
+void printAllocInfo( symbol * func, FILE *of)
+{
+ 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);
+}