From: vrokas Date: Sat, 30 Oct 2004 11:15:15 +0000 (+0000) Subject: * doc/sdccman.lyx: updated SDCC version, X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=62545f9d9b181697e88bff60ef297132b6eee4f6;p=fw%2Fsdcc * doc/sdccman.lyx: updated SDCC version, * (PIC16 port): update list of command line options, * src/pic16/device.h (structure pic16_options_t): added field gstack to enable stack overflow tracing on push/pops, * src/pic16/device.c (statistics structure): added statistics structure, * (pic16_dump_access, pic16_dump_usection, pic16_dump_gsection, pic16_dump_int_registers): increase statistics counters for each * variable which is encountered * (pic16_dump_usection): emit each .udata variable to its own udata section, * src/pic16/gen.c (assignResultValue, genCall, genPcall, genFunction): when macro USE_WREG_IN_FUNC_PARAMS is set to 0 pass all function parameters via stack, otherwise use old scheme, * src/pic16/glue.c (pic16_emitStatistics): dump statistics in assembler output file, * src/pic16/main.c: added command line options --gstack to enable push/pop tracing for stack overflow, * src/pic16/pcode.c (all pCodeInstruction records for PIC18F instructions): added size of each instruction, * (pic16_countInstruction): estimate size of instructions in the_pFile list, inline assembly blocks are not counted, * (pic16_FixRegisterBanking): trace previous register usage, when banksel optimizations is greater than 0, don't emit a redudant banksel directive, git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@3563 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/ChangeLog b/ChangeLog index 52e32eb5..d545400f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,31 @@ +2004-10-30 Vangelis Rokas + + * doc/sdccman.lyx: updated SDCC version, + * (PIC16 port): update list of command line options, + * src/pic16/device.h (structure pic16_options_t): added field gstack + to enable stack overflow tracing on push/pops, + * src/pic16/device.c (statistics structure): added statistics + structure, + * (pic16_dump_access, pic16_dump_usection, pic16_dump_gsection, + pic16_dump_int_registers): increase statistics counters for each + * variable which is encountered + * (pic16_dump_usection): emit each .udata variable to its own udata + section, + * src/pic16/gen.c (assignResultValue, genCall, genPcall, genFunction): + when macro USE_WREG_IN_FUNC_PARAMS is set to 0 pass all function + parameters via stack, otherwise use old scheme, + * src/pic16/glue.c (pic16_emitStatistics): dump statistics in + assembler output file, + * src/pic16/main.c: added command line options --gstack to enable + push/pop tracing for stack overflow, + * src/pic16/pcode.c (all pCodeInstruction records for PIC18F + instructions): added size of each instruction, + * (pic16_countInstruction): estimate size of instructions in + the_pFile list, inline assembly blocks are not counted, + * (pic16_FixRegisterBanking): trace previous register usage, when + banksel optimizations is greater than 0, don't emit a redudant + banksel directive, + 2004-10-26 Slade Rich * src/pic/ralloc.c : fixed inefficient code produced when compiling a complimented bit operation. diff --git a/doc/sdccman.lyx b/doc/sdccman.lyx index 6ff9b92a..5a54930d 100644 --- a/doc/sdccman.lyx +++ b/doc/sdccman.lyx @@ -83,7 +83,7 @@ SDCC Compiler User Guide \size normal -SDCC 2.4.5 +SDCC 2.4.6 \size footnotesize \newline @@ -15265,41 +15265,6 @@ status Collapsed / \end_inset --stack-auto Auto variables that are function parameters, will be saved on - stack by default. - -\emph on -There is no need to specify this in the command line. -\layout List -\labelwidthstring 00.00.0000 - -- -\begin_inset ERT -status Collapsed - -\layout Standard - -\backslash -/ -\end_inset - --float-reent All floating point functions are reentrant by default. - -\emph on -There is no need to specifiy this in the command line. -\layout List -\labelwidthstring 00.00.0000 - -- -\begin_inset ERT -status Collapsed - -\layout Standard - -\backslash -/ -\end_inset - -callee-saves See - \begin_inset ERT status Collapsed @@ -15374,8 +15339,32 @@ status Collapsed / \end_inset --pgen-bank Instructs the port to insert BANKSEL directives before instructions - that use the Bank Select Register (BSR). +-nodefaultlibs do not link default libraries when linking. +\layout List +\labelwidthstring 00.00.0000 + +- +\begin_inset ERT +status Collapsed + +\layout Standard + +\backslash +/ +\end_inset + +-obanksel=# Set optimization level for inserting BANKSELs. +\begin_deeper +\layout List +\labelwidthstring 00.00.0000 + +0 is no optimization +\layout List +\labelwidthstring 00.00.0000 + +1 checkes previous used register and if it is the same then doesn't emit + BANKSEL, accounts only for labels. +\end_deeper \layout List \labelwidthstring 00.00.0000 @@ -15389,8 +15378,7 @@ status Collapsed / \end_inset --pomit-config-words Instructs the port to omit the generation of the configurati -on words. +-pomit-config-words Omit the generation of the configuration words. \layout List \labelwidthstring 00.00.0000 @@ -15404,7 +15392,7 @@ status Collapsed / \end_inset --pomit-ivt Instructs the port to omit the generation of the interrupt vectors +-pomit-ivt Omit the generation of the interrupt vectors. \layout List \labelwidthstring 00.00.0000 @@ -15418,8 +15406,17 @@ status Collapsed / \end_inset --pleave-reset-vector Used in conjuction with the previous command, instructs - the port NOT to omit the reset vector. +-pleave-reset-vector Used in conjuction with - +\begin_inset ERT +status Collapsed + +\layout Standard + +\backslash +/ +\end_inset + +-pomit-ivt, instructs the port NOT to omit the reset vector. \layout List \labelwidthstring 00.00.0000 @@ -15516,6 +15513,78 @@ status Collapsed \end_inset -link= sets the full path and name of an external linker to call. +\layout List +\labelwidthstring 00.00.0000 + +- +\begin_inset ERT +status Collapsed + +\layout Standard + +\backslash +/ +\end_inset + +-call-tree dump call tree in .calltree file +\layout List +\labelwidthstring 00.00.0000 + +- +\begin_inset ERT +status Collapsed + +\layout Standard + +\backslash +/ +\end_inset + +-mplab-comp MPLAB compatibility option. + Currently only suppresses special gpasm directives. +\layout List +\labelwidthstring 00.00.0000 + +- +\begin_inset ERT +status Collapsed + +\layout Standard + +\backslash +/ +\end_inset + +-use-crt= Use a custom run-time module instead of the defaults. +\layout List +\labelwidthstring 00.00.0000 + +- +\begin_inset ERT +status Collapsed + +\layout Standard + +\backslash +/ +\end_inset + +-no-crt Don't link the default run-time modules +\layout List +\labelwidthstring 00.00.0000 + +- +\begin_inset ERT +status Collapsed + +\layout Standard + +\backslash +/ +\end_inset + +-flr-support When entering/leaving a function, call support functions to + store/restore used registers \layout Subsubsection Debugging Options @@ -15581,6 +15650,35 @@ status Collapsed \end_inset -pcode-verbose Enable pcode debugging information in translation. +\layout List +\labelwidthstring 00.00.0000 + +- +\begin_inset ERT +status Collapsed + +\layout Standard + +\backslash +/ +\end_inset + +-denable-peeps Force the usage of peepholes. + Use with care. +\layout List +\labelwidthstring 00.00.0000 + +- +\begin_inset ERT +status Collapsed + +\layout Standard + +\backslash +/ +\end_inset + +-gstack Trace push/pops for stack pointer overflow \layout Subsection Preprocessor Macros @@ -15820,6 +15918,21 @@ Example: \layout List \labelwidthstring 00.00.0000 +code place a function symbol at static FLASH address +\layout LyX-Code + +Example: +\layout LyX-Code + +\layout LyX-Code + +/* place function test_func at 0x4000 */ +\layout LyX-Code + +#pragma code test_func 0x4000 +\layout List +\labelwidthstring 00.00.0000 + udata pragma udata instructs the compiler to emit code so that linker will place a variable at a specific memory bank \layout LyX-Code diff --git a/src/pic16/NOTES b/src/pic16/NOTES index 33ec60ea..4c6e5b14 100644 --- a/src/pic16/NOTES +++ b/src/pic16/NOTES @@ -18,6 +18,13 @@ Scott Dattalo ====================================================================== ====================================================================== +2004-Oct-29 Vangelis Rokas +1. Function parameters are passed now all via stack. This might +lower performance, but some issues are solved this way. Later +we can enable passing through WREG,PRODL,PRODH,FSR0L by implementing +specific pragmas + + 2004-Sep-27 Vangelis Rokas 1. Function parameters have been extended to cover functions with variable arguments. Now function parameters follow the rules below: diff --git a/src/pic16/device.c b/src/pic16/device.c index 737336e8..9420f969 100644 --- a/src/pic16/device.c +++ b/src/pic16/device.c @@ -461,6 +461,8 @@ static PIC16_device Pics16[] = { static int num_of_supported_PICS = sizeof(Pics16)/sizeof(PIC16_device); +stats_t statistics = { 0, 0, 0, 0 }; + #define DEFAULT_PIC "452" PIC16_device *pic16=NULL; @@ -514,6 +516,7 @@ void pic16_dump_access(FILE *of, set *section) fprintf(of, "\tudata_acs\n"); for(; r; r = setNextItem(section)) { fprintf(of, "%s\tres\t%d\n", r->name, r->size); + statistics.adsize += r->size; } } @@ -582,10 +585,21 @@ void pic16_dump_usection(FILE *of, set *section, int fix) qsort(rlist, i /*elementsInSet(section)*/, sizeof(regs *), regCompare); if(!fix) { + +#define EMIT_SINGLE_UDATA_SECTION 0 +#if EMIT_SINGLE_UDATA_SECTION fprintf(of, "\n\n\tudata\n"); for(r = setFirstItem(section); r; r = setNextItem(section)) { fprintf(of, "%s\tres\t%d\n", r->name, r->size); + statistics.udsize += r->size; + } +#else + for(r = setFirstItem(section); r; r = setNextItem(section)) { + fprintf(of, "\nudata_%s_%s\tudata\n", moduleName, r->name); + fprintf(of, "%s\tres\t%d\n", r->name, r->size); + statistics.udsize += r->size; } +#endif } else { unsigned int j=0; int deb_addr=0; @@ -611,6 +625,7 @@ void pic16_dump_usection(FILE *of, set *section, int fix) } else { fprintf(of, "%s\tres\t%d\n", r->name, r->size); deb_addr += r->size; + statistics.udsize += r->size; } rprev = r; @@ -634,6 +649,7 @@ void pic16_dump_gsection(FILE *of, set *sections) r->name, sname->name, sname); #endif fprintf(of, "%s\tres\t%d\n", r->name, r->size); + statistics.udsize += r->size; } } } @@ -752,8 +768,10 @@ void pic16_dump_int_registers(FILE *of, set *section) fprintf(of, "\n\n; Internal registers\n"); fprintf(of, "%s\tudata_ovr\t0x0000\n", ".registers"); - for(r = setFirstItem(section); r; r = setNextItem(section)) + for(r = setFirstItem(section); r; r = setNextItem(section)) { fprintf(of, "%s\tres\t%d\n", r->name, r->size); + statistics.intsize += r->size; + } free(rlist); } diff --git a/src/pic16/device.h b/src/pic16/device.h index f6033055..2906d7bb 100644 --- a/src/pic16/device.h +++ b/src/pic16/device.h @@ -103,6 +103,7 @@ typedef struct { int no_crt; int ip_stack; unsigned long opt_flags; + int gstack; } pic16_options_t; #define STACK_MODEL_SMALL (pic16_options.stack_model == 0) @@ -111,6 +112,16 @@ typedef struct { extern set *fix_idataSymSet; extern set *rel_idataSymSet; +typedef struct { + unsigned long isize; + unsigned long adsize; + unsigned long udsize; + unsigned long idsize; + unsigned long intsize; +} stats_t; + +extern stats_t statistics; + extern pic16_options_t pic16_options; extern PIC16_device *pic16; diff --git a/src/pic16/gen.c b/src/pic16/gen.c index 159eeb8b..ee1c04d4 100644 --- a/src/pic16/gen.c +++ b/src/pic16/gen.c @@ -94,6 +94,11 @@ static bool is_LitAOp(asmop *aop); #define BYTEofLONG(l,b) ( (l>> (b<<3)) & 0xff) +/* set the following macro to 1 to enable passing the + * first byte of functions parameters via WREG */ +#define USE_WREG_IN_FUNC_PARAMS 0 + + /* this is the down and dirty file with all kinds of kludgy & hacky stuff. This is what it is all about CODE GENERATION for a specific MCU . some of the @@ -2770,7 +2775,7 @@ void pic16_loadFromReturn(operand *op, int offset, pCodeOp *src) /*-----------------------------------------------------------------*/ /* assignResultValue - assign results to oper, rescall==1 is */ -/* called from genCall() or genPCall() */ +/* called from genCall() or genPcall() */ /*-----------------------------------------------------------------*/ static void assignResultValue(operand * oper, int rescall) { @@ -2828,6 +2833,7 @@ static void assignResultValue(operand * oper, int rescall) } else { int areg = 0; /* matching argument register */ + debugf("_G.useWreg = %d\n", _G.useWreg); areg = SPEC_ARGREG( OP_SYM_ETYPE( oper ) ) - 1; @@ -3060,8 +3066,9 @@ static void genCall (iCode *ic) if (_G.sendSet) { iCode *sic; int psuedoStkPtr=-1; +#if USE_WREG_IN_FUNC_PARAMS int firstTimeThruLoop = 1; - +#endif #if 1 /* reverse sendSet if function is not reentrant */ @@ -3085,13 +3092,17 @@ static void genCall (iCode *ic) use_wreg = 0; for (sic = setFirstItem(_G.sendSet) ; sic ; sic = setNextItem(_G.sendSet)) { - int size, offset = 0; - + int size; +#if USE_WREG_IN_FUNC_PARAMS + int offset = 0; +#endif pic16_aopOp(IC_LEFT(sic),sic,FALSE); size = AOP_SIZE(IC_LEFT(sic)); stackParms += size; + /* set the following to 1 to enable passing arguments via WREG */ +#if USE_WREG_IN_FUNC_PARAMS while (size--) { DEBUGpic16_emitcode ("; ","%d left %s",__LINE__, pic16_AopType(AOP_TYPE(IC_LEFT(sic)))); @@ -3105,6 +3116,7 @@ static void genCall (iCode *ic) pushw(); // --psuedoStkPtr; // sanity check + use_wreg = 1; } firstTimeThruLoop=0; @@ -3113,13 +3125,27 @@ static void genCall (iCode *ic) offset++; } +#else + /* all arguments are passed via stack */ + while (size--) { + DEBUGpic16_emitcode ("; ","%d left %s",__LINE__, + pic16_AopType(AOP_TYPE(IC_LEFT(sic)))); + DEBUGpic16_emitcode("; ", "push %d", psuedoStkPtr-1); + + mov2w (AOP(IC_LEFT(sic)), size); + pushw(); + } +#endif + pic16_freeAsmop (IC_LEFT(sic),NULL,sic,TRUE); } +#if USE_WREG_IN_FUNC_PARAMS /* save last parameter to stack if functions has varargs */ if(IFFUNC_HASVARARGS(ftype) || IFFUNC_ISREENT(ftype))pushw(); else use_wreg = 1; /* last parameter in WREG */ - +#endif + _G.stackRegSet = _G.sendSet; _G.sendSet = NULL; } @@ -3151,7 +3177,7 @@ static void genCall (iCode *ic) } stackParms -= use_wreg; - + if(stackParms>0) { if(stackParms == 1) { pic16_emitpcode(POC_INCF, pic16_popCopyReg(&pic16_pc_fsr1l)); @@ -3193,9 +3219,9 @@ static void genPcall (iCode *ic) { sym_link *ftype; int stackParms=0; + int use_wreg=0; symbol *retlbl = newiTempLabel(NULL); pCodeOp *pcop_lbl = pic16_popGetLabel(retlbl->key); - int use_wreg=0; DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__); @@ -3205,7 +3231,9 @@ static void genPcall (iCode *ic) if (_G.sendSet) { iCode *sic; int psuedoStkPtr=-1; +#if USE_WREG_IN_FUNC_PARAMS int firstTimeThruLoop = 1; +#endif /* For the Pic port, there is no data stack. * So parameters passed to functions are stored @@ -3232,12 +3260,16 @@ static void genPcall (iCode *ic) stackParms = 0; for (sic = setFirstItem(_G.sendSet) ; sic ; sic = setNextItem(_G.sendSet)) { - int size, offset = 0; + int size; +#if USE_WREG_IN_FUNC_PARAMS + int offset = 0; +#endif pic16_aopOp(IC_LEFT(sic),sic,FALSE); size = AOP_SIZE(IC_LEFT(sic)); stackParms += size; +#if USE_WREG_IN_FUNC_PARAMS while (size--) { DEBUGpic16_emitcode ("; ","%d left %s",__LINE__, pic16_AopType(AOP_TYPE(IC_LEFT(sic)))); @@ -3256,16 +3288,28 @@ static void genPcall (iCode *ic) firstTimeThruLoop=0; mov2w (AOP(IC_LEFT(sic)), size); + use_wreg = 1; offset++; } +#else + while (size--) { + DEBUGpic16_emitcode ("; ","%d left %s",__LINE__, + pic16_AopType(AOP_TYPE(IC_LEFT(sic)))); + DEBUGpic16_emitcode("; ", "push %d", psuedoStkPtr-1); + mov2w (AOP(IC_LEFT(sic)), size); + pushw(); + } +#endif pic16_freeAsmop (IC_LEFT(sic),NULL,sic,TRUE); } +#if USE_WREG_IN_FUNC_PARAMS if(IFFUNC_HASVARARGS(ftype) || IFFUNC_ISREENT(ftype))pushw(); else use_wreg = 1; /* last parameter in WREG */ +#endif _G.stackRegSet = _G.sendSet; _G.sendSet = NULL; @@ -3539,9 +3583,13 @@ static void genFunction (iCode *ic) pic16_emitpcode(POC_DECF, pic16_popCopyReg(&pic16_pc_fsr1h)); } +#if USE_WREG_IN_FUNC_PARAMS if(IFFUNC_HASVARARGS(sym->type) || IFFUNC_ISREENT(sym->type)) _G.useWreg = 0; else _G.useWreg = 1; +#else + _G.useWreg = 0; +#endif /* if callee-save to be used for this function * then save the registers being used in this function */ @@ -11741,6 +11789,7 @@ static void genAssign (iCode *ic) } else if (AOP_TYPE(right) == AOP_CRY) { pic16_emitpcode(POC_CLRF, pic16_popGet(AOP(result),offset)); if(offset == 0) { + debugf("%s: BTFSS offset == 0\n", __FUNCTION__); pic16_emitpcode(POC_BTFSS, pic16_popGet(AOP(right),0)); pic16_emitpcode(POC_INCF, pic16_popGet(AOP(result),0)); } diff --git a/src/pic16/glue.c b/src/pic16/glue.c index 56e458b0..f4087a6f 100644 --- a/src/pic16/glue.c +++ b/src/pic16/glue.c @@ -59,7 +59,9 @@ extern char *iComments1; extern char *iComments2; extern int initsfpnt; +extern unsigned long pFile_isize; +extern unsigned long pic16_countInstructions(); set *rel_idataSymSet=NULL; set *fix_idataSymSet=NULL; @@ -1600,6 +1602,23 @@ pic16emitOverlay (FILE * afile) } } +void emitStatistics(FILE *asmFile) +{ + statistics.isize = pic16_countInstructions(); + + fprintf (asmFile, "\n\n; Statistics:\n"); + fprintf (asmFile, "; code size:\t%ld (0x%lx) bytes\n;\t\t%ld (0x%lx) words\n", + statistics.isize, statistics.isize, + statistics.isize>>1, statistics.isize>>1); + fprintf (asmFile, "; udata size:\t%ld (0x%lx) bytes\n", + statistics.udsize, statistics.udsize); + fprintf (asmFile, "; access size:\t%ld (0x%lx) bytes\n", + statistics.intsize, statistics.intsize); + + fprintf (asmFile, "\n\n"); +} + + /*-----------------------------------------------------------------*/ /* glue - the final glue that hold the whole thing together */ @@ -1817,6 +1836,8 @@ pic16glue () pic16_copypCode(asmFile, 'P'); + emitStatistics(asmFile); + fprintf (asmFile,"\tend\n"); fclose (asmFile); diff --git a/src/pic16/main.c b/src/pic16/main.c index c24466af..4667a303 100644 --- a/src/pic16/main.c +++ b/src/pic16/main.c @@ -298,7 +298,6 @@ _process_pragma(const char *sz) #define OFMSG_LRSUPPORT "--flr-support" - char *alt_asm=NULL; char *alt_link=NULL; @@ -337,6 +336,7 @@ OPTION pic16_optionsTable[]= { { 0, NL_OPT, NULL, "new line, \"lf\" or \"crlf\""}, { 0, USE_CRT, NULL, "use run-time initialization module"}, { 0, "--no-crt", &pic16_options.no_crt, "do not link any default run-time initialization module"}, + { 0, "--gstack", &pic16_options.gstack, "trace stack pointer push/pop to overflow"}, { 0, OFMSG_LRSUPPORT, NULL, "use support functions for local register store/restore"}, { 0, NULL, NULL, NULL} }; @@ -623,6 +623,7 @@ _pic16_setDefaultOptions (void) pic16_options.crt_name = "crt0i.o"; /* the default crt to link */ pic16_options.no_crt = 0; /* use crt by default */ pic16_options.ip_stack = 1; /* set to 1 to enable ipop/ipush for stack */ + pic16_options.gstack = 0; } static const char * diff --git a/src/pic16/pcode.c b/src/pic16/pcode.c index 38abb360..ae9caeb1 100644 --- a/src/pic16/pcode.c +++ b/src/pic16/pcode.c @@ -194,6 +194,7 @@ pCodeInstruction pic16_pciADDWF = { genericPrint}, POC_ADDWF, "ADDWF", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -221,6 +222,7 @@ pCodeInstruction pic16_pciADDFW = { genericPrint}, POC_ADDFW, "ADDWF", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -248,6 +250,7 @@ pCodeInstruction pic16_pciADDWFC = { // mdubuc - New genericPrint}, POC_ADDWFC, "ADDWFC", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -275,6 +278,7 @@ pCodeInstruction pic16_pciADDFWC = { genericPrint}, POC_ADDFWC, "ADDWFC", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -302,6 +306,7 @@ pCodeInstruction pic16_pciADDLW = { genericPrint}, POC_ADDLW, "ADDLW", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -329,6 +334,7 @@ pCodeInstruction pic16_pciANDLW = { genericPrint}, POC_ANDLW, "ANDLW", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -356,6 +362,7 @@ pCodeInstruction pic16_pciANDWF = { genericPrint}, POC_ANDWF, "ANDWF", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -383,6 +390,7 @@ pCodeInstruction pic16_pciANDFW = { genericPrint}, POC_ANDFW, "ANDWF", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -409,6 +417,7 @@ pCodeInstruction pic16_pciBC = { // mdubuc - New genericPrint}, POC_BC, "BC", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -436,6 +445,7 @@ pCodeInstruction pic16_pciBCF = { genericPrint}, POC_BCF, "BCF", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -463,6 +473,7 @@ pCodeInstruction pic16_pciBN = { // mdubuc - New genericPrint}, POC_BN, "BN", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -490,6 +501,7 @@ pCodeInstruction pic16_pciBNC = { // mdubuc - New genericPrint}, POC_BNC, "BNC", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -517,6 +529,7 @@ pCodeInstruction pic16_pciBNN = { // mdubuc - New genericPrint}, POC_BNN, "BNN", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -544,6 +557,7 @@ pCodeInstruction pic16_pciBNOV = { // mdubuc - New genericPrint}, POC_BNOV, "BNOV", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -571,6 +585,7 @@ pCodeInstruction pic16_pciBNZ = { // mdubuc - New genericPrint}, POC_BNZ, "BNZ", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -598,6 +613,7 @@ pCodeInstruction pic16_pciBOV = { // mdubuc - New genericPrint}, POC_BOV, "BOV", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -625,6 +641,7 @@ pCodeInstruction pic16_pciBRA = { // mdubuc - New genericPrint}, POC_BRA, "BRA", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -652,6 +669,7 @@ pCodeInstruction pic16_pciBSF = { genericPrint}, POC_BSF, "BSF", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -679,6 +697,7 @@ pCodeInstruction pic16_pciBTFSC = { genericPrint}, POC_BTFSC, "BTFSC", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -706,6 +725,7 @@ pCodeInstruction pic16_pciBTFSS = { genericPrint}, POC_BTFSS, "BTFSS", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -733,6 +753,7 @@ pCodeInstruction pic16_pciBTG = { // mdubuc - New genericPrint}, POC_BTG, "BTG", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -760,6 +781,7 @@ pCodeInstruction pic16_pciBZ = { // mdubuc - New genericPrint}, POC_BZ, "BZ", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -787,6 +809,7 @@ pCodeInstruction pic16_pciCALL = { genericPrint}, POC_CALL, "CALL", + 4, NULL, // from branch NULL, // to branch NULL, // label @@ -814,6 +837,7 @@ pCodeInstruction pic16_pciCOMF = { genericPrint}, POC_COMF, "COMF", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -841,6 +865,7 @@ pCodeInstruction pic16_pciCOMFW = { genericPrint}, POC_COMFW, "COMF", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -868,6 +893,7 @@ pCodeInstruction pic16_pciCLRF = { genericPrint}, POC_CLRF, "CLRF", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -895,6 +921,7 @@ pCodeInstruction pic16_pciCLRWDT = { genericPrint}, POC_CLRWDT, "CLRWDT", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -922,6 +949,7 @@ pCodeInstruction pic16_pciCPFSEQ = { // mdubuc - New genericPrint}, POC_CPFSEQ, "CPFSEQ", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -949,6 +977,7 @@ pCodeInstruction pic16_pciCPFSGT = { // mdubuc - New genericPrint}, POC_CPFSGT, "CPFSGT", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -976,6 +1005,7 @@ pCodeInstruction pic16_pciCPFSLT = { // mdubuc - New genericPrint}, POC_CPFSLT, "CPFSLT", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -1003,6 +1033,7 @@ pCodeInstruction pic16_pciDAW = { genericPrint}, POC_DAW, "DAW", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -1030,6 +1061,7 @@ pCodeInstruction pic16_pciDCFSNZ = { // mdubuc - New genericPrint}, POC_DCFSNZ, "DCFSNZ", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -1057,6 +1089,7 @@ pCodeInstruction pic16_pciDCFSNZW = { // mdubuc - New genericPrint}, POC_DCFSNZW, "DCFSNZ", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -1084,6 +1117,7 @@ pCodeInstruction pic16_pciDECF = { genericPrint}, POC_DECF, "DECF", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -1111,6 +1145,7 @@ pCodeInstruction pic16_pciDECFW = { genericPrint}, POC_DECFW, "DECF", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -1138,6 +1173,7 @@ pCodeInstruction pic16_pciDECFSZ = { genericPrint}, POC_DECFSZ, "DECFSZ", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -1165,6 +1201,7 @@ pCodeInstruction pic16_pciDECFSZW = { genericPrint}, POC_DECFSZW, "DECFSZ", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -1192,6 +1229,7 @@ pCodeInstruction pic16_pciGOTO = { genericPrint}, POC_GOTO, "GOTO", + 4, NULL, // from branch NULL, // to branch NULL, // label @@ -1219,6 +1257,7 @@ pCodeInstruction pic16_pciINCF = { genericPrint}, POC_INCF, "INCF", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -1246,6 +1285,7 @@ pCodeInstruction pic16_pciINCFW = { genericPrint}, POC_INCFW, "INCF", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -1273,6 +1313,7 @@ pCodeInstruction pic16_pciINCFSZ = { genericPrint}, POC_INCFSZ, "INCFSZ", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -1300,6 +1341,7 @@ pCodeInstruction pic16_pciINCFSZW = { genericPrint}, POC_INCFSZW, "INCFSZ", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -1327,6 +1369,7 @@ pCodeInstruction pic16_pciINFSNZ = { // mdubuc - New genericPrint}, POC_INFSNZ, "INFSNZ", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -1354,6 +1397,7 @@ pCodeInstruction pic16_pciINFSNZW = { // vrokas - New genericPrint}, POC_INFSNZW, "INFSNZ", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -1381,6 +1425,7 @@ pCodeInstruction pic16_pciIORWF = { genericPrint}, POC_IORWF, "IORWF", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -1408,6 +1453,7 @@ pCodeInstruction pic16_pciIORFW = { genericPrint}, POC_IORFW, "IORWF", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -1435,6 +1481,7 @@ pCodeInstruction pic16_pciIORLW = { genericPrint}, POC_IORLW, "IORLW", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -1462,6 +1509,7 @@ pCodeInstruction pic16_pciLFSR = { // mdubuc - New genericPrint}, POC_LFSR, "LFSR", + 4, NULL, // from branch NULL, // to branch NULL, // label @@ -1489,6 +1537,7 @@ pCodeInstruction pic16_pciMOVF = { genericPrint}, POC_MOVF, "MOVF", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -1516,6 +1565,7 @@ pCodeInstruction pic16_pciMOVFW = { genericPrint}, POC_MOVFW, "MOVF", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -1543,6 +1593,7 @@ pCodeInstruction pic16_pciMOVFF = { // mdubuc - New genericPrint}, POC_MOVFF, "MOVFF", + 4, NULL, // from branch NULL, // to branch NULL, // label @@ -1569,6 +1620,7 @@ pCodeInstruction pic16_pciMOVLB = { // mdubuc - New genericPrint}, POC_MOVLB, "MOVLB", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -1595,6 +1647,7 @@ pCodeInstruction pic16_pciMOVLW = { genericPrint}, POC_MOVLW, "MOVLW", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -1622,6 +1675,7 @@ pCodeInstruction pic16_pciMOVWF = { genericPrint}, POC_MOVWF, "MOVWF", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -1648,6 +1702,7 @@ pCodeInstruction pic16_pciMULLW = { // mdubuc - New genericPrint}, POC_MULLW, "MULLW", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -1674,6 +1729,7 @@ pCodeInstruction pic16_pciMULWF = { // mdubuc - New genericPrint}, POC_MULWF, "MULWF", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -1700,6 +1756,7 @@ pCodeInstruction pic16_pciNEGF = { // mdubuc - New genericPrint}, POC_NEGF, "NEGF", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -1726,6 +1783,7 @@ pCodeInstruction pic16_pciNOP = { genericPrint}, POC_NOP, "NOP", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -1752,6 +1810,7 @@ pCodeInstruction pic16_pciPOP = { // mdubuc - New genericPrint}, POC_POP, "POP", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -1778,6 +1837,7 @@ pCodeInstruction pic16_pciPUSH = { genericPrint}, POC_PUSH, "PUSH", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -1804,6 +1864,7 @@ pCodeInstruction pic16_pciRCALL = { // mdubuc - New genericPrint}, POC_RCALL, "RCALL", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -1831,6 +1892,7 @@ pCodeInstruction pic16_pciRETFIE = { genericPrint}, POC_RETFIE, "RETFIE", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -1858,6 +1920,7 @@ pCodeInstruction pic16_pciRETLW = { genericPrint}, POC_RETLW, "RETLW", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -1885,6 +1948,7 @@ pCodeInstruction pic16_pciRETURN = { genericPrint}, POC_RETURN, "RETURN", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -1911,6 +1975,7 @@ pCodeInstruction pic16_pciRLCF = { // mdubuc - New genericPrint}, POC_RLCF, "RLCF", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -1938,6 +2003,7 @@ pCodeInstruction pic16_pciRLCFW = { // mdubuc - New genericPrint}, POC_RLCFW, "RLCF", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -1965,6 +2031,7 @@ pCodeInstruction pic16_pciRLNCF = { // mdubuc - New genericPrint}, POC_RLNCF, "RLNCF", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -1991,6 +2058,7 @@ pCodeInstruction pic16_pciRLNCFW = { // mdubuc - New genericPrint}, POC_RLNCFW, "RLNCF", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -2017,6 +2085,7 @@ pCodeInstruction pic16_pciRRCF = { // mdubuc - New genericPrint}, POC_RRCF, "RRCF", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -2043,6 +2112,7 @@ pCodeInstruction pic16_pciRRCFW = { // mdubuc - New genericPrint}, POC_RRCFW, "RRCF", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -2069,6 +2139,7 @@ pCodeInstruction pic16_pciRRNCF = { // mdubuc - New genericPrint}, POC_RRNCF, "RRNCF", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -2096,6 +2167,7 @@ pCodeInstruction pic16_pciRRNCFW = { // mdubuc - New genericPrint}, POC_RRNCFW, "RRNCF", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -2123,6 +2195,7 @@ pCodeInstruction pic16_pciSETF = { // mdubuc - New genericPrint}, POC_SETF, "SETF", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -2150,6 +2223,7 @@ pCodeInstruction pic16_pciSUBLW = { genericPrint}, POC_SUBLW, "SUBLW", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -2177,6 +2251,7 @@ pCodeInstruction pic16_pciSUBFWB = { genericPrint}, POC_SUBFWB, "SUBFWB", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -2204,6 +2279,7 @@ pCodeInstruction pic16_pciSUBWF = { genericPrint}, POC_SUBWF, "SUBWF", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -2231,6 +2307,7 @@ pCodeInstruction pic16_pciSUBFW = { genericPrint}, POC_SUBFW, "SUBWF", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -2258,6 +2335,7 @@ pCodeInstruction pic16_pciSUBFWB_D1 = { // mdubuc - New genericPrint}, POC_SUBFWB_D1, "SUBFWB", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -2285,6 +2363,7 @@ pCodeInstruction pic16_pciSUBFWB_D0 = { // mdubuc - New genericPrint}, POC_SUBFWB_D0, "SUBFWB", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -2312,6 +2391,7 @@ pCodeInstruction pic16_pciSUBWFB_D1 = { // mdubuc - New genericPrint}, POC_SUBWFB_D1, "SUBWFB", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -2339,6 +2419,7 @@ pCodeInstruction pic16_pciSUBWFB_D0 = { // mdubuc - New genericPrint}, POC_SUBWFB_D0, "SUBWFB", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -2366,6 +2447,7 @@ pCodeInstruction pic16_pciSWAPF = { genericPrint}, POC_SWAPF, "SWAPF", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -2393,6 +2475,7 @@ pCodeInstruction pic16_pciSWAPFW = { genericPrint}, POC_SWAPFW, "SWAPF", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -2419,6 +2502,7 @@ pCodeInstruction pic16_pciTBLRD = { // patch 15 genericPrint}, POC_TBLRD, "TBLRD*", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -2445,6 +2529,7 @@ pCodeInstruction pic16_pciTBLRD_POSTINC = { // patch 15 genericPrint}, POC_TBLRD_POSTINC, "TBLRD*+", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -2471,6 +2556,7 @@ pCodeInstruction pic16_pciTBLRD_POSTDEC = { // patch 15 genericPrint}, POC_TBLRD_POSTDEC, "TBLRD*-", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -2497,6 +2583,7 @@ pCodeInstruction pic16_pciTBLRD_PREINC = { // patch 15 genericPrint}, POC_TBLRD_PREINC, "TBLRD+*", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -2523,6 +2610,7 @@ pCodeInstruction pic16_pciTBLWT = { // patch 15 genericPrint}, POC_TBLWT, "TBLWT*", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -2549,6 +2637,7 @@ pCodeInstruction pic16_pciTBLWT_POSTINC = { // patch 15 genericPrint}, POC_TBLWT_POSTINC, "TBLWT*+", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -2575,6 +2664,7 @@ pCodeInstruction pic16_pciTBLWT_POSTDEC = { // patch 15 genericPrint}, POC_TBLWT_POSTDEC, "TBLWT*-", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -2601,6 +2691,7 @@ pCodeInstruction pic16_pciTBLWT_PREINC = { // patch 15 genericPrint}, POC_TBLWT_PREINC, "TBLWT+*", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -2628,6 +2719,7 @@ pCodeInstruction pic16_pciTSTFSZ = { // mdubuc - New genericPrint}, POC_TSTFSZ, "TSTFSZ", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -2655,6 +2747,7 @@ pCodeInstruction pic16_pciXORWF = { genericPrint}, POC_XORWF, "XORWF", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -2682,6 +2775,7 @@ pCodeInstruction pic16_pciXORFW = { genericPrint}, POC_XORFW, "XORWF", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -2709,6 +2803,7 @@ pCodeInstruction pic16_pciXORLW = { genericPrint}, POC_XORLW, "XORLW", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -2736,6 +2831,7 @@ pCodeInstruction pic16_pciBANKSEL = { genericPrint}, POC_BANKSEL, "BANKSEL", + 2, NULL, // from branch NULL, // to branch NULL, // label @@ -3336,6 +3432,25 @@ void pic16_pcode_test(void) } } } + + +unsigned long pic16_countInstructions(void) +{ + pBlock *pb; + pCode *pc; + unsigned long isize=0; + + if(!the_pFile)return -1; + + for(pb = the_pFile->pbHead; pb; pb = pb->next) { + for(pc = pb->pcHead; pc; pc = pc->next) { + if(isPCI(pc) || isASMDIR(pc))isize += PCI(pc)->isize; + } + } + return (isize); +} + + /*-----------------------------------------------------------------*/ /* int RegCond(pCodeOp *pcop) - if pcop points to the STATUS reg- */ /* ister, RegCond will return the bit being referenced. */ @@ -3689,7 +3804,7 @@ pCode *pic16_newpCodeAsmDir(char *asdir, char *argfmt, ...) pcad->pci.pc.type = PC_ASMDIR; pcad->pci.pc.prev = pcad->pci.pc.next = NULL; pcad->pci.pc.pb = NULL; - + pcad->pci.isize = 2; pcad->pci.pc.destruct = genericDestruct; pcad->pci.pc.print = genericPrint; @@ -6661,9 +6776,18 @@ static void pic16_FixRegisterBanking(pBlock *pb) /* for each flow block, determine the register banking * requirements */ + + /* if label, then might come from other point, force banksel */ + if(isPCL(pc))prevreg = NULL; + if(!isPCI(pc))goto loop; + if(PCI(pc)->label)prevreg = NULL; + if(PCI(pc)->is2MemOp)goto loop; + + /* if goto, then force banksel */ +// if(PCI(pc)->op == POC_GOTO)prevreg = NULL; reg = pic16_getRegFromInstruction(pc); @@ -6687,6 +6811,7 @@ static void pic16_FixRegisterBanking(pBlock *pb) if(isPCI_SKIP(pc)) { // fprintf(stderr, "instruction is SKIP instruction\n"); +// prevreg = NULL; } if(reg && isACCESS_BANK(reg))goto loop; @@ -6704,15 +6829,27 @@ static void pic16_FixRegisterBanking(pBlock *pb) /* if previous instruction is a skip one, then set flag * to 2 and call insertBankSwitch */ - if(pcprev && isPCI_SKIP(pcprev))flag=2; //goto loop; + if(pcprev && isPCI_SKIP(pcprev)) { + flag=2; //goto loop +// prevreg = NULL; + } + if(pic16_options.opt_banksel>0) { + char op1[128], op2[128]; + + if(prevreg) { + strcpy(op1, pic16_get_op_from_instruction(PCI(pc))); + strcpy(op2, pic16_get_op_from_instruction(PCI(pcprev))); + if(!strcmp(op1, op2))goto loop; + } + } prevreg = reg; insertBankSwitch(flag, pc); - pcprev = pc; // fprintf(stderr, "BANK SWITCH inserted\n"); loop: + pcprev = pc; pc = pc->next; } while (pc); } diff --git a/src/pic16/pcode.h b/src/pic16/pcode.h index c3d17fd9..b169350e 100644 --- a/src/pic16/pcode.h +++ b/src/pic16/pcode.h @@ -649,6 +649,8 @@ typedef struct pCodeInstruction char const * const mnemonic; // Pointer to mnemonic string + char isize; // pCode instruction size + pBranch *from; // pCodes that execute before this one pBranch *to; // pCodes that execute after pBranch *label; // pCode instructions that have labels