From abec7f165e2cc7135a4592f9007518a435d5ec7c Mon Sep 17 00:00:00 2001 From: sandeep Date: Sun, 7 May 2000 22:41:27 +0000 Subject: [PATCH] Added print Allocation info will print the allocation information for function git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@242 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- src/SDCCglue.c | 6 ++++- src/SDCCmem.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++ src/SDCCmem.h | 2 +- src/avr/main.c | 1 + src/mcs51/gen.c | 6 ++++- src/mcs51/main.c | 1 + src/port.h | 2 ++ src/z80/main.c | 1 + 8 files changed, 77 insertions(+), 3 deletions(-) diff --git a/src/SDCCglue.c b/src/SDCCglue.c index 4920cd18..31ebf5b9 100644 --- a/src/SDCCglue.c +++ b/src/SDCCglue.c @@ -35,6 +35,7 @@ set *externs = NULL; /* Varibles that are declared as extern */ /* TODO: this should be configurable (DS803C90 uses more than 6) */ int maxInterrupts = 6; +int allocInfo = 1; extern int maxRegBank ; symbol *mainf; extern char *VersionString; @@ -228,7 +229,9 @@ static void emitRegularMap (memmap * map, bool addPublics, bool arFlag) ival = newNode ('=', newAst (EX_VALUE, symbolVal (sym)), decorateType (resolveSymbols (list2expr (sym->ival)))); codeOutFile = statsg->oFile; + allocInfo = 0; eBBlockFromiCode (iCodeFromAst (ival)); + allocInfo = 1; sym->ival = NULL; } } @@ -1048,7 +1051,8 @@ void glue () /* print the global variables in this module */ printPublics (asmFile); - printExterns (asmFile); + if (port->assembler.externGlobal) + printExterns (asmFile); /* copy the sfr segment */ fprintf (asmFile, "%s", iComments2); diff --git a/src/SDCCmem.c b/src/SDCCmem.c index a134a4d9..3ad2d92d 100644 --- a/src/SDCCmem.c +++ b/src/SDCCmem.c @@ -858,3 +858,64 @@ void redoStackOffsets () cdbSymbol(sym,cdbFile,FALSE,FALSE); } } + +/*-----------------------------------------------------------------*/ +/* 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); + } +} + +/*-----------------------------------------------------------------*/ +/* 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); +} diff --git a/src/SDCCmem.h b/src/SDCCmem.h index 54f5229a..b52eb9a3 100644 --- a/src/SDCCmem.h +++ b/src/SDCCmem.h @@ -79,5 +79,5 @@ int allocVariables (struct symbol * ); void overlay2Set ( ); void overlay2data ( ); void redoStackOffsets( ); - +void printAllocInfo (struct symbol *, FILE *); #endif diff --git a/src/avr/main.c b/src/avr/main.c index dd194986..c0f05c38 100644 --- a/src/avr/main.c +++ b/src/avr/main.c @@ -145,6 +145,7 @@ PORT avr_port = { _asmCmd, "-plosgffc", /* Options with debug */ "-plosgff", /* Options without debug */ + 0 }, { _linkCmd diff --git a/src/mcs51/gen.c b/src/mcs51/gen.c index 1b99d94b..602ffba0 100644 --- a/src/mcs51/gen.c +++ b/src/mcs51/gen.c @@ -53,6 +53,7 @@ #include "gen.h" char *aopLiteral (value *val, int offset); +extern int allocInfo; /* this is the down and dirty file with all kinds of kludgy & hacky stuff. This is what it is all about @@ -7421,6 +7422,9 @@ void gen51Code (iCode *lic) lineHead = lineCurr = NULL; + /* print the allocation information */ + if (allocInfo) + printAllocInfo( currFunc, codeOutFile); /* if debug information required */ /* if (options.debug && currFunc) { */ if (currFunc) { @@ -7656,6 +7660,6 @@ void gen51Code (iCode *lic) peepHole (&lineHead); /* now do the actual printing */ - printLine (lineHead,codeOutFile); + printLine (lineHead,codeOutFile); return; } diff --git a/src/mcs51/main.c b/src/mcs51/main.c index e480975e..2a2b8fc0 100644 --- a/src/mcs51/main.c +++ b/src/mcs51/main.c @@ -202,6 +202,7 @@ PORT mcs51_port = { _asmCmd, "-plosgffc", /* Options with debug */ "-plosgff", /* Options without debug */ + 0 }, { _linkCmd diff --git a/src/port.h b/src/port.h index fb2bc1b7..081e26db 100644 --- a/src/port.h +++ b/src/port.h @@ -30,6 +30,8 @@ typedef struct { const char *debug_opts; /** Arguments for normal assembly mode. PENDING: ignored */ const char *plain_opts; + /* print externs as global */ + int externGlobal; } assembler; /* linker related info */ diff --git a/src/z80/main.c b/src/z80/main.c index b5d1849d..c46ce7c8 100644 --- a/src/z80/main.c +++ b/src/z80/main.c @@ -260,6 +260,7 @@ PORT gbz80_port = { _gbz80_asmCmd, "-plosgff", /* Options with debug */ "-plosgff", /* Options without debug */ + 1 }, { _gbz80_linkCmd -- 2.47.2