From 93a5bd697ecc846637ce8e797e0bc3a08167aee5 Mon Sep 17 00:00:00 2001 From: vrokas Date: Sun, 12 Sep 2004 11:43:22 +0000 Subject: [PATCH] * src/pic16/device.h (pic16_options_t): added field use_crt, crt_name, no_crt, * src/pic16/genarith.c (pic16_genPlus): added an assert(0) line to catch a probable future bug, * src/pic16/gen.c: aopIdx function commented out, * (genAssign): commented out old code which used aopIdx, * src/pic16/glue.c (pic16glue): removed some legacy fragments of code, added if conditionals to take into account the --use-crt command line options, * src/pic16/main.c (pic16_optionsTable): added new command line options, --use-crt= and --no-crt, * (_pic16_linkEdit): now the proper crt object is added in the linker command line except than when --no-crt is specified, * pcode.c, * pcode.h: added some structures and functions for a new optimization scheme to compansete for instruction overhead between same iCodes, this scheme is currently under development and is not working in any way, * src/pic16/gen.c (genAnd): added patch provided by Aaron Collwell to && operator, * device/lib/pic16/startup/crt0i.c, * device/lib/pic16/startup/crt0iz.c: added global char variable __uflags to force the generation of an idata section git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@3491 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 27 ++++++++++++ device/lib/pic16/startup/crt0i.c | 3 ++ device/lib/pic16/startup/crt0iz.c | 3 ++ src/pic16/device.h | 3 ++ src/pic16/gen.c | 73 ++++++++++++++++++++++++------- src/pic16/genarith.c | 1 + src/pic16/glue.c | 36 +++++---------- src/pic16/main.c | 17 ++++++- src/pic16/pcode.c | 29 ++++++++++++ src/pic16/pcode.h | 55 ++++++++++++++++++++++- 10 files changed, 204 insertions(+), 43 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5fdf44a6..ca12662c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,30 @@ +2004-09-12 Vangelis Rokas + + * src/pic16/device.h (pic16_options_t): added field use_crt, + crt_name, no_crt, + * src/pic16/genarith.c (pic16_genPlus): added an assert(0) line to + catch a probable future bug, + * src/pic16/gen.c: aopIdx function commented out, + * (genAssign): commented out old code which used aopIdx, + * src/pic16/glue.c (pic16glue): removed some legacy fragments of + code, added if conditionals to take into account the --use-crt + command line options, + * src/pic16/main.c (pic16_optionsTable): added new command line + options, --use-crt= and --no-crt, + * (_pic16_linkEdit): now the proper crt object is added in the + linker command line except than when --no-crt is specified, + * src/pic16/pcode.c, + * src/pic16/pcode.h: added some structures and functions for a new + optimization scheme to compansete for instruction overhead between + same iCodes, this scheme is currently under development and is not + working in any way, + * src/pic16/gen.c (genAnd): added patch provided by Aaron Collwell + to && operator, + * device/lib/pic16/startup/crt0i.c, + * device/lib/pic16/startup/crt0iz.c: added global char variable + __uflags to force the generation of an idata section + + 2004-09-12 Bernhard Held * doc/Makefile, diff --git a/device/lib/pic16/startup/crt0i.c b/device/lib/pic16/startup/crt0i.c index 45e3af77..4b1751f9 100644 --- a/device/lib/pic16/startup/crt0i.c +++ b/device/lib/pic16/startup/crt0i.c @@ -21,6 +21,9 @@ extern FSR0H; extern TABLAT; extern POSTINC0; +/* global variable for forcing gplink to add _cinit section */ +char __uflags = 0; + /* external reference to the user's main routine */ extern void main (void); diff --git a/device/lib/pic16/startup/crt0iz.c b/device/lib/pic16/startup/crt0iz.c index f9105a76..ea6c7da0 100644 --- a/device/lib/pic16/startup/crt0iz.c +++ b/device/lib/pic16/startup/crt0iz.c @@ -22,6 +22,9 @@ extern TABLAT; extern POSTINC0; extern POSTDEC0; +/* global variable for forcing gplink to add _cinit section */ +char __uflags = 0; + /* external reference to the user's main routine */ extern void main (void); diff --git a/src/pic16/device.h b/src/pic16/device.h index e477ef3a..468e1823 100644 --- a/src/pic16/device.h +++ b/src/pic16/device.h @@ -100,6 +100,9 @@ typedef struct { int ivt_loc; int nodefaultlibs; int dumpcalltree; + int use_crt; + char *crt_name; + int no_crt; } pic16_options_t; #define STACK_MODEL_SMALL (pic16_options.stack_model == 0) diff --git a/src/pic16/gen.c b/src/pic16/gen.c index f39c93df..2a1b26c8 100644 --- a/src/pic16/gen.c +++ b/src/pic16/gen.c @@ -58,7 +58,7 @@ static asmop *newAsmop (short type); static pCodeOp *pic16_popRegFromString(char *str, int size, int offset, operand *op); extern pCode *pic16_newpCodeAsmDir(char *asdir, char *argfmt, ...); static void mov2w (asmop *aop, int offset); -static int aopIdx (asmop *aop, int offset); +//static int aopIdx (asmop *aop, int offset); int pic16_labelOffset=0; extern int pic16_debug_verbose; @@ -873,6 +873,7 @@ static asmop *aopForRemat (operand *op) // x symbol *sym) return aop; } +#if 0 static int aopIdx (asmop *aop, int offset) { if(!aop) @@ -884,6 +885,8 @@ static int aopIdx (asmop *aop, int offset) return aop->aopu.aop_reg[offset]->rIdx; } +#endif + /*-----------------------------------------------------------------*/ /* regsInCommon - two operands have some registers in common */ /*-----------------------------------------------------------------*/ @@ -6601,10 +6604,41 @@ static void genAnd (iCode *ic, iCode *ifx) } else { symbol *tlbl = newiTempLabel(NULL); int sizel = AOP_SIZE(left); + + /* here to add patch from Aaron */ if(size) - pic16_emitcode("setb","c"); - while(sizel--){ - if((bytelit = ((lit >> (offset*8)) & 0x0FFL)) != 0x0L){ + emitSETC; //pic16_emitcode("setb","c"); + + + while(sizel--) { + if((bytelit = ((lit >> (offset*8)) & 0x0FFL)) != 0x0L){ + + + /* patch provided by Aaron Colwell */ + if((posbit = isLiteralBit(bytelit)) != 0) { + pic16_emitpcode(((rIfx.condition) ? POC_BTFSS : POC_BTFSC ), + pic16_newpCodeOpBit(pic16_aopGet(AOP(left), + offset,FALSE, + FALSE), + (posbit-1),0, PO_GPR_REGISTER)); + + pic16_emitpcode(POC_BRA, pic16_popGetLabel(tlbl->key)); + } else { + if (bytelit == 0xff) { + /* Aaron had a MOVF instruction here, changed to MOVFW cause + * a peephole could optimize it out -- VR */ + pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(left), offset)); + } else { + pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(left), offset)); + pic16_emitpcode(POC_ANDLW, pic16_popGetLit(bytelit)); + } + + pic16_emitpcode(((rIfx.condition) ? POC_BZ : POC_BNZ), + pic16_popGetLabel(tlbl->key)); + } + +#if 0 + /* old code, left here for reference -- VR 09/2004 */ MOVA( pic16_aopGet(AOP(left),offset,FALSE,FALSE)); // byte == 2^n ? if((posbit = isLiteralBit(bytelit)) != 0) @@ -6614,22 +6648,27 @@ static void genAnd (iCode *ic, iCode *ifx) pic16_emitcode("anl","a,%s", pic16_aopGet(AOP(right),offset,FALSE,TRUE)); pic16_emitcode("jnz","%05d_DS_",tlbl->key+100); - } + } +#endif } offset++; } // bit = left & literal - if(size){ - pic16_emitcode("clr","c"); - pic16_emitcode("","%05d_DS_:",tlbl->key+100); + if(size) { + emitCLRC; + pic16_emitpLabel(tlbl->key); } // if(left & literal) - else{ - if(ifx) - jmpTrueOrFalse(ifx, tlbl); - goto release ; + else { + if(ifx) { + pic16_emitpcode(POC_BRA, pic16_popGetLabel(rIfx.lbl->key)); + pic16_emitpLabel(tlbl->key); + ifx->generated = 1; + } + goto release; } } + pic16_outBitC(result); goto release ; } @@ -10895,12 +10934,15 @@ static void genAssign (iCode *ic) +#if 0 /* VR - What is this?! */ if( AOP_TYPE(right) == AOP_DIR && (AOP_TYPE(result) == AOP_REG) && size==1) { - DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__); + DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__); if(aopIdx(AOP(result),0) == 4) { - DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__); - assert(0); + + /* this is a workaround to save value of right into wreg too, + * value of wreg is going to be used later */ + DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__); pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(right),offset)); pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(result),offset)); goto release; @@ -10908,6 +10950,7 @@ static void genAssign (iCode *ic) // assert(0); DEBUGpic16_emitcode ("; WARNING","%s %d ignoring register storage",__FUNCTION__,__LINE__); } +#endif know_W=-1; while (size--) { diff --git a/src/pic16/genarith.c b/src/pic16/genarith.c index 7af1e3f7..0fad965e 100644 --- a/src/pic16/genarith.c +++ b/src/pic16/genarith.c @@ -1085,6 +1085,7 @@ void pic16_genPlus (iCode *ic) } + assert( 0 ); // TODO: anything from here to before "release:" is probably obsolete and should be removed // when the regression tests are stable diff --git a/src/pic16/glue.c b/src/pic16/glue.c index f78f83a3..d4f90371 100644 --- a/src/pic16/glue.c +++ b/src/pic16/glue.c @@ -1617,7 +1617,8 @@ pic16glue () addSetHead(&tmpfileSet,ovrFile); pic16_pCodeInitRegisters(); - if (mainf && IFFUNC_HASBODY(mainf->type)) { + + if (pic16_options.no_crt && mainf && IFFUNC_HASBODY(mainf->type)) { pBlock *pb = pic16_newpCodeChain(NULL,'X',pic16_newpCodeCharP("; Starting pCode block")); pic16_addpBlock(pb); @@ -1774,35 +1775,16 @@ pic16glue () fprintf (asmFile, "; global & static initialisations\n"); fprintf (asmFile, "%s", iComments2); -#if 0 - /* copy over code */ - fprintf (asmFile, "%s", iComments2); - fprintf (asmFile, "\tcode\n"); - fprintf (asmFile, "%s", iComments2); -#endif - if(pic16_debug_verbose) fprintf(asmFile, "; A code from now on!\n"); pic16_copypCode(asmFile, 'A'); - if(mainf && IFFUNC_HASBODY(mainf->type)) { - fprintf(asmFile, "\tcode\n"); - fprintf(asmFile,"__sdcc_gsinit_startup:\n"); - -#if 0 - /* FIXME 8051 legacy (?!) - VR 20-Jun-2003 */ - /* if external stack is specified then the - * higher order byte of the xdatalocation is - * going into P2 and the lower order going into */ - - if (options.useXstack) { - fprintf(asmFile,";\tmov\tP2,#0x%02x\n", - (((unsigned int)options.xdata_loc) >> 8) & 0xff); - fprintf(asmFile,";\tmov\t_spx,#0x%02x\n", - (unsigned int)options.xdata_loc & 0xff); + if(pic16_options.no_crt) { + if(mainf && IFFUNC_HASBODY(mainf->type)) { + fprintf(asmFile, "\tcode\n"); + fprintf(asmFile,"__sdcc_gsinit_startup:\n"); } -#endif } // copyFile (stderr, code->oFile); @@ -1815,8 +1797,10 @@ pic16glue () pic16_copypCode(asmFile, statsg->dbName); - if (port->general.glue_up_main && mainf && IFFUNC_HASBODY(mainf->type)) { - fprintf (asmFile,"\tgoto\t__sdcc_program_startup\n"); + if(pic16_options.no_crt) { + if (port->general.glue_up_main && mainf && IFFUNC_HASBODY(mainf->type)) { + fprintf (asmFile,"\tgoto\t__sdcc_program_startup\n"); + } } diff --git a/src/pic16/main.c b/src/pic16/main.c index 67cc81e2..413a5f43 100644 --- a/src/pic16/main.c +++ b/src/pic16/main.c @@ -287,6 +287,7 @@ _process_pragma(const char *sz) #define MPLAB_COMPAT "--mplab-comp" #define NL_OPT "--nl=" +#define USE_CRT "--use-crt=" char *alt_asm=NULL; char *alt_link=NULL; @@ -324,6 +325,8 @@ OPTION pic16_optionsTable[]= { { 0, MPLAB_COMPAT, &pic16_mplab_comp, "enable compatibility mode for MPLAB utilities (MPASM/MPLINK)"}, { 0, "--fstack", &pic16_fstack, "enable stack optimizations"}, { 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, NULL, NULL, NULL} }; @@ -400,6 +403,14 @@ _pic16_parseOptions (int *pargc, char **argv, int *i) } return TRUE; } + + if(ISOPT(USE_CRT)) { + char *tmp; + + tmp = Safe_strdup( getStringArg(USE_CRT, argv, i, *pargc) ); + pic16_options.use_crt = 1; pic16_options.no_crt = 0; + pic16_options.crt_name = tmp; + } return FALSE; } @@ -475,7 +486,8 @@ static void _pic16_linkEdit(void) addSetHead(&relFilesSet, temp); } -// shash_add(&linkValues, "spec_ofiles", "crt0i.o"); + if(pic16_options.use_crt && !pic16_options.no_crt) + shash_add(&linkValues, "spec_ofiles", pic16_options.crt_name); //"crt0i.o"); shash_add(&linkValues, "ofiles", joinStrSet(relFilesSet)); shash_add(&linkValues, "libs", joinStrSet(libFilesSet)); @@ -594,6 +606,9 @@ _pic16_setDefaultOptions (void) pic16_options.ivt_loc = 0x000000; pic16_options.nodefaultlibs = 0; pic16_options.dumpcalltree = 0; + pic16_options.use_crt = 1; + pic16_options.crt_name = "crt0i"; /* the default crt to link */ + pic16_options.no_crt = 0; } static const char * diff --git a/src/pic16/pcode.c b/src/pic16/pcode.c index f4ec7207..8ed4d51e 100644 --- a/src/pic16/pcode.c +++ b/src/pic16/pcode.c @@ -3739,6 +3739,13 @@ pCode *pic16_newpCodeLabelFORCE(char *name, int key) return ( (pCode *)pcl ); } +#if 0 +pCode *pic16_newpCodeInfo(INFO_TYPE type, pCodeOp *pcop) +{ + +} +#endif + /*-----------------------------------------------------------------*/ /* newpBlock - create and return a pointer to a new pBlock */ @@ -3781,6 +3788,8 @@ pBlock *pic16_newpCodeChain(memmap *cm,char c, pCode *pc) return pB; } + + /*-----------------------------------------------------------------*/ /* pic16_newpCodeOpLabel - Create a new label given the key */ /* Note, a negative key means that the label is part of wild card */ @@ -4050,6 +4059,21 @@ pCodeOp *pic16_newpCodeOpRegFromStr(char *name) return pcop; } +/*-----------------------------------------------------------------*/ +/*-----------------------------------------------------------------*/ +pCodeOp *pic16_newpCodeOpOpt(OPT_TYPE type, char *key) +{ + pCodeOpOpt *pcop; + + pcop = Safe_calloc(1, sizeof(pCodeOpOpt)); + + pcop->type = type; + pcop->key = Safe_strdup( key ); + + return (PCOP(pcop)); +} + + /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ @@ -4758,6 +4782,11 @@ char *pic16_pCode2str(char *str, size_t size, pCode *pc) case PC_BAD: SAFE_snprintf(&s,&size,";A bad pCode is being used\n"); + break; + + case PC_INFO: + SAFE_snprintf(&s,&size,"; PC INFO pcode\n"); + break; } return str; diff --git a/src/pic16/pcode.h b/src/pic16/pcode.h index 950251b1..b9d044c1 100644 --- a/src/pic16/pcode.h +++ b/src/pic16/pcode.h @@ -300,9 +300,34 @@ typedef enum * in the pCode peep hole optimizer */ PC_CSOURCE, /* C-Source Line */ PC_ASMDIR, /* Assembler directive */ - PC_BAD /* Mark the pCode object as being bad */ + PC_BAD, /* Mark the pCode object as being bad */ + PC_INFO /* pCode informatio node, used primarily in optimizing */ } PC_TYPE; + +/*********************************************************************** + * INFO_TYPE - information node types + ***********************************************************************/ + +typedef enum +{ + INF_OPTIMIZATION, /* structure contains optimization information */ +} INFO_TYPE; + + + +/*********************************************************************** + * OPT_TYPE - optimization node types + ***********************************************************************/ + +typedef enum +{ + OPT_BEGIN, /* mark beginning of optimization block */ + OPT_END, /* mark ending of optimization block */ +} OPT_TYPE; + + + /************************************************/ /*************** Structures ********************/ /************************************************/ @@ -446,6 +471,17 @@ typedef struct pCodeOpWild } pCodeOpWild; +typedef struct pCodeOpOpt +{ + pCodeOp pcop; + + OPT_TYPE type; /* optimization node type */ + + char *key; /* key by which a block is identified */ +} pCodeOpOpt; + + + /************************************************* pCode @@ -703,6 +739,22 @@ typedef struct pCodeWild } pCodeWild; + +/************************************************* + pInfo + + Here are stored generic informaton +*************************************************/ +typedef struct pInfo +{ + pCode pc; + + INFO_TYPE type; /* info node type */ + + pCodeOp *oper1; /* info node arguments */ +} pInfo; + + /************************************************* pBlock @@ -863,6 +915,7 @@ typedef struct peepCommand { #define PCOR(x) ((pCodeOpReg *)(x)) #define PCOR2(x) ((pCodeOpReg2 *)(x)) #define PCORB(x) ((pCodeOpRegBit *)(x)) +#define PCOO(x) ((pCodeOpOpt *)(x)) #define PCOW(x) ((pCodeOpWild *)(x)) #define PCOW2(x) (PCOW(PCOW(x)->pcop2)) #define PBR(x) ((pBranch *)(x)) -- 2.30.2