From ac9ebda6996416faaf1f6ac189024acb7efbf991 Mon Sep 17 00:00:00 2001 From: tecodev Date: Fri, 15 Aug 2008 14:57:21 +0000 Subject: [PATCH] * src/z80/gen.c (_vemit2): suppress compiler warning * src/pic/*.[ch]: make proper use of header files and avoid ad-hoc extern declarations, mark module-local helpers 'static', no functional changes * src/pic16/pcode.c: disentangled from pic14 backend git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@5213 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 12 + src/pic/device.c | 164 +++++------- src/pic/device.h | 29 +- src/pic/gen.c | 248 ++++++++--------- src/pic/gen.h | 52 ++-- src/pic/genarith.c | 27 +- src/pic/glue.c | 147 +++------- src/pic/glue.h | 4 +- src/pic/main.c | 88 +++--- src/pic/main.h | 6 +- src/pic/pcode.c | 636 +++++++++++++++++++++++--------------------- src/pic/pcode.h | 52 +++- src/pic/pcodeflow.c | 19 +- src/pic/pcodeflow.h | 5 +- src/pic/pcodepeep.c | 82 +++--- src/pic/pcoderegs.c | 70 ++--- src/pic/pcoderegs.h | 8 + src/pic/ralloc.c | 114 ++++---- src/pic/ralloc.h | 17 +- src/pic16/pcode.c | 5 +- src/z80/gen.c | 6 +- 21 files changed, 838 insertions(+), 953 deletions(-) diff --git a/ChangeLog b/ChangeLog index fe77709e..972844da 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,14 @@ +2008-08-15 Raphael Neider + + * src/z80/gen.c (_vemit2): suppress compiler warning + + * src/pic/*.[ch]: make proper use of header files and avoid + ad-hoc extern declarations, mark module-local helpers 'static', + no functional changes + * src/pic16/pcode.c: disentangled from pic14 backend + 2008-08-14 Philipp Klaus Krause + * src/z80/gen.c: fixed #2051348 * support/regression/tests/bug-2051348.c: regression test for #2051348 @@ -70,9 +80,11 @@ thanks Mauro Giachero 2008-07-13 Philipp Klaus Krause + * src/port.h: Fixed typo in comment 2008-07-12 Philipp Klaus Krause + * src/z80/mappings.i: Implemented RFE #1919415 * src/z80/peeph-z80.def: Implemented RFE #1919415, #1861376, #1880202, #1914434, prepared for RFE #1703943 diff --git a/src/pic/device.c b/src/pic/device.c index 442292ef..5a5ef830 100644 --- a/src/pic/device.c +++ b/src/pic/device.c @@ -18,29 +18,21 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -------------------------------------------------------------------------*/ -#include -#include -#include - -#include "common.h" // Include everything in the SDCC src directory -#include "newalloc.h" - - -#include "main.h" -#include "pcode.h" -#include "ralloc.h" #include "device.h" -extern int Gstack_base_addr; -extern int Gstack_size; +/* + * Imports + */ +extern set *includeDirsSet; +extern set *userIncDirsSet; +extern set *libDirsSet; +extern set *libPathsSet; #define MAX_PICLIST 200 static PIC_device *Pics[MAX_PICLIST]; +static PIC_device *pic = NULL; static int num_of_supported_PICS = 0; - -static PIC_device *pic=NULL; - -int maxRAMaddress = 0; +static int maxRAMaddress = 0; #define CONFIG_WORD_ADDRESS 0x2007 #define CONFIG2_WORD_ADDRESS 0x2008 @@ -51,6 +43,8 @@ int maxRAMaddress = 0; #define PIC14_STRING_LEN 256 #define SPLIT_WORDS_MAX 16 +/* Keep track of whether we found an assignment to the __config words. */ +static int pic14_hasSetConfigWord = 0; static unsigned int config_word = DEFAULT_CONFIG_WORD; static unsigned int config2_word = DEFAULT_CONFIG2_WORD; static memRange *rangeRAM = NULL; @@ -188,10 +182,16 @@ static void ram_map(int num_words, char word[SPLIT_WORDS_MAX][PIC14_STRING_LEN]) rangeRAM = r; } -extern set *includeDirsSet; -extern set *userIncDirsSet; -extern set *libDirsSet; -extern set *libPathsSet; +static void setMaxRAM(int size) +{ + maxRAMaddress = size; + + if (maxRAMaddress < 0) { + fprintf(stderr, "invalid maxram 0x%x setting in %s\n", + maxRAMaddress, DEVICE_FILE_NAME); + return; + } +} /* read the file with all the pic14 definitions and pick out the definition * for a processor if specified. if pic_name is NULL reads everything */ @@ -411,44 +411,6 @@ static PIC_device *find_device(char *pic_name) return NULL; } -void setMaxRAM(int size) -{ - maxRAMaddress = size; - - if (maxRAMaddress < 0) { - fprintf(stderr, "invalid maxram 0x%x setting in %s\n", - maxRAMaddress, DEVICE_FILE_NAME); - return; - } -} - -/*-----------------------------------------------------------------* -*-----------------------------------------------------------------*/ - -int isREGinBank(regs *reg, int bank) -{ - - if(!reg || !pic) - return 0; - - if((int)((reg->address | reg->alias) & pic->bankMask & bank) == bank) - return 1; - - return 0; -} - -/*-----------------------------------------------------------------* -*-----------------------------------------------------------------*/ -int REGallBanks(regs *reg) -{ - - if(!reg || !pic) - return 0; - - return ((reg->address | reg->alias) & pic->bankMask); - -} - /*-----------------------------------------------------------------* * void list_valid_pics(int ncols, int list_alias) * @@ -459,7 +421,7 @@ int REGallBanks(regs *reg) * list_alias - if non-zero, print all of the supported aliases * for a device (e.g. F84, 16F84, etc...) *-----------------------------------------------------------------*/ -void list_valid_pics(int ncols) +static void list_valid_pics(int ncols) { int col=0,longest; int i,k,l; @@ -576,9 +538,10 @@ char *processor_base_name(void) return pic->name; } +#if 0 /*-----------------------------------------------------------------* *-----------------------------------------------------------------*/ -int validAddress(int address, int reg_size) +static int validAddress(int address, int reg_size) { if (maxRAMaddress < 0) { fprintf(stderr, "missing maxram setting in %s\n", DEVICE_FILE_NAME); @@ -591,6 +554,7 @@ int validAddress(int address, int reg_size) return 1; } +#endif #if 0 /* The following code should be (and is) implemented in the linker. */ @@ -737,11 +701,15 @@ void assignRelocatableRegisters(set *regset, int used) } #endif -/* Keep track of whether we found an assignment to the __config words. */ -static int pic14_hasSetConfigWord = 0; +int IS_CONFIG_ADDRESS(int address) +{ + + return ((address == CONFIG_WORD_ADDRESS) + || (address == CONFIG2_WORD_ADDRESS)); +} /*-----------------------------------------------------------------* - * void assignConfigWordValue(int address, int value) + * void pic14_assignConfigWordValue(int address, int value) * * Most midrange PICs have one config word at address 0x2007. * Newer PIC14s have a second config word at address 0x2008. @@ -761,33 +729,6 @@ void pic14_assignConfigWordValue(int address, int value) pic14_hasSetConfigWord = 1; } -/*-----------------------------------------------------------------* - * int pic14_emitConfigWord (FILE * vFile) - * - * Emit the __config directives iff we found a previous assignment - * to the config word. - *-----------------------------------------------------------------*/ -extern char *iComments2; -int pic14_emitConfigWord (FILE * vFile) -{ - if (pic14_hasSetConfigWord) - { - fprintf (vFile, "%s", iComments2); - fprintf (vFile, "; config word \n"); - fprintf (vFile, "%s", iComments2); - if (pic14_getHasSecondConfigReg()) - { - fprintf (vFile, "\t__config _CONFIG1, 0x%x\n", pic14_getConfigWord(0x2007)); - fprintf (vFile, "\t__config _CONFIG2, 0x%x\n", pic14_getConfigWord(0x2008)); - } - else - fprintf (vFile, "\t__config 0x%x\n", pic14_getConfigWord(0x2007)); - - return 1; - } - return 0; -} - /*-----------------------------------------------------------------* * int pic14_getConfigWord(int address) * @@ -795,7 +736,7 @@ int pic14_emitConfigWord (FILE * vFile) * *-----------------------------------------------------------------*/ -int pic14_getConfigWord(int address) +static int pic14_getConfigWord(int address) { switch (address) { @@ -810,20 +751,21 @@ int pic14_getConfigWord(int address) } } +#if 0 /*-----------------------------------------------------------------* * *-----------------------------------------------------------------*/ -unsigned pic14_getMaxRam(void) +static unsigned pic14_getMaxRam(void) { - return pic->defMaxRAMaddrs; + return pic->defMaxRAMaddrs; } - +#endif /*-----------------------------------------------------------------* * int getHasSecondConfigReg(void) - check if the device has a * second config register, rather than just one. *-----------------------------------------------------------------*/ -int pic14_getHasSecondConfigReg(void) +static int pic14_getHasSecondConfigReg(void) { if(!pic) return 0; @@ -831,12 +773,38 @@ int pic14_getHasSecondConfigReg(void) return pic->hasSecondConfigReg; } +/*-----------------------------------------------------------------* + * int pic14_emitConfigWord (FILE * vFile) + * + * Emit the __config directives iff we found a previous assignment + * to the config word. + *-----------------------------------------------------------------*/ +int pic14_emitConfigWord (FILE * vFile) +{ + if (pic14_hasSetConfigWord) + { + fprintf (vFile, "%s", iComments2); + fprintf (vFile, "; config word \n"); + fprintf (vFile, "%s", iComments2); + if (pic14_getHasSecondConfigReg()) + { + fprintf (vFile, "\t__config _CONFIG1, 0x%x\n", pic14_getConfigWord(0x2007)); + fprintf (vFile, "\t__config _CONFIG2, 0x%x\n", pic14_getConfigWord(0x2008)); + } + else + fprintf (vFile, "\t__config 0x%x\n", pic14_getConfigWord(0x2007)); + + return 1; + } + return 0; +} + /*-----------------------------------------------------------------* * True iff the device has memory aliased in every bank. * If true, low and high will be set to the low and high address * occupied by the (last) sharebank found. *-----------------------------------------------------------------*/ -int pic14_hasSharebank(int *low, int *high, int *size) +static int pic14_hasSharebank(int *low, int *high, int *size) { memRange *r; @@ -868,7 +836,7 @@ int pic14_hasSharebank(int *low, int *high, int *size) /* * True iff the memory region [low, high] is aliased in all banks. */ -int pic14_isShared(int low, int high) +static int pic14_isShared(int low, int high) { memRange *r; diff --git a/src/pic/device.h b/src/pic/device.h index 81dc90ea..ccf3616e 100644 --- a/src/pic/device.h +++ b/src/pic/device.h @@ -29,6 +29,13 @@ #ifndef __DEVICE_H__ #define __DEVICE_H__ +#include "common.h" + +/* + * Imports + */ +extern char *iComments2; + /* memRange - a structure to define a range of valid memory addresses * * The Memory of most PICs (and other micros) is a collection of @@ -68,27 +75,15 @@ typedef struct PIC_device { } PIC_device; -/* Given a pointer to a register, this macro returns the bank that it is in */ -#define REG_ADDR(r) ((r)->isBitField ? (((r)->address)>>3) : (r)->address) - - -/****************************************/ -void assignConfigWordValue(int address, int value); -int getConfigWord(int address); -int isREGinBank(regs *reg, int bank); -int REGallBanks(regs *reg); -void addMemRange(memRange *r, int type); -void setMaxRAM(int size); -void setDefMaxRam(void); +PIC_device *init_pic(char *pic_type); +int picIsInitialized(void); +char *processor_base_name(void); +int IS_CONFIG_ADDRESS(int addr); void pic14_assignConfigWordValue(int address, int value); -int pic14_emitConfigWord (FILE * vFile); -int pic14_getConfigWord(int address); +int pic14_emitConfigWord(FILE *vFile); -unsigned pic14_getMaxRam(void); -int pic14_getHasSecondConfigReg(void); int pic14_allRAMShared(void); -int pic14_hasSharebank(int *low, int *high, int *size); int pic14_getSharedStack(int *low, int *high, int *size); PIC_device * pic14_getPIC(void); diff --git a/src/pic/gen.c b/src/pic/gen.c index 6ff00ac7..507d386d 100644 --- a/src/pic/gen.c +++ b/src/pic/gen.c @@ -30,56 +30,46 @@ Made everything static -------------------------------------------------------------------------*/ -#include -#include -#include -#include -#include "SDCCglobl.h" -#include "newalloc.h" - -#include "common.h" -#include "SDCCpeeph.h" -#include "ralloc.h" -#include "pcode.h" +/* + * 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 + * routines may be reusable, will have to see. + */ + #include "gen.h" #include "glue.h" -/* The PIC port(s) need not differentiate between POINTER and FPOINTER. */ -#define PIC_IS_DATA_PTR(x) (IS_DATA_PTR(x) || IS_FARPTR(x)) -#define PIC_IS_FARPTR(x) (PIC_IS_DATA_PTR(x)) - -extern void printpBlock(FILE *of, pBlock *pb); - -static int labelOffset=0; -extern int debug_verbose; -extern int pic14_hasInterrupt; -//static int optimized_for_speed = 0; +/* + * Imports + */ +extern struct dbuf_s *codeOutBuf; +extern set *externs; -/* max_key keeps track of the largest label number used in -a function. This is then used to adjust the label offset -for the next function. -*/ -static int max_key=0; -static int GpsuedoStkPtr=0; -static int pic14_inISR = 0; -pCodeOp *popGetImmd(char *name, unsigned int offset, int index,int is_func); -extern char *get_op( pCodeOp *pcop,char *buff,size_t buf_size); -const char *AopType(short type); +static pCodeOp *popGetImmd(char *name, unsigned int offset, int index,int is_func); +static pCodeOp *popRegFromString(char *str, int size, int offset); +static int aop_isLitLike(asmop *aop); -#define BYTEofLONG(l,b) ( (l>> (b<<3)) & 0x00ff) +/* The PIC port(s) need not differentiate between POINTER and FPOINTER. */ +#define PIC_IS_DATA_PTR(x) (IS_DATA_PTR(x) || IS_FARPTR(x)) -/* 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 -routines may be reusable, will have to see */ +/* + * max_key keeps track of the largest label number used in + * a function. This is then used to adjust the label offset + * for the next function. + */ +static int max_key = 0; +static int labelOffset = 0; +static int GpsuedoStkPtr = 0; +static int pic14_inISR = 0; static char *zero = "0x00"; static char *one = "0x01"; static char *spname = "sp"; -char *fReturnpic14[] = {"temp1","temp2","temp3","temp4" }; unsigned fReturnSizePic = 4; /* shared with ralloc.c */ +static char *fReturnpic14[] = {"temp1","temp2","temp3","temp4" }; static char **fReturn = fReturnpic14; static struct { @@ -90,9 +80,10 @@ static struct { set *sendSet; } _G; -/* Resolved ifx structure. This structure stores information -about an iCode ifx that makes it easier to generate code. -*/ +/* + * Resolved ifx structure. This structure stores information + * about an iCode ifx that makes it easier to generate code. + */ typedef struct resolvedIfx { symbol *lbl; /* pointer to a label */ int condition; /* true or false ifx */ @@ -100,14 +91,9 @@ typedef struct resolvedIfx { * is generated */ } resolvedIfx; -extern int pic14_nRegs; -extern struct dbuf_s *codeOutBuf; -static void saverbank (int, iCode *,bool); - static lineNode *lineHead = NULL; static lineNode *lineCurr = NULL; - -static pBlock *pb; +static pBlock *pb; /*-----------------------------------------------------------------*/ /* my_powof2(n) - If `n' is an integaer power of 2, then the */ @@ -151,7 +137,7 @@ void DEBUGpic14_AopType(int line_no, operand *left, operand *right, operand *res } -void DEBUGpic14_AopTypeSign(int line_no, operand *left, operand *right, operand *result) +static void DEBUGpic14_AopTypeSign(int line_no, operand *left, operand *right, operand *result) { DEBUGpic14_emitcode ("; ","line = %d, signs: result %s=%c, left %s=%c, right %s=%c", @@ -264,7 +250,7 @@ void emitpcode_real(PIC_OPCODE poc, pCodeOp *pcop) } } -void emitpcodeNULLop(PIC_OPCODE poc) +static void emitpcodeNULLop(PIC_OPCODE poc) { addpCode2pBlock(pb,newpCode(poc,NULL)); @@ -323,7 +309,7 @@ pic14_emitDebuggerSymbol (char * debugSym) /*-----------------------------------------------------------------*/ /* newAsmop - creates a new asmOp */ /*-----------------------------------------------------------------*/ -asmop *newAsmop (short type) +static asmop *newAsmop (short type) { asmop *aop; @@ -502,7 +488,7 @@ static asmop *aopForRemat (operand *op) // x symbol *sym) return aop; } -int aopIdx (asmop *aop, int offset) +static int aopIdx (asmop *aop, int offset) { if(!aop) return -1; @@ -802,6 +788,33 @@ void freeAsmop (operand *op, asmop *aaop, iCode *ic, bool pop) } } +/*-----------------------------------------------------------------*/ +/* pic14aopLiteral - string from a literal value */ +/*-----------------------------------------------------------------*/ +static unsigned int pic14aopLiteral (value *val, int offset) +{ + union { + float f; + unsigned char c[4]; + } fl; + + /* if it is a float then it gets tricky */ + /* otherwise it is fairly simple */ + if (!IS_FLOAT(val->type)) { + unsigned long v = ulFromVal (val); + + return ( (v >> (offset * 8)) & 0xff); + } + + /* it is type float */ + fl.f = (float) floatFromVal(val); +#ifdef WORDS_BIGENDIAN + return fl.c[3-offset]; +#else + return fl.c[offset]; +#endif +} + /*-----------------------------------------------------------------*/ /* aopGet - for fetching value of the aop */ /*-----------------------------------------------------------------*/ @@ -907,7 +920,7 @@ char *aopGet (asmop *aop, int offset, bool bit16, bool dname) /*-----------------------------------------------------------------*/ /* popGetTempReg - create a new temporary pCodeOp */ /*-----------------------------------------------------------------*/ -pCodeOp *popGetTempReg(void) +static pCodeOp *popGetTempReg(void) { pCodeOp *pcop; @@ -924,7 +937,7 @@ pCodeOp *popGetTempReg(void) /*-----------------------------------------------------------------*/ /* popReleaseTempReg - create a new temporary pCodeOp */ /*-----------------------------------------------------------------*/ -void popReleaseTempReg(pCodeOp *pcop) +static void popReleaseTempReg(pCodeOp *pcop) { if(pcop && pcop->type == PO_GPR_TEMP && PCOR(pcop)->r) @@ -948,7 +961,7 @@ pCodeOp *popGetLabel(unsigned int key) /*-------------------------------------------------------------------*/ /* popGetHighLabel - create a new pCodeOp of type PO_LABEL with offset=1 */ /*-------------------------------------------------------------------*/ -pCodeOp *popGetHighLabel(unsigned int key) +static pCodeOp *popGetHighLabel(unsigned int key) { pCodeOp *pcop; pcop = popGetLabel(key); @@ -968,18 +981,16 @@ pCodeOp *popGetLit(unsigned int lit) /*-----------------------------------------------------------------*/ /* popGetImmd - asm operator to pcode immediate conversion */ /*-----------------------------------------------------------------*/ -pCodeOp *popGetImmd(char *name, unsigned int offset, int index,int is_func) +static pCodeOp *popGetImmd(char *name, unsigned int offset, int index,int is_func) { return newpCodeOpImmd(name, offset,index, 0, is_func); } -extern set *externs; - /*-----------------------------------------------------------------*/ /* popGetWithString - asm operator to pcode operator conversion */ /*-----------------------------------------------------------------*/ -pCodeOp *popGetWithString(char *str, int isExtern) +static pCodeOp *popGetWithString(char *str, int isExtern) { pCodeOp *pcop; @@ -1027,7 +1038,7 @@ pCodeOp *popGetExternal (char *str, int isReg) /*-----------------------------------------------------------------*/ /* popRegFromString - */ /*-----------------------------------------------------------------*/ -pCodeOp *popRegFromString(char *str, int size, int offset) +static pCodeOp *popRegFromString(char *str, int size, int offset) { pCodeOp *pcop = Safe_calloc(1,sizeof(pCodeOpReg) ); @@ -1058,7 +1069,7 @@ pCodeOp *popRegFromString(char *str, int size, int offset) /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ -pCodeOp *popRegFromIdx(int rIdx) +static pCodeOp *popRegFromIdx(int rIdx) { pCodeOp *pcop; @@ -1285,7 +1296,6 @@ void aopPut (asmop *aop, char *s, int offset) case AOP_REG: if (strcmp(aop->aopu.aop_reg[offset]->name,s) != 0) { - //strcmp(aop->aopu.aop_reg[offset]->dname,s)!= 0){ /* if (*s == '@' || strcmp(s,"r0") == 0 || @@ -1541,7 +1551,7 @@ void pic14_outAcc(operand *result) /*-----------------------------------------------------------------*/ /* pic14_outBitC - output a bit C */ /*-----------------------------------------------------------------*/ -void pic14_outBitC(operand *result) +static void pic14_outBitC(operand *result) { DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__); @@ -1558,7 +1568,7 @@ void pic14_outBitC(operand *result) /*-----------------------------------------------------------------*/ /* pic14_toBoolean - emit code for orl a,operator(sizeop) */ /*-----------------------------------------------------------------*/ -void pic14_toBoolean(operand *oper) +static void pic14_toBoolean(operand *oper) { int size = AOP_SIZE(oper); int offset = 0; @@ -1769,6 +1779,56 @@ release: freeAsmop(IC_RESULT(ic),NULL,ic,TRUE); } +/*-----------------------------------------------------------------*/ +/* saverbank - saves an entire register bank on the stack */ +/*-----------------------------------------------------------------*/ +static void saverbank (int bank, iCode *ic, bool pushPsw) +{ + FENTRY; + + DEBUGpic14_emitcode ("; ***","%s %d - WARNING no code generated",__FUNCTION__,__LINE__); +#if 0 + int i; + asmop *aop ; + regs *r = NULL; + + DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__); + if (options.useXstack) { + + aop = newAsmop(0); + r = getFreePtr(ic,&aop,FALSE); + pic14_emitcode("mov","%s,_spx",r->name); + + } + + for (i = 0 ; i < pic14_nRegs ;i++) { + if (options.useXstack) { + pic14_emitcode("inc","%s",r->name); + //pic14_emitcode("mov","a,(%s+%d)", + // regspic14[i].base,8*bank+regspic14[i].offset); + pic14_emitcode("movx","@%s,a",r->name); + } else + pic14_emitcode("push","");// "(%s+%d)", + //regspic14[i].base,8*bank+regspic14[i].offset); + } + + if (pushPsw) { + if (options.useXstack) { + pic14_emitcode("mov","a,psw"); + pic14_emitcode("movx","@%s,a",r->name); + pic14_emitcode("inc","%s",r->name); + pic14_emitcode("mov","_spx,%s",r->name); + freeAsmop (NULL,aop,ic,TRUE); + + } else + pic14_emitcode("push","psw"); + + pic14_emitcode("mov","psw,#0x%02x",(bank << 3)&0x00ff); + } + ic->bankSaved = 1; +#endif +} + /*-----------------------------------------------------------------*/ /* saveRegisters - will look for a call and save the registers */ /*-----------------------------------------------------------------*/ @@ -2033,56 +2093,6 @@ static void unsaverbank (int bank,iCode *ic,bool popPsw) #endif } -/*-----------------------------------------------------------------*/ -/* saverbank - saves an entire register bank on the stack */ -/*-----------------------------------------------------------------*/ -static void saverbank (int bank, iCode *ic, bool pushPsw) -{ - FENTRY; - - DEBUGpic14_emitcode ("; ***","%s %d - WARNING no code generated",__FUNCTION__,__LINE__); -#if 0 - int i; - asmop *aop ; - regs *r = NULL; - - DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__); - if (options.useXstack) { - - aop = newAsmop(0); - r = getFreePtr(ic,&aop,FALSE); - pic14_emitcode("mov","%s,_spx",r->name); - - } - - for (i = 0 ; i < pic14_nRegs ;i++) { - if (options.useXstack) { - pic14_emitcode("inc","%s",r->name); - //pic14_emitcode("mov","a,(%s+%d)", - // regspic14[i].base,8*bank+regspic14[i].offset); - pic14_emitcode("movx","@%s,a",r->name); - } else - pic14_emitcode("push","");// "(%s+%d)", - //regspic14[i].base,8*bank+regspic14[i].offset); - } - - if (pushPsw) { - if (options.useXstack) { - pic14_emitcode("mov","a,psw"); - pic14_emitcode("movx","@%s,a",r->name); - pic14_emitcode("inc","%s",r->name); - pic14_emitcode("mov","_spx,%s",r->name); - freeAsmop (NULL,aop,ic,TRUE); - - } else - pic14_emitcode("push","psw"); - - pic14_emitcode("mov","psw,#0x%02x",(bank << 3)&0x00ff); - } - ic->bankSaved = 1; -#endif -} - /*-----------------------------------------------------------------*/ /* genCall - generates a call statement */ /*-----------------------------------------------------------------*/ @@ -3333,7 +3343,8 @@ static int genChkZeroes(operand *op, int lit, int size) /* aop (if it's NOT a literal) or from lit (if */ /* aop is a literal) */ /*-----------------------------------------------------------------*/ -void pic14_mov2w_regOrLit (asmop *aop, unsigned long lit, int offset) { +static void pic14_mov2w_regOrLit (asmop *aop, unsigned long lit, int offset) +{ if (aop->type == AOP_LIT) { emitpcode (POC_MOVLW, popGetLit((lit >> (offset*8)) & 0x00FF)); } else { @@ -6303,12 +6314,6 @@ static void shiftR2Left2Result (operand *left, int offl, } */ /* a:x >> shCount (x = lsb(result))*/ - /* - if(sign) - AccAXRshS( aopGet(AOP(result),offr,FALSE,FALSE) , shCount); - else { - AccAXRsh( aopGet(AOP(result),offr,FALSE,FALSE) , shCount); - */ switch(shCount) { case 0: break; @@ -6890,7 +6895,8 @@ static void genLeftShift (iCode *ic) /*-----------------------------------------------------------------*/ /* SetIrp - Set IRP bit */ /*-----------------------------------------------------------------*/ -void SetIrp(operand *result) { +static void SetIrp(operand *result) +{ FENTRY; if (AOP_TYPE(result) == AOP_LIT) { unsigned lit = (unsigned) double2ul (operandLitValue(result)); @@ -9000,7 +9006,7 @@ void genpic14Code (iCode *lic) /* This is not safe, as a AOP_PCODE/PO_IMMEDIATE might be used both as literal * (meaning: representing its own address) or not (referencing its contents). * This can only be decided based on the operand's type. */ -int +static int aop_isLitLike (asmop *aop) { assert (aop); diff --git a/src/pic/gen.h b/src/pic/gen.h index ccfe5f39..64198360 100644 --- a/src/pic/gen.h +++ b/src/pic/gen.h @@ -26,7 +26,11 @@ #ifndef SDCCGENPIC14_H #define SDCCGENPIC14_H -extern int debug_verbose; +#include "common.h" + +#include "main.h" +#include "pcode.h" +#include "ralloc.h" #define FENTRY do { \ /*fprintf (stderr, "%s:%u:%s: *{*\n", __FILE__, __LINE__, __FUNCTION__);*/ \ @@ -41,8 +45,6 @@ extern int debug_verbose; } \ } while (0) -struct pCodeOp; - enum { AOP_LIT = 1, @@ -92,8 +94,6 @@ typedef struct asmop } asmop; -void genpic14Code (iCode *); - extern unsigned fReturnSizePic; @@ -110,18 +110,11 @@ extern unsigned fReturnSizePic; #define MOVA(x) if (strcmp(x,"a") && strcmp(x,"acc")) pic14_emitcode(";XXX mov","a,%s %s,%d",x,__FILE__,__LINE__); #define CLRC pic14_emitcode(";XXX clr","c %s,%d",__FILE__,__LINE__); -#define BIT_NUMBER(x) (x & 7) -#define BIT_REGISTER(x) (x>>3) - - #define LSB 0 #define MSB16 1 #define MSB24 2 #define MSB32 3 - -#define FUNCTION_LABEL_INC 40 - /*-----------------------------------------------------------------*/ /* Macros for emitting skip instructions */ /*-----------------------------------------------------------------*/ @@ -149,40 +142,33 @@ void emitpLabel(int key); void pic14_emitcode (char *inst,char *fmt, ...); void DEBUGpic14_emitcode (char *inst,char *fmt, ...); void pic14_emitDebuggerSymbol (char *); -asmop *newAsmop (short type); bool pic14_sameRegs (asmop *aop1, asmop *aop2 ); char *aopGet (asmop *aop, int offset, bool bit16, bool dname); +void DEBUGpic14_AopType(int line_no, operand *left, operand *right, operand *result); +void genpic14Code (iCode *lic); -bool genPlusIncr (iCode *ic); -void pic14_outBitAcc(operand *result); -void genPlus (iCode *ic); -void addSign(operand *result, int offset, int sign); -void genMinus (iCode *ic); - - -pCodeOp *popGetLabel(unsigned int key); -pCodeOp *popCopyReg(pCodeOpReg *pc); -pCodeOp *popCopyGPR2Bit(pCodeOp *pc, int bitval); -pCodeOp *popGetLit(unsigned int lit); -pCodeOp *popGetWithString(char *str, int isExtern); -pCodeOp *popRegFromString(char *str, int size, int offset); pCodeOp *popGet (asmop *aop, int offset);//, bool bit16, bool dname); pCodeOp *popGetAddr (asmop *aop, int offset, int index); -pCodeOp *popGetTempReg(void); -void popReleaseTempReg(pCodeOp *pcop); +pCodeOp *popGetExternal (char *str, int isReg); +pCodeOp *popGetLabel(unsigned int key); +pCodeOp *popGetLit(unsigned int lit); void aopPut (asmop *aop, char *s, int offset); void pic14_outAcc(operand *result); void aopOp (operand *op, iCode *ic, bool result); -void pic14_outBitC(operand *result); -void pic14_toBoolean(operand *oper); void freeAsmop (operand *op, asmop *aaop, iCode *ic, bool pop); void mov2w (asmop *aop, int offset); -const char *pCodeOpType( pCodeOp *pcop); - -int aop_isLitLike (asmop *aop); int op_isLitLike (operand *op); +/* + * From genarith.c: + */ +const char *AopType(short type); +const char *pCodeOpType(pCodeOp *pcop); +void genPlus (iCode *ic); +void addSign(operand *result, int offset, int sign); +void genMinus (iCode *ic); + #endif diff --git a/src/pic/genarith.c b/src/pic/genarith.c index 11dc0fe1..b0f0bd2b 100644 --- a/src/pic/genarith.c +++ b/src/pic/genarith.c @@ -29,26 +29,21 @@ Made everything static -------------------------------------------------------------------------*/ -#include -#include -#include -#include -#include "SDCCglobl.h" -#include "newalloc.h" - #if defined(_MSC_VER) && (_MSC_VER < 1300) #define __FUNCTION__ __FILE__ #endif #include "common.h" -#include "SDCCpeeph.h" -#include "ralloc.h" -#include "pcode.h" +#include "newalloc.h" +//#include "SDCCglobl.h" +//#include "SDCCpeeph.h" + #include "gen.h" +#include "pcode.h" +#include "ralloc.h" #define BYTEofLONG(l,b) ( (l>> (b<<3)) & 0xff) -extern void DEBUGpic14_AopType(int line_no, operand *left, operand *right, operand *result); const char *AopType(short type) { @@ -82,7 +77,8 @@ const char *AopType(short type) return "BAD TYPE"; } -void DebugAop(asmop *aop) +#if 0 +static void DebugAop(asmop *aop) { if(!aop) return; @@ -115,6 +111,7 @@ void DebugAop(asmop *aop) break; } } +#endif const char *pCodeOpType( pCodeOp *pcop) { @@ -174,7 +171,7 @@ const char *pCodeOpType( pCodeOp *pcop) /*-----------------------------------------------------------------*/ /* genPlusIncr :- does addition with increment if possible */ /*-----------------------------------------------------------------*/ -bool genPlusIncr (iCode *ic) +static bool genPlusIncr (iCode *ic) { unsigned int icount ; unsigned int size = pic14_getDataSize(IC_RESULT(ic)); @@ -264,10 +261,11 @@ bool genPlusIncr (iCode *ic) return FALSE ; } +#if 0 /*-----------------------------------------------------------------*/ /* pic14_outBitAcc - output a bit in acc */ /*-----------------------------------------------------------------*/ -void pic14_outBitAcc(operand *result) +static void pic14_outBitAcc(operand *result) { symbol *tlbl = newiTempLabel(NULL); /* if the result is a bit */ @@ -284,6 +282,7 @@ void pic14_outBitAcc(operand *result) pic14_outAcc(result); } } +#endif #if 0 /* This is the original version of this code. diff --git a/src/pic/glue.c b/src/pic/glue.c index 24ba689b..3f4d6a8c 100644 --- a/src/pic/glue.c +++ b/src/pic/glue.c @@ -22,94 +22,51 @@ what you give them. Help stamp out software-hoarding! -------------------------------------------------------------------------*/ -#include "../common.h" -#include -#include "ralloc.h" -#include "pcode.h" -#include "newalloc.h" -#include "gen.h" -#include "main.h" -#include "device.h" +#include "glue.h" #include "dbuf_string.h" +#include "device.h" +#include "gen.h" +#include "main.h" -#ifdef WORDS_BIGENDIAN -#define _ENDIAN(x) (3-x) -#else -#define _ENDIAN(x) (x) -#endif - -#define BYTE_IN_LONG(x,b) ((x>>(8*_ENDIAN(b)))&0xff) -#define IS_GLOBAL(sym) ((sym)->level == 0) - -extern symbol *interrupts[256]; -static void showAllMemmaps(FILE *of); // XXX: emits initialized symbols -extern int noAlloc; +/* + * Imports + */ extern set *publics; extern set *externs; -extern unsigned maxInterrupts; extern symbol *mainf; -extern char *VersionString; extern struct dbuf_s *codeOutBuf; -extern char *iComments1; -extern char *iComments2; -//extern void emitStaticSeg (memmap * map); -set *pic14_localFunctions = NULL; - -extern DEFSETFUNC (closeTmpFiles); -extern DEFSETFUNC (rmTmpFiles); -extern void AnalyzeBanking (void); -extern void ReuseReg(void); -extern void InlinepCode(void); -extern void writeUsedRegs(FILE *); +extern DEFSETFUNC(closeTmpFiles); +extern DEFSETFUNC(rmTmpFiles); +extern void initialComments(FILE *afile); +extern operand *operandFromAst(ast *tree, int lvl); +extern value *initPointer(initList *ilist, sym_link *toType); -extern void initialComments (FILE * afile); -extern void printPublics (FILE * afile); -extern void printChar (FILE * ofile, char *s, int plen); -void pCodeInitRegisters(void); -int getConfigWord(int address); -int getHasSecondConfigReg(void); -void pic14_debugLogClose(void); // from ralloc.c - -char *udata_section_name=0; // FIXME Temporary fix to change udata section name -- VR +set *pic14_localFunctions = NULL; int pic14_hasInterrupt = 0; // Indicates whether to emit interrupt handler or not -/* dbufs for initialized data (idata and code sections), - * extern, and global declarations */ -struct dbuf_s *ivalBuf, *extBuf, *gloBuf, *gloDefBuf; - -static set *emitted = NULL; int pic14_stringInSet(const char *str, set **world, int autoAdd); -/*-----------------------------------------------------------------*/ -/* aopLiteral - string from a literal value */ -/*-----------------------------------------------------------------*/ -unsigned int pic14aopLiteral (value *val, int offset) -{ - union { - float f; - unsigned char c[4]; - } fl; - - /* if it is a float then it gets tricky */ - /* otherwise it is fairly simple */ - if (!IS_FLOAT(val->type)) { - unsigned long v = ulFromVal (val); - - return ( (v >> (offset * 8)) & 0xff); - } - /* it is type float */ - fl.f = (float) floatFromVal(val); #ifdef WORDS_BIGENDIAN - return fl.c[3-offset]; +#define _ENDIAN(x) (3-x) #else - return fl.c[offset]; +#define _ENDIAN(x) (x) #endif -} +#define BYTE_IN_LONG(x,b) ((x>>(8*_ENDIAN(b)))&0xff) +#define IS_GLOBAL(sym) ((sym)->level == 0) +#define IS_DEFINED_HERE(sym) (!IS_EXTERN(sym->etype)) + +/* dbufs for initialized data (idata and code sections), + * extern, and global declarations */ +static struct dbuf_s *ivalBuf, *extBuf, *gloBuf, *gloDefBuf; + +static set *emitted = NULL; + +static void showAllMemmaps(FILE *of); // XXX: emits initialized symbols #if 0 static int @@ -210,8 +167,6 @@ emitIfNew(struct dbuf_s *oBuf, set **emitted, const char *fmt, return (!wasPresent); } -#define IS_DEFINED_HERE(sym) (!IS_EXTERN(sym->etype)) -extern int IS_CONFIG_ADDRESS( int addr ); static void pic14_constructAbsMap (struct dbuf_s *oBuf, struct dbuf_s *gloBuf) { @@ -716,8 +671,6 @@ printIvalArray (symbol * sym, sym_link * type, initList * ilist, /*-----------------------------------------------------------------*/ /* printIvalPtr - generates code for initial value of pointers */ /*-----------------------------------------------------------------*/ -extern value *initPointer (initList *, sym_link *toType); - static void printIvalPtr (symbol * sym, sym_link * type, initList * ilist, pBlock *pb) { @@ -840,7 +793,6 @@ printIval (symbol * sym, sym_link * type, initList * ilist, pBlock *pb) #endif #if 0 -extern void pCodeConstString(char *name, char *value); /*-----------------------------------------------------------------*/ /* emitStaticSeg - emitcode for the static segment */ /*-----------------------------------------------------------------*/ @@ -967,7 +919,6 @@ pic14emitMaps () /*-----------------------------------------------------------------*/ /* createInterruptVect - creates the interrupt vector */ /*-----------------------------------------------------------------*/ -pCodeOp *popGetExternal (char *str, int isReg); static void pic14createInterruptVect (struct dbuf_s * vBuf) { @@ -1143,34 +1094,6 @@ pic14printPublics (FILE * afile) } #endif -/* - * Interface to BANKSEL generation. - * This function should return != 0 iff str1 and str2 denote operands that - * are known to be allocated into the same bank. Consequently, there will - * be no BANKSEL emitted if str2 is accessed while str1 has been used to - * select the current bank just previously. - * - * If in doubt, return 0. - */ -int -pic14_operandsAllocatedInSameBank(const char *str1, const char *str2) { - // see pic14printLocals - - if (getenv("SDCC_PIC14_SPLIT_LOCALS")) { - // no clustering applied, each register resides in its own bank - } else { - // check whether BOTH names are local registers - // XXX: This is some kind of shortcut, should be safe... - // In this model, all r0xXXXX are allocated into a single section - // per file, so no BANKSEL required if accessing a r0xXXXX after a - // (different) r0xXXXX. Works great for multi-byte operands. - if (str1 && str2 && str1[0] == 'r' && str2[0] == 'r') return (1); - } // if - - // assume operands in different banks - return (0); -} - static void pic14printLocals (struct dbuf_s *oBuf) { @@ -1324,7 +1247,7 @@ pic14emitOverlay (struct dbuf_s * aBuf) } -void +static void pic14_emitInterruptHandler (FILE * asmFile) { if (pic14_hasInterrupt) @@ -1597,8 +1520,6 @@ picglue () #endif -void ast_print (ast * tree, FILE *outfile, int indent); - #if 0 /* * Emit all memmaps. @@ -1630,11 +1551,12 @@ showInitList(initList *list, int level) } #endif +#if 0 /* * DEBUG: Print a value. */ -void -printVal(value *val) +static void +printValue(value *val) { printf ("value %p: name %s, type %p, etype %p, sym %s, vArgs %d, lit 0x%lx/%ld\n", val, val->name, val->type, val->etype, @@ -1645,11 +1567,9 @@ printVal(value *val) printTypeChain(val->etype, stdout); printf ("\n"); } +#endif -//prototype from ../SDCCicode.c -operand *operandFromAst (ast * tree,int lvl); - -char * +static char * parseIvalAst (ast *node, int *inCodeSpace) { #define LEN 4096 char *buffer = NULL; @@ -1762,7 +1682,6 @@ emitIvalLabel(struct dbuf_s *oBuf, symbol *sym) return (in_code); } -char *get_op(pCodeOp *pcop,char *buffer, size_t size); /* * Actually emit the initial values in .asm format. */ @@ -1801,7 +1720,7 @@ emitIvals(struct dbuf_s *oBuf, symbol *sym, initList *list, long lit, int size) if (constExprTree(node) && (val = constExprValue(node, 0))) { op = operandFromValue(val); DEBUGprintf ("%s: constExpr ", __FUNCTION__); - //printVal(val); + //printValue(val); } else if (IS_AST_VALUE(node)) { op = operandFromAst(node, 0); } else if (IS_AST_OP(node)) { diff --git a/src/pic/glue.h b/src/pic/glue.h index 88e54429..f4a9407a 100644 --- a/src/pic/glue.h +++ b/src/pic/glue.h @@ -25,12 +25,12 @@ #ifndef PIC_GLUE_H #define PIC_GLUE_H -#include "../SDCCset.h" +#include "common.h" +extern int pic14_hasInterrupt; extern set *pic14_localFunctions; void picglue (void); -unsigned int pic14aopLiteral (value *val, int offset); int pic14_stringInSet(const char *str, set **world, int autoAdd); #endif diff --git a/src/pic/main.c b/src/pic/main.c index 7e87781b..b06c144c 100644 --- a/src/pic/main.c +++ b/src/pic/main.c @@ -5,36 +5,43 @@ it easier to set a breakpoint using the debugger. */ #include "common.h" -#include "main.h" -#include "ralloc.h" -#include "device.h" -#include "SDCCutil.h" -#include "SDCCmacro.h" +#include "dbuf_string.h" #include "MySystem.h" +#include "SDCCmacro.h" + +#include "device.h" +#include "gen.h" #include "glue.h" -#include "dbuf_string.h" -#include -//#include "gen.h" +#include "main.h" +#include "pcode.h" +#include "ralloc.h" -#define OPTION_STACK_SIZE "--stack-size" -#define OPTION_UDATA_SECTION_NAME "--udata-section-name" +/* + * Imports + */ +extern set *dataDirsSet; +extern set *includeDirsSet; +extern set *libDirsSet; +extern set *libPathsSet; +extern set *linkOptionsSet; + + +pic14_options_t pic14_options; +int debug_verbose = 0; +#define OPTION_STACK_SIZE "--stack-size" + static char _defaultRules[] = { #include "peeph.rul" }; -pic14_options_t pic14_options; -extern int debug_verbose; /* from pcode.c */ -extern char *udata_section_name; - static OPTION _pic14_poptions[] = { { 0, "--debug-xtra", &debug_verbose, "show more debug info in assembly output" }, { 0, "--no-pcode-opt", &pic14_options.disable_df, "disable (slightly faulty) optimization on pCode" }, { 0, OPTION_STACK_SIZE, &options.stack_size, "sets the size if the argument passing stack (default: 16, minimum: 4)", CLAT_INTEGER }, - { 0, OPTION_UDATA_SECTION_NAME, &udata_section_name, "set udata section name", CLAT_STRING }, { 0, NULL, NULL, NULL } }; @@ -66,15 +73,24 @@ static char *_pic14_keywords[] = NULL }; -void pCodeInitRegisters(void); +static int regParmFlg = 0; /* determine if we can register a parameter */ -void pic14_assignRegisters (ebbIndex *); -/* Also defined in gen.h, but the #include is commented out */ -/* for an unknowned reason. - EEP */ -void pic14_emitDebuggerSymbol (char *); +/** $1 is always the basename. + $2 is always the output file. + $3 varies + $l is the list of extra options that should be there somewhere... + MUST be terminated with a NULL. +*/ +static const char *_linkCmd[] = +{ + "gplink", "$l", "-w", "-r", "-o \"$2\"", "\"$1\"", "$3", NULL +}; -static int regParmFlg = 0; /* determine if we can register a parameter */ +static const char *_asmCmd[] = +{ + "gpasm", "$l", "$3", "-c", "\"$1.asm\"", NULL +}; static void _pic14_init (void) @@ -110,8 +126,6 @@ _pic14_parseOptions (int *pargc, char **argv, int *i) return FALSE; } -extern set *dataDirsSet; -extern set *includeDirsSet; /* pic14 port uses include/pic and lib/pic instead of * include/pic14 and lib/pic14 as indicated by SDCCmain.c's * setIncludePaths routine. */ @@ -219,8 +233,6 @@ _pic14_getRegName (struct regs *reg) return "err"; } -extern char *processor_base_name(void); - static void _pic14_genAssemblerPreamble (FILE * of) { @@ -345,32 +357,6 @@ oclsExpense (struct memmap *oclass) return 0; } -/** $1 is always the basename. - $2 is always the output file. - $3 varies - $l is the list of extra options that should be there somewhere... - MUST be terminated with a NULL. -*/ -static const char *_linkCmd[] = -{ - "gplink", "$l", "-w", "-r", "-o \"$2\"", "\"$1\"", "$3", NULL -}; - -static const char *_asmCmd[] = -{ - "gpasm", "$l", "$3", "-c", "\"$1.asm\"", NULL - -}; - -extern set *libFilesSet; -extern set *libDirsSet; -extern set *libPathsSet; -extern set *includeDirsSet; -extern set *userIncDirsSet; -extern set *dataDirsSetSet; -extern set *relFilesSet; -extern set *linkOptionsSet; - static void _pic14_do_link (void) { hTab *linkValues=NULL; diff --git a/src/pic/main.h b/src/pic/main.h index da5f40a1..b185ad73 100644 --- a/src/pic/main.h +++ b/src/pic/main.h @@ -7,9 +7,7 @@ typedef struct { } pic14_options_t; extern pic14_options_t pic14_options; - -bool x_parseOptions (char **argv, int *pargc); -void x_setDefaultOptions (void); -void x_finaliseOptions (void); +extern int debug_verbose; #endif + diff --git a/src/pic/pcode.c b/src/pic/pcode.c index 659c749a..1149e6db 100644 --- a/src/pic/pcode.c +++ b/src/pic/pcode.c @@ -18,35 +18,15 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -------------------------------------------------------------------------*/ -#include - -#include "common.h" // Include everything in the SDCC src directory -#include "newalloc.h" - - +#include "device.h" +#include "gen.h" #include "pcode.h" #include "pcodeflow.h" #include "ralloc.h" -#include "device.h" - -pCode *findFunction(char *fname); - -static void FixRegisterBanking(pBlock *pb); /****************************************************************/ /****************************************************************/ -peepCommand peepCommands[] = { - - {NOTBITSKIP, "_NOTBITSKIP_"}, - {BITSKIP, "_BITSKIP_"}, - {INVERTBITSKIP, "_INVERTBITSKIP_"}, - - {-1, NULL} -}; - - - // Eventually this will go into device dependent files: pCodeOpReg pc_status = {{PO_STATUS, "STATUS"}, -1, NULL,0,NULL}; pCodeOpReg pc_indf = {{PO_INDF, "INDF"}, -1, NULL,0,NULL}; @@ -59,42 +39,45 @@ pCodeOpReg pc_wsave = {{PO_GPR_REGISTER, "WSAVE"}, -1, NULL,0,NULL}; pCodeOpReg pc_ssave = {{PO_GPR_REGISTER, "SSAVE"}, -1, NULL,0,NULL}; pCodeOpReg pc_psave = {{PO_GPR_REGISTER, "PSAVE"}, -1, NULL,0,NULL}; +pFile *the_pFile = NULL; + + +#define SET_BANK_BIT (1 << 16) +#define CLR_BANK_BIT 0 + +static peepCommand peepCommands[] = { + + {NOTBITSKIP, "_NOTBITSKIP_"}, + {BITSKIP, "_BITSKIP_"}, + {INVERTBITSKIP, "_INVERTBITSKIP_"}, + + {-1, NULL} +}; + static int mnemonics_initialized = 0; static hTab *pic14MnemonicsHash = NULL; static hTab *pic14pCodePeepCommandsHash = NULL; - -pFile *the_pFile = NULL; static pBlock *pb_dead_pcodes = NULL; /* Hardcoded flags to change the behavior of the PIC port */ static int functionInlining = 1; /* inline functions if nonzero */ -int debug_verbose = 0; /* Set true to inundate .asm file */ // static int GpCodeSequenceNumber = 1; -int GpcFlowSeq = 1; +static int GpcFlowSeq = 1; /* statistics (code size estimation) */ static unsigned int pcode_insns = 0; static unsigned int pcode_doubles = 0; +static unsigned peakIdx = 0; /* This keeps track of the peak register index for call tree register reuse */ -unsigned maxIdx; /* This keeps track of the maximum register index for call tree register reuse */ -unsigned peakIdx; /* This keeps track of the peak register index for call tree register reuse */ - -extern void RemoveUnusedRegisters(void); -extern void RegsUnMapLiveRanges(void); -extern void BuildFlowTree(pBlock *pb); -extern void pCodeRegOptimizeRegUsage(int level); -extern int picIsInitialized(void); -extern const char *pCodeOpType(pCodeOp *pcop); /****************************************************************/ /* Forward declarations */ /****************************************************************/ -void unlinkpCode(pCode *pc); #if 0 static void genericAnalyze(pCode *pc); static void AnalyzeGOTO(pCode *pc); @@ -105,26 +88,20 @@ static void AnalyzeRETURN(pCode *pc); static void genericDestruct(pCode *pc); static void genericPrint(FILE *of,pCode *pc); +static void pBlockStats(FILE *of, pBlock *pb); +static pCode *findFunction(char *fname); static void pCodePrintLabel(FILE *of, pCode *pc); static void pCodePrintFunction(FILE *of, pCode *pc); static void pCodeOpPrint(FILE *of, pCodeOp *pcop); static char *get_op_from_instruction( pCodeInstruction *pcc); -char *get_op( pCodeOp *pcop,char *buff,size_t buf_size); -int pCodePeepMatchLine(pCodePeep *peepBlock, pCode *pcs, pCode *pcd); -int pCodePeepMatchRule(pCode *pc); -void pBlockStats(FILE *of, pBlock *pb); -pBlock *newpBlock(void); -pCodeOp *popCopyGPR2Bit(pCodeOp *pc, int bitval); -void pCodeRegMapLiveRanges(pBlock *pb); - -pBranch * pBranchAppend(pBranch *h, pBranch *n); +static pBlock *newpBlock(void); /****************************************************************/ /* PIC Instructions */ /****************************************************************/ -pCodeInstruction pciADDWF = { +static pCodeInstruction pciADDWF = { {PC_OPCODE, NULL, NULL, 0, 0, NULL, // genericAnalyze, genericDestruct, @@ -146,7 +123,7 @@ pCodeInstruction pciADDWF = { (PCC_REGISTER | PCC_C | PCC_DC | PCC_Z) // outCond }; -pCodeInstruction pciADDFW = { +static pCodeInstruction pciADDFW = { {PC_OPCODE, NULL, NULL, 0, 0, NULL, // genericAnalyze, genericDestruct, @@ -168,7 +145,7 @@ pCodeInstruction pciADDFW = { (PCC_W | PCC_C | PCC_DC | PCC_Z) // outCond }; -pCodeInstruction pciADDLW = { +static pCodeInstruction pciADDLW = { {PC_OPCODE, NULL, NULL, 0, 0, NULL, // genericAnalyze, genericDestruct, @@ -190,7 +167,7 @@ pCodeInstruction pciADDLW = { (PCC_W | PCC_Z | PCC_C | PCC_DC) // outCond }; -pCodeInstruction pciANDLW = { +static pCodeInstruction pciANDLW = { {PC_OPCODE, NULL, NULL, 0, 0, NULL, // genericAnalyze, genericDestruct, @@ -212,7 +189,7 @@ pCodeInstruction pciANDLW = { (PCC_W | PCC_Z) // outCond }; -pCodeInstruction pciANDWF = { +static pCodeInstruction pciANDWF = { {PC_OPCODE, NULL, NULL, 0, 0, NULL, // genericAnalyze, genericDestruct, @@ -234,7 +211,7 @@ pCodeInstruction pciANDWF = { (PCC_REGISTER | PCC_Z) // outCond }; -pCodeInstruction pciANDFW = { +static pCodeInstruction pciANDFW = { {PC_OPCODE, NULL, NULL, 0, 0, NULL, // genericAnalyze, genericDestruct, @@ -256,7 +233,7 @@ pCodeInstruction pciANDFW = { (PCC_W | PCC_Z) // outCond }; -pCodeInstruction pciBCF = { +static pCodeInstruction pciBCF = { {PC_OPCODE, NULL, NULL, 0, 0, NULL, // genericAnalyze, genericDestruct, @@ -278,7 +255,7 @@ pCodeInstruction pciBCF = { (PCC_REGISTER | PCC_EXAMINE_PCOP) // outCond }; -pCodeInstruction pciBSF = { +static pCodeInstruction pciBSF = { {PC_OPCODE, NULL, NULL, 0, 0, NULL, // genericAnalyze, genericDestruct, @@ -300,7 +277,7 @@ pCodeInstruction pciBSF = { (PCC_REGISTER | PCC_EXAMINE_PCOP) // outCond }; -pCodeInstruction pciBTFSC = { +static pCodeInstruction pciBTFSC = { {PC_OPCODE, NULL, NULL, 0, 0, NULL, // AnalyzeSKIP, genericDestruct, @@ -322,7 +299,7 @@ pCodeInstruction pciBTFSC = { PCC_NONE // outCond }; -pCodeInstruction pciBTFSS = { +static pCodeInstruction pciBTFSS = { {PC_OPCODE, NULL, NULL, 0, 0, NULL, // AnalyzeSKIP, genericDestruct, @@ -344,7 +321,7 @@ pCodeInstruction pciBTFSS = { PCC_NONE // outCond }; -pCodeInstruction pciCALL = { +static pCodeInstruction pciCALL = { {PC_OPCODE, NULL, NULL, 0, 0, NULL, // genericAnalyze, genericDestruct, @@ -366,7 +343,7 @@ pCodeInstruction pciCALL = { (PCC_NONE | PCC_W | PCC_C | PCC_DC | PCC_Z) // outCond, flags are destroyed by called function }; -pCodeInstruction pciCOMF = { +static pCodeInstruction pciCOMF = { {PC_OPCODE, NULL, NULL, 0, 0, NULL, // genericAnalyze, genericDestruct, @@ -388,7 +365,7 @@ pCodeInstruction pciCOMF = { PCC_REGISTER | PCC_Z // outCond }; -pCodeInstruction pciCOMFW = { +static pCodeInstruction pciCOMFW = { {PC_OPCODE, NULL, NULL, 0, 0, NULL, // genericAnalyze, genericDestruct, @@ -410,7 +387,7 @@ pCodeInstruction pciCOMFW = { PCC_W | PCC_Z // outCond }; -pCodeInstruction pciCLRF = { +static pCodeInstruction pciCLRF = { {PC_OPCODE, NULL, NULL, 0, 0, NULL, // genericAnalyze, genericDestruct, @@ -432,7 +409,7 @@ pCodeInstruction pciCLRF = { PCC_REGISTER | PCC_Z // outCond }; -pCodeInstruction pciCLRW = { +static pCodeInstruction pciCLRW = { {PC_OPCODE, NULL, NULL, 0, 0, NULL, // genericAnalyze, genericDestruct, @@ -454,7 +431,7 @@ pCodeInstruction pciCLRW = { PCC_W | PCC_Z // outCond }; -pCodeInstruction pciCLRWDT = { +static pCodeInstruction pciCLRWDT = { {PC_OPCODE, NULL, NULL, 0, 0, NULL, // genericAnalyze, genericDestruct, @@ -476,7 +453,7 @@ pCodeInstruction pciCLRWDT = { PCC_NONE // outCond }; -pCodeInstruction pciDECF = { +static pCodeInstruction pciDECF = { {PC_OPCODE, NULL, NULL, 0, 0, NULL, // genericAnalyze, genericDestruct, @@ -498,7 +475,7 @@ pCodeInstruction pciDECF = { PCC_REGISTER | PCC_Z // outCond }; -pCodeInstruction pciDECFW = { +static pCodeInstruction pciDECFW = { {PC_OPCODE, NULL, NULL, 0, 0, NULL, // genericAnalyze, genericDestruct, @@ -520,7 +497,7 @@ pCodeInstruction pciDECFW = { PCC_W | PCC_Z // outCond }; -pCodeInstruction pciDECFSZ = { +static pCodeInstruction pciDECFSZ = { {PC_OPCODE, NULL, NULL, 0, 0, NULL, // AnalyzeSKIP, genericDestruct, @@ -542,7 +519,7 @@ pCodeInstruction pciDECFSZ = { PCC_REGISTER | PCC_Z // outCond }; -pCodeInstruction pciDECFSZW = { +static pCodeInstruction pciDECFSZW = { {PC_OPCODE, NULL, NULL, 0, 0, NULL, // AnalyzeSKIP, genericDestruct, @@ -564,7 +541,7 @@ pCodeInstruction pciDECFSZW = { PCC_W | PCC_Z // outCond }; -pCodeInstruction pciGOTO = { +static pCodeInstruction pciGOTO = { {PC_OPCODE, NULL, NULL, 0, 0, NULL, // AnalyzeGOTO, genericDestruct, @@ -586,7 +563,7 @@ pCodeInstruction pciGOTO = { PCC_NONE // outCond }; -pCodeInstruction pciINCF = { +static pCodeInstruction pciINCF = { {PC_OPCODE, NULL, NULL, 0, 0, NULL, // genericAnalyze, genericDestruct, @@ -608,7 +585,7 @@ pCodeInstruction pciINCF = { PCC_REGISTER | PCC_Z // outCond }; -pCodeInstruction pciINCFW = { +static pCodeInstruction pciINCFW = { {PC_OPCODE, NULL, NULL, 0, 0, NULL, // genericAnalyze, genericDestruct, @@ -630,7 +607,7 @@ pCodeInstruction pciINCFW = { PCC_W | PCC_Z // outCond }; -pCodeInstruction pciINCFSZ = { +static pCodeInstruction pciINCFSZ = { {PC_OPCODE, NULL, NULL, 0, 0, NULL, // AnalyzeSKIP, genericDestruct, @@ -652,7 +629,7 @@ pCodeInstruction pciINCFSZ = { PCC_REGISTER | PCC_Z // outCond }; -pCodeInstruction pciINCFSZW = { +static pCodeInstruction pciINCFSZW = { {PC_OPCODE, NULL, NULL, 0, 0, NULL, // AnalyzeSKIP, genericDestruct, @@ -674,7 +651,7 @@ pCodeInstruction pciINCFSZW = { PCC_W | PCC_Z // outCond }; -pCodeInstruction pciIORWF = { +static pCodeInstruction pciIORWF = { {PC_OPCODE, NULL, NULL, 0, 0, NULL, // genericAnalyze, genericDestruct, @@ -696,7 +673,7 @@ pCodeInstruction pciIORWF = { (PCC_REGISTER | PCC_Z) // outCond }; -pCodeInstruction pciIORFW = { +static pCodeInstruction pciIORFW = { {PC_OPCODE, NULL, NULL, 0, 0, NULL, // genericAnalyze, genericDestruct, @@ -718,7 +695,7 @@ pCodeInstruction pciIORFW = { (PCC_W | PCC_Z) // outCond }; -pCodeInstruction pciIORLW = { +static pCodeInstruction pciIORLW = { {PC_OPCODE, NULL, NULL, 0, 0, NULL, // genericAnalyze, genericDestruct, @@ -740,7 +717,7 @@ pCodeInstruction pciIORLW = { (PCC_W | PCC_Z) // outCond }; -pCodeInstruction pciMOVF = { +static pCodeInstruction pciMOVF = { {PC_OPCODE, NULL, NULL, 0, 0, NULL, // genericAnalyze, genericDestruct, @@ -762,7 +739,7 @@ pCodeInstruction pciMOVF = { PCC_Z // outCond }; -pCodeInstruction pciMOVFW = { +static pCodeInstruction pciMOVFW = { {PC_OPCODE, NULL, NULL, 0, 0, NULL, // genericAnalyze, genericDestruct, @@ -784,7 +761,7 @@ pCodeInstruction pciMOVFW = { (PCC_W | PCC_Z) // outCond }; -pCodeInstruction pciMOVWF = { +static pCodeInstruction pciMOVWF = { {PC_OPCODE, NULL, NULL, 0, 0, NULL, // genericAnalyze, genericDestruct, @@ -806,7 +783,7 @@ pCodeInstruction pciMOVWF = { PCC_REGISTER // outCond }; -pCodeInstruction pciMOVLW = { +static pCodeInstruction pciMOVLW = { {PC_OPCODE, NULL, NULL, 0, 0, NULL, genericDestruct, genericPrint}, @@ -827,7 +804,7 @@ pCodeInstruction pciMOVLW = { PCC_W // outCond }; -pCodeInstruction pciNOP = { +static pCodeInstruction pciNOP = { {PC_OPCODE, NULL, NULL, 0, 0, NULL, genericDestruct, genericPrint}, @@ -848,7 +825,7 @@ pCodeInstruction pciNOP = { PCC_NONE // outCond }; -pCodeInstruction pciRETFIE = { +static pCodeInstruction pciRETFIE = { {PC_OPCODE, NULL, NULL, 0, 0, NULL, // AnalyzeRETURN, genericDestruct, @@ -870,7 +847,7 @@ pCodeInstruction pciRETFIE = { (PCC_NONE | PCC_C | PCC_DC | PCC_Z) // outCond (not true... affects the GIE bit too), STATUS bit are retored }; -pCodeInstruction pciRETLW = { +static pCodeInstruction pciRETLW = { {PC_OPCODE, NULL, NULL, 0, 0, NULL, // AnalyzeRETURN, genericDestruct, @@ -892,7 +869,7 @@ pCodeInstruction pciRETLW = { (PCC_W| PCC_C | PCC_DC | PCC_Z) // outCond, STATUS bits are irrelevant after RETLW }; -pCodeInstruction pciRETURN = { +static pCodeInstruction pciRETURN = { {PC_OPCODE, NULL, NULL, 0, 0, NULL, // AnalyzeRETURN, genericDestruct, @@ -914,7 +891,7 @@ pCodeInstruction pciRETURN = { (PCC_NONE | PCC_C | PCC_DC | PCC_Z) // outCond, STATUS bits are irrelevant after RETURN }; -pCodeInstruction pciRLF = { +static pCodeInstruction pciRLF = { {PC_OPCODE, NULL, NULL, 0, 0, NULL, // genericAnalyze, genericDestruct, @@ -936,7 +913,7 @@ pCodeInstruction pciRLF = { (PCC_REGISTER | PCC_C ) // outCond }; -pCodeInstruction pciRLFW = { +static pCodeInstruction pciRLFW = { {PC_OPCODE, NULL, NULL, 0, 0, NULL, // genericAnalyze, genericDestruct, @@ -958,7 +935,7 @@ pCodeInstruction pciRLFW = { (PCC_W | PCC_C) // outCond }; -pCodeInstruction pciRRF = { +static pCodeInstruction pciRRF = { {PC_OPCODE, NULL, NULL, 0, 0, NULL, // genericAnalyze, genericDestruct, @@ -980,7 +957,7 @@ pCodeInstruction pciRRF = { (PCC_REGISTER | PCC_C) // outCond }; -pCodeInstruction pciRRFW = { +static pCodeInstruction pciRRFW = { {PC_OPCODE, NULL, NULL, 0, 0, NULL, // genericAnalyze, genericDestruct, @@ -1002,7 +979,7 @@ pCodeInstruction pciRRFW = { (PCC_W | PCC_C) // outCond }; -pCodeInstruction pciSUBWF = { +static pCodeInstruction pciSUBWF = { {PC_OPCODE, NULL, NULL, 0, 0, NULL, // genericAnalyze, genericDestruct, @@ -1024,7 +1001,7 @@ pCodeInstruction pciSUBWF = { (PCC_REGISTER | PCC_C | PCC_DC | PCC_Z) // outCond }; -pCodeInstruction pciSUBFW = { +static pCodeInstruction pciSUBFW = { {PC_OPCODE, NULL, NULL, 0, 0, NULL, // genericAnalyze, genericDestruct, @@ -1046,7 +1023,7 @@ pCodeInstruction pciSUBFW = { (PCC_W | PCC_C | PCC_DC | PCC_Z) // outCond }; -pCodeInstruction pciSUBLW = { +static pCodeInstruction pciSUBLW = { {PC_OPCODE, NULL, NULL, 0, 0, NULL, // genericAnalyze, genericDestruct, @@ -1068,7 +1045,7 @@ pCodeInstruction pciSUBLW = { (PCC_W | PCC_Z | PCC_C | PCC_DC) // outCond }; -pCodeInstruction pciSWAPF = { +static pCodeInstruction pciSWAPF = { {PC_OPCODE, NULL, NULL, 0, 0, NULL, // genericAnalyze, genericDestruct, @@ -1090,7 +1067,7 @@ pCodeInstruction pciSWAPF = { (PCC_REGISTER) // outCond }; -pCodeInstruction pciSWAPFW = { +static pCodeInstruction pciSWAPFW = { {PC_OPCODE, NULL, NULL, 0, 0, NULL, // genericAnalyze, genericDestruct, @@ -1112,7 +1089,7 @@ pCodeInstruction pciSWAPFW = { (PCC_W) // outCond }; -pCodeInstruction pciTRIS = { +static pCodeInstruction pciTRIS = { {PC_OPCODE, NULL, NULL, 0, 0, NULL, // genericAnalyze, genericDestruct, @@ -1134,7 +1111,7 @@ pCodeInstruction pciTRIS = { PCC_REGISTER // outCond /* FIXME: what's TRIS doing */ }; -pCodeInstruction pciXORWF = { +static pCodeInstruction pciXORWF = { {PC_OPCODE, NULL, NULL, 0, 0, NULL, // genericAnalyze, genericDestruct, @@ -1156,7 +1133,7 @@ pCodeInstruction pciXORWF = { (PCC_REGISTER | PCC_Z) // outCond }; -pCodeInstruction pciXORFW = { +static pCodeInstruction pciXORFW = { {PC_OPCODE, NULL, NULL, 0, 0, NULL, // genericAnalyze, genericDestruct, @@ -1178,7 +1155,7 @@ pCodeInstruction pciXORFW = { (PCC_W | PCC_Z) // outCond }; -pCodeInstruction pciXORLW = { +static pCodeInstruction pciXORLW = { {PC_OPCODE, NULL, NULL, 0, 0, NULL, // genericAnalyze, genericDestruct, @@ -1201,7 +1178,7 @@ pCodeInstruction pciXORLW = { }; -pCodeInstruction pciBANKSEL = { +static pCodeInstruction pciBANKSEL = { {PC_OPCODE, NULL, NULL, 0, 0, NULL, // genericAnalyze, genericDestruct, @@ -1223,7 +1200,7 @@ pCodeInstruction pciBANKSEL = { PCC_NONE // outCond }; -pCodeInstruction pciPAGESEL = { +static pCodeInstruction pciPAGESEL = { {PC_OPCODE, NULL, NULL, 0, 0, NULL, // genericAnalyze, genericDestruct, @@ -1251,7 +1228,7 @@ pCodeInstruction *pic14Mnemonics[MAX_PIC14MNEMONICS]; /*-----------------------------------------------------------------*/ /* return a unique ID number to assist pCodes debuging */ /*-----------------------------------------------------------------*/ -unsigned PCodeID(void) { +static unsigned PCodeID(void) { static unsigned int pcodeId = 1; /* unique ID number to be assigned to all pCodes */ /* static unsigned int stop; @@ -1261,11 +1238,6 @@ unsigned PCodeID(void) { return pcodeId++; } -extern void initStack(int base_address, int size, int shared); -extern regs *allocProcessorRegister(int rIdx, char * name, short po_type, int alias); -extern regs *allocInternalRegister(int rIdx, char * name, PIC_OPTYPE po_type, int alias); -extern PIC_device *init_pic(char *); - void pCodeInitRegisters(void) { static int initialized=0; @@ -1330,7 +1302,7 @@ void pCodeInitRegisters(void) /* */ /*-----------------------------------------------------------------*/ -int mnem2key(unsigned char const *mnem) +static int mnem2key(unsigned char const *mnem) { int key = 0; @@ -1347,7 +1319,7 @@ int mnem2key(unsigned char const *mnem) } -void pic14initMnemonics(void) +static void pic14initMnemonics(void) { int i = 0; int key; @@ -1425,8 +1397,6 @@ void pic14initMnemonics(void) mnemonics_initialized = 1; } -int getpCodePeepCommand(char *cmd); - int getpCode(char *mnem,unsigned dest) { @@ -1505,7 +1475,7 @@ int getpCodePeepCommand(char *cmd) return -1; } -char getpBlock_dbName(pBlock *pb) +static char getpBlock_dbName(pBlock *pb) { if(!pb) return 0; @@ -1774,8 +1744,8 @@ pCode *newpCodeWild(int pCodeID, pCodeOp *optional_operand, pCodeOp *optional_la /* newPcodeInlineP - create a new pCode from a char string */ /*-----------------------------------------------------------------*/ - -pCode *newpCodeInlineP(char *cP) +#if 0 +static pCode *newpCodeInlineP(char *cP) { pCodeComment *pcc ; @@ -1800,6 +1770,7 @@ pCode *newpCodeInlineP(char *cP) return ( (pCode *)pcc); } +#endif /*-----------------------------------------------------------------*/ /* newPcodeCharP - create a new pCode from a char string */ @@ -1878,7 +1849,7 @@ pCode *newpCodeFunction(char *mod,char *f,int isPublic) /*-----------------------------------------------------------------*/ /* newpCodeFlow */ /*-----------------------------------------------------------------*/ -void destructpCodeFlow(pCode *pc) +static void destructpCodeFlow(pCode *pc) { if(!pc || !isPCFL(pc)) return; @@ -1896,7 +1867,7 @@ void destructpCodeFlow(pCode *pc) } -pCode *newpCodeFlow(void ) +static pCode *newpCodeFlow(void ) { pCodeFlow *pcflow; @@ -1934,7 +1905,7 @@ pCode *newpCodeFlow(void ) /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ -pCodeFlowLink *newpCodeFlowLink(pCodeFlow *pcflow) +static pCodeFlowLink *newpCodeFlowLink(pCodeFlow *pcflow) { pCodeFlowLink *pcflowLink; @@ -2076,7 +2047,7 @@ pCode *newpCodeLabel(char *name, int key) /*-----------------------------------------------------------------*/ /* newpBlock - create and return a pointer to a new pBlock */ /*-----------------------------------------------------------------*/ -pBlock *newpBlock(void) +static pBlock *newpBlock(void) { pBlock *PpB; @@ -2288,7 +2259,7 @@ pCodeOp *newpCodeOpBit(char *name, int ibit, int inBitSpace) } #if 0 -pCodeOp *newpCodeOpBitReg(regs *reg, int ibit, int inBitSpace) +static pCodeOp *newpCodeOpBitReg(regs *reg, int ibit, int inBitSpace) { pCodeOp *pcop; @@ -2314,7 +2285,7 @@ pCodeOp *newpCodeOpBitReg(regs *reg, int ibit, int inBitSpace) * for. *-----------------------------------------------------------------*/ -pCodeOp *newpCodeOpReg(int rIdx) +static pCodeOp *newpCodeOpReg(int rIdx) { pCodeOp *pcop; @@ -2351,7 +2322,7 @@ pCodeOp *newpCodeOpRegFromStr(char *name) return pcop; } -pCodeOp *newpCodeOpStr(char *name) +static pCodeOp *newpCodeOpStr(char *name) { pCodeOp *pcop; @@ -2414,9 +2385,10 @@ pCodeOp *newpCodeOp(char *name, PIC_OPTYPE type) return pcop; } +#if 0 /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ -void pCodeConstString(char *name, char *value) +static void pCodeConstString(char *name, char *value) { pBlock *pb; unsigned i; @@ -2453,7 +2425,7 @@ void pCodeConstString(char *name, char *value) /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ -void pCodeReadCodeTable(void) +static void pCodeReadCodeTable(void) { pBlock *pb; @@ -2475,6 +2447,7 @@ void pCodeReadCodeTable(void) } +#endif /*-----------------------------------------------------------------*/ /* addpCode2pBlock - place the pCode into the pBlock linked list */ @@ -2526,7 +2499,7 @@ void addpBlock(pBlock *pb) /*-----------------------------------------------------------------*/ /* removepBlock - remove a pBlock from the pFile */ /*-----------------------------------------------------------------*/ -void removepBlock(pBlock *pb) +static void removepBlock(pBlock *pb) { pBlock *pbs; @@ -2893,9 +2866,10 @@ void pCodeDeleteChain(pCode *f,pCode *t) } } +#if 0 /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ -void pBlockRegs(FILE *of, pBlock *pb) +static void pBlockRegs(FILE *of, pBlock *pb) { regs *r; @@ -2905,7 +2879,7 @@ void pBlockRegs(FILE *of, pBlock *pb) r = setNextItem(pb->tregisters); } } - +#endif /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ @@ -3543,7 +3517,7 @@ static void genericAnalyze(pCode *pc) /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ -int compareLabel(pCode *pc, pCodeOpLabel *pcop_label) +static int compareLabel(pCode *pc, pCodeOpLabel *pcop_label) { pBranch *pbr; @@ -3567,7 +3541,7 @@ int compareLabel(pCode *pc, pCodeOpLabel *pcop_label) /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ -int checkLabel(pCode *pc) +static int checkLabel(pCode *pc) { pBranch *pbr; @@ -3587,7 +3561,7 @@ int checkLabel(pCode *pc) /*-----------------------------------------------------------------*/ /* findLabelinpBlock - Search the pCode for a particular label */ /*-----------------------------------------------------------------*/ -pCode * findLabelinpBlock(pBlock *pb,pCodeOpLabel *pcop_label) +static pCode * findLabelinpBlock(pBlock *pb,pCodeOpLabel *pcop_label) { pCode *pc; @@ -3601,10 +3575,11 @@ pCode * findLabelinpBlock(pBlock *pb,pCodeOpLabel *pcop_label) return NULL; } +#if 0 /*-----------------------------------------------------------------*/ /* findLabel - Search the pCode for a particular label */ /*-----------------------------------------------------------------*/ -pCode * findLabel(pCodeOpLabel *pcop_label) +static pCode * findLabel(pCodeOpLabel *pcop_label) { pBlock *pb; pCode *pc; @@ -3620,6 +3595,7 @@ pCode * findLabel(pCodeOpLabel *pcop_label) fprintf(stderr,"Couldn't find label %s\n", pcop_label->pcop.name); return NULL; } +#endif /*-----------------------------------------------------------------*/ /* findNextpCode - given a pCode, find the next of type 'pct' */ @@ -3638,11 +3614,12 @@ pCode * findNextpCode(pCode *pc, PC_TYPE pct) return NULL; } +#if 0 /*-----------------------------------------------------------------*/ /* findPrevpCode - given a pCode, find the previous of type 'pct' */ /* in the linked list */ /*-----------------------------------------------------------------*/ -pCode * findPrevpCode(pCode *pc, PC_TYPE pct) +static pCode * findPrevpCode(pCode *pc, PC_TYPE pct) { while(pc) { @@ -3660,6 +3637,7 @@ pCode * findPrevpCode(pCode *pc, PC_TYPE pct) return NULL; } +#endif /*-----------------------------------------------------------------*/ /* findNextInstruction - given a pCode, find the next instruction */ @@ -3713,11 +3691,12 @@ pCode * findPrevInstruction(pCode *pci) return NULL; } +#if 0 /*-----------------------------------------------------------------*/ /* findFunctionEnd - given a pCode find the end of the function */ /* that contains it */ /*-----------------------------------------------------------------*/ -pCode * findFunctionEnd(pCode *pc) +static pCode * findFunctionEnd(pCode *pc) { while(pc) { if(pc->type == PC_FUNCTION && !(PCF(pc)->fname)) @@ -3729,6 +3708,7 @@ pCode * findFunctionEnd(pCode *pc) fprintf(stderr,"Couldn't find function end\n"); return NULL; } +#endif #if 0 /*-----------------------------------------------------------------*/ @@ -3819,7 +3799,7 @@ regs * getRegFromInstruction(pCode *pc) /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ -void AnalyzepBlock(pBlock *pb) +static void AnalyzepBlock(pBlock *pb) { pCode *pc; @@ -3883,7 +3863,7 @@ void AnalyzepBlock(pBlock *pb) /*-----------------------------------------------------------------*/ /* */ /*-----------------------------------------------------------------*/ -void InsertpFlow(pCode *pc, pCode **pflow) +static void InsertpFlow(pCode *pc, pCode **pflow) { if(*pflow) PCFL(*pflow)->end = pc; @@ -3903,7 +3883,7 @@ void InsertpFlow(pCode *pc, pCode **pflow) * point the instruction flow changes. */ /*-----------------------------------------------------------------*/ -void BuildFlow(pBlock *pb) +static void BuildFlow(pBlock *pb) { pCode *pc; pCode *last_pci=NULL; @@ -4005,7 +3985,7 @@ void BuildFlow(pBlock *pb) * unBuildFlow removes pCodeFlow objects from a pCode chain */ /*-----------------------------------------------------------------*/ -void unBuildFlow(pBlock *pb) +static void unBuildFlow(pBlock *pb) { pCode *pc,*pcnext; @@ -4034,9 +4014,10 @@ void unBuildFlow(pBlock *pb) } +#if 0 /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ -void dumpCond(int cond) +static void dumpCond(int cond) { static char *pcc_str[] = { @@ -4063,10 +4044,12 @@ void dumpCond(int cond) fprintf(stderr, " %s\n",pcc_str[i]); } +#endif +#if 0 /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ -void FlowStats(pCodeFlow *pcflow) +static void FlowStats(pCodeFlow *pcflow) { pCode *pc; @@ -4090,6 +4073,7 @@ void FlowStats(pCodeFlow *pcflow) dumpCond(pcflow->outCond); } +#endif /*-----------------------------------------------------------------* * int isBankInstruction(pCode *pc) - examine the pCode *pc to determine @@ -4106,9 +4090,6 @@ void FlowStats(pCodeFlow *pcflow) * *-----------------------------------------------------------------*/ /* -#define SET_BANK_BIT (1 << 16) -#define CLR_BANK_BIT 0 - static int isBankInstruction(pCode *pc) { regs *reg; @@ -4204,7 +4185,7 @@ static void FillFlow(pCodeFlow *pcflow) /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ -void LinkFlow_pCode(pCodeInstruction *from, pCodeInstruction *to) +static void LinkFlow_pCode(pCodeInstruction *from, pCodeInstruction *to) { pCodeFlowLink *fromLink, *toLink; #if 0 @@ -4238,7 +4219,7 @@ void LinkFlow_pCode(pCodeInstruction *from, pCodeInstruction *to) * with a skip, then we know that there are two possible flow segments * to which control may be passed. *-----------------------------------------------------------------*/ -void LinkFlow(pBlock *pb) +static void LinkFlow(pBlock *pb) { pCode *pc=NULL; pCode *pcflow; @@ -4330,9 +4311,10 @@ void LinkFlow(pBlock *pb) /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ +#if 0 /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ -int isPCinFlow(pCode *pc, pCode *pcflow) +static int isPCinFlow(pCode *pc, pCode *pcflow) { if(!pc || !pcflow) @@ -4346,6 +4328,31 @@ int isPCinFlow(pCode *pc, pCode *pcflow) return 0; } +#endif + +#if 0 +static int isREGinBank(regs *reg, int bank) +{ + + if(!reg || !pic) + return 0; + + if((int)((reg->address | reg->alias) & pic->bankMask & bank) == bank) + return 1; + + return 0; +} + +static int REGallBanks(regs *reg) +{ + + if(!reg || !pic) + return 0; + + return ((reg->address | reg->alias) & pic->bankMask); + +} +#endif /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ @@ -4435,7 +4442,7 @@ static void BanksUsedFlow(pBlock *pb) } */ -void pCodeReplace (pCode *old, pCode *new) +static void pCodeReplace (pCode *old, pCode *new) { pCodeInsertAfter (old, new); @@ -4455,7 +4462,7 @@ void pCodeReplace (pCode *old, pCode *new) /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ -void addpCodeComment(pCode *pc, const char *fmt, ...) +static void addpCodeComment(pCode *pc, const char *fmt, ...) { va_list ap; char buffer[4096]; @@ -4473,7 +4480,6 @@ void addpCodeComment(pCode *pc, const char *fmt, ...) va_end(ap); } -void pBlockMergeLabels(pBlock *pb); /*-----------------------------------------------------------------*/ /* Inserts a new pCodeInstruction before an existing one */ /*-----------------------------------------------------------------*/ @@ -4590,9 +4596,36 @@ static int bankCompare(const char *op1, const char *op2) return 0; } +/* + * Interface to BANKSEL generation. + * This function should return != 0 iff str1 and str2 denote operands that + * are known to be allocated into the same bank. Consequently, there will + * be no BANKSEL emitted if str2 is accessed while str1 has been used to + * select the current bank just previously. + * + * If in doubt, return 0. + */ +static int +pic14_operandsAllocatedInSameBank(const char *str1, const char *str2) { + // see glue.c(pic14printLocals) + + if (getenv("SDCC_PIC14_SPLIT_LOCALS")) { + // no clustering applied, each register resides in its own bank + } else { + // check whether BOTH names are local registers + // XXX: This is some kind of shortcut, should be safe... + // In this model, all r0xXXXX are allocated into a single section + // per file, so no BANKSEL required if accessing a r0xXXXX after a + // (different) r0xXXXX. Works great for multi-byte operands. + if (str1 && str2 && str1[0] == 'r' && str2[0] == 'r') return (1); + } // if + + // assume operands in different banks + return (0); +} + /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ -extern int pic14_operandsAllocatedInSameBank(const char *str1, const char *str2); static int sameBank(regs *reg, regs *previous_reg, const char *new_bank, const char *cur_bank, unsigned max_mask) { if (!cur_bank) return 0; @@ -4615,7 +4648,7 @@ static int sameBank(regs *reg, regs *previous_reg, const char *new_bank, const c /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ -void FixRegisterBanking(pBlock *pb) +static void FixRegisterBanking(pBlock *pb) { pCode *pc; pCodeInstruction *pci; @@ -4715,7 +4748,7 @@ void FixRegisterBanking(pBlock *pb) /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ -int OptimizepBlock(pBlock *pb) +static int OptimizepBlock(pBlock *pb) { pCode *pc, *pcprev; int matches =0; @@ -4758,7 +4791,7 @@ int OptimizepBlock(pBlock *pb) /*-----------------------------------------------------------------*/ /* pBlockRemoveUnusedLabels - remove the pCode labels from the */ /*-----------------------------------------------------------------*/ -pCode * findInstructionUsingLabel(pCodeLabel *pcl, pCode *pcs) +static pCode * findInstructionUsingLabel(pCodeLabel *pcl, pCode *pcs) { pCode *pc; @@ -4776,7 +4809,7 @@ pCode * findInstructionUsingLabel(pCodeLabel *pcl, pCode *pcs) /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ -void exchangeLabels(pCodeLabel *pcl, pCode *pc) +static void exchangeLabels(pCodeLabel *pcl, pCode *pc) { char *s=NULL; @@ -4816,7 +4849,7 @@ void exchangeLabels(pCodeLabel *pcl, pCode *pc) /* pBlockRemoveUnusedLabels - remove the pCode labels from the */ /* pCode chain if they're not used. */ /*-----------------------------------------------------------------*/ -void pBlockRemoveUnusedLabels(pBlock *pb) +static void pBlockRemoveUnusedLabels(pBlock *pb) { pCode *pc; pCodeLabel *pcl; @@ -4862,7 +4895,6 @@ void pBlockRemoveUnusedLabels(pBlock *pb) * refers to it */ if( (pcl->key>0) && (!findInstructionUsingLabel(pcl, pb->pcHead))) { - //if( !findInstructionUsingLabel(pcl, pb->pcHead)) { /* Couldn't find an instruction that refers to this label * So, unlink the pCode label from it's pCode chain * and destroy the label */ @@ -4905,7 +4937,6 @@ void pBlockMergeLabels(pBlock *pb) /* Now loop through the pBlock and merge the labels with the opcodes */ pc = pb->pcHead; - // for(pc = pb->pcHead; pc; pc = pc->next) { while(pc) { pCode *pcn = pc->next; @@ -4957,7 +4988,7 @@ void pBlockMergeLabels(pBlock *pb) /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ -int OptimizepCode(char dbName) +static int OptimizepCode(char dbName) { #define MAX_PASSES 4 @@ -5002,7 +5033,7 @@ pCodeOp *popCopyGPR2Bit(pCodeOp *pc, int bitval) /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ -void pBlockDestruct(pBlock *pb) +static void pBlockDestruct(pBlock *pb) { if(!pb) @@ -5018,7 +5049,7 @@ void pBlockDestruct(pBlock *pb) /* name dbName and combine them */ /* into one block */ /*-----------------------------------------------------------------*/ -void mergepBlocks(char dbName) +static void mergepBlocks(char dbName) { pBlock *pb, *pbmerged = NULL,*pbn; @@ -5065,115 +5096,115 @@ void mergepBlocks(char dbName) /* register. */ /*-----------------------------------------------------------------*/ -void AnalyzeFlow(int level) +static void AnalyzeFlow(int level) { - static int times_called=0; - - pBlock *pb; - - if(!the_pFile) - return; - - - /* if this is not the first time this function has been called, - then clean up old flow information */ - if(times_called++) { - for(pb = the_pFile->pbHead; pb; pb = pb->next) - unBuildFlow(pb); - - RegsUnMapLiveRanges(); - - } - - GpcFlowSeq = 1; - - /* Phase 2 - Flow Analysis - Register Banking - * - * In this phase, the individual flow blocks are examined - * and register banking is fixed. - */ - - //for(pb = the_pFile->pbHead; pb; pb = pb->next) - //FixRegisterBanking(pb); - - /* Phase 2 - Flow Analysis - * - * In this phase, the pCode is partition into pCodeFlow - * blocks. The flow blocks mark the points where a continuous - * stream of instructions changes flow (e.g. because of - * a call or goto or whatever). - */ - - for(pb = the_pFile->pbHead; pb; pb = pb->next) - BuildFlow(pb); - - - /* Phase 2 - Flow Analysis - linking flow blocks - * - * In this phase, the individual flow blocks are examined - * to determine their order of excution. - */ - - for(pb = the_pFile->pbHead; pb; pb = pb->next) - LinkFlow(pb); - - /* Phase 3 - Flow Analysis - Flow Tree - * - * In this phase, the individual flow blocks are examined - * to determine their order of excution. - */ - - for(pb = the_pFile->pbHead; pb; pb = pb->next) - BuildFlowTree(pb); - - - /* Phase x - Flow Analysis - Used Banks - * - * In this phase, the individual flow blocks are examined - * to determine the Register Banks they use - */ - - // for(pb = the_pFile->pbHead; pb; pb = pb->next) - // FixBankFlow(pb); - - - for(pb = the_pFile->pbHead; pb; pb = pb->next) - pCodeRegMapLiveRanges(pb); - - RemoveUnusedRegisters(); - - // for(pb = the_pFile->pbHead; pb; pb = pb->next) - pCodeRegOptimizeRegUsage(level); - - OptimizepCode('*'); - - /* - for(pb = the_pFile->pbHead; pb; pb = pb->next) - DumpFlow(pb); - */ - /* debug stuff */ - /* - for(pb = the_pFile->pbHead; pb; pb = pb->next) { - pCode *pcflow; - for( pcflow = findNextpCode(pb->pcHead, PC_FLOW); - (pcflow = findNextpCode(pcflow, PC_FLOW)) != NULL; - pcflow = pcflow->next) { - - FillFlow(PCFL(pcflow)); - } - } - */ - /* - for(pb = the_pFile->pbHead; pb; pb = pb->next) { - pCode *pcflow; - for( pcflow = findNextpCode(pb->pcHead, PC_FLOW); - (pcflow = findNextpCode(pcflow, PC_FLOW)) != NULL; - pcflow = pcflow->next) { - - FlowStats(PCFL(pcflow)); - } - } - */ + static int times_called=0; + + pBlock *pb; + + if(!the_pFile) + return; + + + /* if this is not the first time this function has been called, + then clean up old flow information */ + if(times_called++) { + for(pb = the_pFile->pbHead; pb; pb = pb->next) + unBuildFlow(pb); + + RegsUnMapLiveRanges(); + + } + + GpcFlowSeq = 1; + + /* Phase 2 - Flow Analysis - Register Banking + * + * In this phase, the individual flow blocks are examined + * and register banking is fixed. + */ + + //for(pb = the_pFile->pbHead; pb; pb = pb->next) + //FixRegisterBanking(pb); + + /* Phase 2 - Flow Analysis + * + * In this phase, the pCode is partition into pCodeFlow + * blocks. The flow blocks mark the points where a continuous + * stream of instructions changes flow (e.g. because of + * a call or goto or whatever). + */ + + for(pb = the_pFile->pbHead; pb; pb = pb->next) + BuildFlow(pb); + + + /* Phase 2 - Flow Analysis - linking flow blocks + * + * In this phase, the individual flow blocks are examined + * to determine their order of excution. + */ + + for(pb = the_pFile->pbHead; pb; pb = pb->next) + LinkFlow(pb); + + /* Phase 3 - Flow Analysis - Flow Tree + * + * In this phase, the individual flow blocks are examined + * to determine their order of excution. + */ + + for(pb = the_pFile->pbHead; pb; pb = pb->next) + BuildFlowTree(pb); + + + /* Phase x - Flow Analysis - Used Banks + * + * In this phase, the individual flow blocks are examined + * to determine the Register Banks they use + */ + +// for(pb = the_pFile->pbHead; pb; pb = pb->next) +// FixBankFlow(pb); + + + for(pb = the_pFile->pbHead; pb; pb = pb->next) + pCodeRegMapLiveRanges(pb); + + RemoveUnusedRegisters(); + +// for(pb = the_pFile->pbHead; pb; pb = pb->next) + pCodeRegOptimizeRegUsage(level); + + OptimizepCode('*'); + + /* + for(pb = the_pFile->pbHead; pb; pb = pb->next) + DumpFlow(pb); + */ + /* debug stuff */ + /* + for(pb = the_pFile->pbHead; pb; pb = pb->next) { + pCode *pcflow; + for( pcflow = findNextpCode(pb->pcHead, PC_FLOW); + (pcflow = findNextpCode(pcflow, PC_FLOW)) != NULL; + pcflow = pcflow->next) { + + FillFlow(PCFL(pcflow)); + } + } + */ + /* + for(pb = the_pFile->pbHead; pb; pb = pb->next) { + pCode *pcflow; + for( pcflow = findNextpCode(pb->pcHead, PC_FLOW); + (pcflow = findNextpCode(pcflow, PC_FLOW)) != NULL; + pcflow = pcflow->next) { + + FlowStats(PCFL(pcflow)); + } + } + */ } /*-----------------------------------------------------------------*/ @@ -5214,7 +5245,7 @@ void AnalyzeBanking(void) /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ -DEFSETFUNC (resetrIdx) +static DEFSETFUNC (resetrIdx) { regs *r = (regs *)item; if (!r->isFixed) { @@ -5227,7 +5258,7 @@ DEFSETFUNC (resetrIdx) /*-----------------------------------------------------------------*/ /* InitRegReuse - Initialises variables for code analyzer */ /*-----------------------------------------------------------------*/ -void InitReuseReg(void) +static void InitReuseReg(void) { /* Find end of statically allocated variables for start idx */ /* Start from begining of GPR. Note may not be 0x20 on some PICs */ @@ -5356,7 +5387,7 @@ void ReuseReg(void) /* */ /*-----------------------------------------------------------------*/ -void buildCallTree(void ) +static void buildCallTree(void) { pBranch *pbr; pBlock *pb; @@ -5365,32 +5396,32 @@ void buildCallTree(void ) if(!the_pFile) return; - /* Now build the call tree. - First we examine all of the pCodes for functions. - Keep in mind that the function boundaries coincide - with pBlock boundaries. - - The algorithm goes something like this: - We have two nested loops. The outer loop iterates - through all of the pBlocks/functions. The inner - loop iterates through all of the pCodes for - a given pBlock. When we begin iterating through - a pBlock, the variable pc_fstart, pCode of the start - of a function, is cleared. We then search for pCodes - of type PC_FUNCTION. When one is encountered, we - initialize pc_fstart to this and at the same time - associate a new pBranch object that signifies a - branch entry. If a return is found, then this signifies - a function exit point. We'll link the pCodes of these - returns to the matching pc_fstart. - - When we're done, a doubly linked list of pBranches - will exist. The head of this list is stored in - `the_pFile', which is the meta structure for all - of the pCode. Look at the printCallTree function - on how the pBranches are linked together. - - */ + /* Now build the call tree. + First we examine all of the pCodes for functions. + Keep in mind that the function boundaries coincide + with pBlock boundaries. + + The algorithm goes something like this: + We have two nested loops. The outer loop iterates + through all of the pBlocks/functions. The inner + loop iterates through all of the pCodes for + a given pBlock. When we begin iterating through + a pBlock, the variable pc_fstart, pCode of the start + of a function, is cleared. We then search for pCodes + of type PC_FUNCTION. When one is encountered, we + initialize pc_fstart to this and at the same time + associate a new pBranch object that signifies a + branch entry. If a return is found, then this signifies + a function exit point. We'll link the pCodes of these + returns to the matching pc_fstart. + + When we're done, a doubly linked list of pBranches + will exist. The head of this list is stored in + `the_pFile', which is the meta structure for all + of the pCode. Look at the printCallTree function + on how the pBranches are linked together. + */ + for(pb = the_pFile->pbHead; pb; pb = pb->next) { pCode *pc_fstart=NULL; for(pc = pb->pcHead; pc; pc = pc->next) { @@ -5482,11 +5513,12 @@ void AnalyzepCode(char dbName) buildCallTree(); } +#if 0 /*-----------------------------------------------------------------*/ /* ispCodeFunction - returns true if *pc is the pCode of a */ /* function */ /*-----------------------------------------------------------------*/ -bool ispCodeFunction(pCode *pc) +static bool ispCodeFunction(pCode *pc) { if(pc && pc->type == PC_FUNCTION && PCF(pc)->fname) @@ -5494,6 +5526,7 @@ bool ispCodeFunction(pCode *pc) return 0; } +#endif /*-----------------------------------------------------------------*/ /* findFunction - Search for a function by name (given the name) */ @@ -5501,7 +5534,7 @@ bool ispCodeFunction(pCode *pc) /* (note - I expect this to change because I'm planning to limit */ /* pBlock's to just one function declaration */ /*-----------------------------------------------------------------*/ -pCode *findFunction(char *fname) +static pCode *findFunction(char *fname) { pBlock *pb; pCode *pc; @@ -5526,7 +5559,8 @@ pCode *findFunction(char *fname) return NULL; } -void MarkUsedRegisters(set *regset) +#if 0 +static void MarkUsedRegisters(set *regset) { regs *r1,*r2; @@ -5539,8 +5573,9 @@ void MarkUsedRegisters(set *regset) } } } +#endif -void pBlockStats(FILE *of, pBlock *pb) +static void pBlockStats(FILE *of, pBlock *pb) { pCode *pc; @@ -5608,7 +5643,7 @@ static void sequencepCode(void) /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ /* -set *register_usage(pBlock *pb) +static set *register_usage(pBlock *pb) { pCode *pc,*pcn; set *registers=NULL; @@ -5719,7 +5754,7 @@ set *register_usage(pBlock *pb) /* printCallTree - writes the call tree to a file */ /* */ /*-----------------------------------------------------------------*/ -void pct2(FILE *of,pBlock *pb,int indent) +static void pct2(FILE *of,pBlock *pb,int indent) { pCode *pc,*pcn; int i; @@ -5764,13 +5799,13 @@ void pct2(FILE *of,pBlock *pb,int indent) } - +#if 0 /*-----------------------------------------------------------------*/ /* printCallTree - writes the call tree to a file */ /* */ /*-----------------------------------------------------------------*/ -void printCallTree(FILE *of) +static void printCallTree(FILE *of) { pBranch *pbr; pBlock *pb; @@ -5820,14 +5855,14 @@ void printCallTree(FILE *of) fprintf(of,"block dbname: %c\n", getpBlock_dbName(pb)); } } - +#endif /*-----------------------------------------------------------------*/ /* */ /*-----------------------------------------------------------------*/ -void InlineFunction(pBlock *pb) +static void InlineFunction(pBlock *pb) { pCode *pc; pCode *pc_call; @@ -5982,3 +6017,4 @@ void InlinepCode(void) unBuildFlow(pb); } + diff --git a/src/pic/pcode.h b/src/pic/pcode.h index d90eb86c..46d72ea1 100644 --- a/src/pic/pcode.h +++ b/src/pic/pcode.h @@ -19,14 +19,19 @@ -------------------------------------------------------------------------*/ -//#include "ralloc.h" -struct regs; +#ifndef __PCODE_H__ +#define __PCODE_H__ + +#include "common.h" /* When changing these, you must also update the assembler template * in device/lib/libsdcc/macros.inc */ #define GPTRTAG_DATA 0x00 #define GPTRTAG_CODE 0x80 +/* Cyclic dependency with ralloc.h: */ +struct regs; + /* Post code generation @@ -55,21 +60,18 @@ struct regs; movwf t1 movf t1,w ; Can't remove this movf skpz - return + return example3: movwf t1 movf t1,w ; This movf can be removed xorwf t2,w ; since xorwf will over write Z skpz - return + return */ -#ifndef __PCODE_H__ -#define __PCODE_H__ - /*********************************************************************** * debug stuff * @@ -86,7 +88,7 @@ struct regs; #ifdef PCODE_DEBUG #define DFPRINTF(args) (fprintf args) #else -#define DFPRINTF(args) ; +#define DFPRINTF(args) ((void)0) #endif @@ -834,11 +836,12 @@ typedef struct peepCommand { pCode *newpCode (PIC_OPCODE op, pCodeOp *pcop); // Create a new pCode given an operand pCode *newpCodeCharP(char *cP); // Create a new pCode given a char * -pCode *newpCodeInlineP(char *cP); // Create a new pCode given a char * pCode *newpCodeFunction(char *g, char *f,int); // Create a new function pCode *newpCodeLabel(char *name,int key); // Create a new label given a key pCode *newpCodeCSource(int ln, char *f, const char *l); // Create a new symbol line +pCode *newpCodeWild(int pCodeID, pCodeOp *optional_operand, pCodeOp *optional_label); pCode *findNextInstruction(pCode *pci); +pCode *findPrevInstruction(pCode *pci); pCode *findNextpCode(pCode *pc, PC_TYPE pct); pCode *pCodeInstructionCopy(pCodeInstruction *pci,int invert); @@ -847,13 +850,17 @@ void printpBlock(FILE *of, pBlock *pb); // Write a pBlock to a file void printpCode(FILE *of, pCode *pc); // Write a pCode to a file void addpCode2pBlock(pBlock *pb, pCode *pc); // Add a pCode to a pBlock void addpBlock(pBlock *pb); // Add a pBlock to a pFile +void unlinkpCode(pCode *pc); void copypCode(FILE *of, char dbName); // Write all pBlocks with dbName to *of void movepBlock2Head(char dbName); // move pBlocks around +void AnalyzeBanking(void); +void ReuseReg(void); void AnalyzepCode(char dbName); -int OptimizepCode(char dbName); -void printCallTree(FILE *of); -void pCodePeepInit(void); +void InlinepCode(void); +void pCodeInitRegisters(void); +void pic14initpCodePeepCommands(void); void pBlockConvert2ISR(pBlock *pb); +void pBlockMergeLabels(pBlock *pb); void pCodeInsertAfter(pCode *pc1, pCode *pc2); void pCodeInsertBefore(pCode *pc1, pCode *pc2); void pCodeDeleteChain(pCode *f,pCode *t); @@ -864,15 +871,23 @@ pCodeOp *newpCodeOpLabel(char *name, int key); pCodeOp *newpCodeOpImmd(char *name, int offset, int index, int code_space,int is_func); pCodeOp *newpCodeOpLit(int lit); pCodeOp *newpCodeOpBit(char *name, int bit,int inBitSpace); +pCodeOp *newpCodeOpWild(int id, pCodeWildBlock *pcwb, pCodeOp *subtype); pCodeOp *newpCodeOpRegFromStr(char *name); pCodeOp *newpCodeOp(char *name, PIC_OPTYPE p); pCodeOp *pCodeOpCopy(pCodeOp *pcop); +pCodeOp *popCopyGPR2Bit(pCodeOp *pc, int bitval); pCodeOp *popCopyReg(pCodeOpReg *pc); -int isPCinFlow(pCode *pc, pCode *pcflow); +pBranch *pBranchAppend(pBranch *h, pBranch *n); + struct regs * getRegFromInstruction(pCode *pc); -extern void pcode_test(void); +char *get_op(pCodeOp *pcop, char *buff, size_t buf_size); +char *pCode2str(char *str, size_t size, pCode *pc); + +int pCodePeepMatchRule(pCode *pc); + +void pcode_test(void); void resetpCodeStatistics (void); void dumppCodeStatistics (FILE *of); @@ -890,5 +905,14 @@ extern pCodeOpReg pc_wsave; /* wsave, ssave and psave are used to save W, th extern pCodeOpReg pc_ssave; /* registers during an interrupt */ extern pCodeOpReg pc_psave; /* registers during an interrupt */ +extern pFile *the_pFile; +extern pCodeInstruction *pic14Mnemonics[MAX_PIC14MNEMONICS]; + +/* + * From pcodepeep.h: + */ +int getpCode(char *mnem, unsigned dest); +int getpCodePeepCommand(char *cmd); +int pCodeSearchCondition(pCode *pc, unsigned int cond, int contIfSkip); #endif // __PCODE_H__ diff --git a/src/pic/pcodeflow.c b/src/pic/pcodeflow.c index 2a420719..68292856 100644 --- a/src/pic/pcodeflow.c +++ b/src/pic/pcodeflow.c @@ -27,14 +27,6 @@ */ -#include - -#include "common.h" // Include everything in the SDCC src directory -#include "newalloc.h" -#include "ralloc.h" -#include "device.h" -#include "pcode.h" -#include "pcoderegs.h" #include "pcodeflow.h" #if 0 @@ -49,7 +41,7 @@ flow path is constructed. static set *FlowTree=NULL; -void dbg_dumpFlowTree(set *FlowTree) +static void dbg_dumpFlowTree(set *FlowTree) { set *segment; pCodeFlow *pcflow; @@ -74,7 +66,7 @@ void dbg_dumpFlowTree(set *FlowTree) /*-----------------------------------------------------------------* * void BuildFlowSegment(set *segment, pCodeFlow *pcflow) *-----------------------------------------------------------------*/ -void BuildFlowSegment(set *segment, pCodeFlow *pcflow) +static void BuildFlowSegment(set *segment, pCodeFlow *pcflow) { int nNextFlow=0; @@ -156,7 +148,8 @@ void BuildFlowTree(pBlock *pb) } #endif -void dbg_dumpFlow(pBlock *pb) +#if 0 +static void dbg_dumpFlow(pBlock *pb) { pCode *pcflow; @@ -183,11 +176,13 @@ void dbg_dumpFlow(pBlock *pb) } } +#endif + /*-----------------------------------------------------------------* * void BuildFlowSegment(set *segment, pCodeFlow *pcflow) *-----------------------------------------------------------------*/ -void BuildFlowSegment(pCodeFlow *pcflow) +static void BuildFlowSegment(pCodeFlow *pcflow) { static int recursion=0; pCodeFlow *pcflow_other; diff --git a/src/pic/pcodeflow.h b/src/pic/pcodeflow.h index d7c3b57e..1577770c 100644 --- a/src/pic/pcodeflow.h +++ b/src/pic/pcodeflow.h @@ -22,6 +22,8 @@ #ifndef __PCODEFLOW_H__ #define __PCODEFLOW_H__ +#include "pcode.h" + /************************************************* * pCode conditions: * @@ -60,6 +62,7 @@ /*------------------------------------------------------------*/ -void BuildFlowAncestry(pBlock *pb); +void BuildFlowTree(pBlock *pb); #endif // __PCODEFLOW_H__ + diff --git a/src/pic/pcodepeep.c b/src/pic/pcodepeep.c index f041796a..d80d8f3f 100644 --- a/src/pic/pcodepeep.c +++ b/src/pic/pcodepeep.c @@ -18,31 +18,11 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -------------------------------------------------------------------------*/ -#include -#include - -#include "common.h" // Include everything in the SDCC src directory -#include "newalloc.h" -//#define PCODE_DEBUG #include "pcode.h" #include "pcodeflow.h" #include "ralloc.h" -pCodeOp *popCopyGPR2Bit(pCodeOpReg *pc, int bitval); -pCodeOp *popRegFromString(char *str, int size, int offset); - -pCodeOp *newpCodeOpWild(int id, pCodeWildBlock *pcwb, pCodeOp *subtype); -pCode *newpCodeWild(int pCodeID, pCodeOp *optional_operand, pCodeOp *optional_label); -pCode * findNextInstruction(pCode *pc); -int getpCode(char *mnem,int dest); -int getpCodePeepCommand(char *cmd); -void pBlockMergeLabels(pBlock *pb); -char *pCode2str(char *str, int size, pCode *pc); -char *get_op( pCodeOp *pcop,char *buf,int buf_size); - -extern pCodeInstruction *pic14Mnemonics[]; -extern pCode * findPrevInstruction(pCode *pci); - +//#define PCODE_DEBUG #define IS_PCCOMMENT(x) ( x && (x->type==PC_COMMENT)) @@ -120,8 +100,8 @@ typedef struct pCodeToken } pCodeToken; -pCodeToken tokArr[50]; -unsigned tokIdx=0; +static pCodeToken tokArr[50]; +static unsigned tokIdx=0; typedef enum { @@ -145,9 +125,10 @@ typedef struct parsedPattern { } parsedPattern; #define MAX_PARSEDPATARR 50 -parsedPattern parsedPatArr[MAX_PARSEDPATARR]; -unsigned int parsedPatIdx=0; - +static parsedPattern parsedPatArr[MAX_PARSEDPATARR]; +#if 0 +static unsigned int parsedPatIdx=0; +#endif typedef enum { PCP_LABEL=1, @@ -174,7 +155,7 @@ typedef struct pcPattern { void * (*f) (void *,pCodeWildBlock *); } pcPattern; -pcPattern pcpArr[] = { +static pcPattern pcpArr[] = { {PCP_LABEL, pcpat_label, NULL}, {PCP_WILDSTR, pcpat_wildString, NULL}, {PCP_STR, pcpat_string, NULL}, @@ -222,7 +203,7 @@ static void * cvt_altpat_mnem2(void *pp,pCodeWildBlock *pcwb); static void * cvt_altpat_mnem2a(void *pp,pCodeWildBlock *pcwb); static void * cvt_altpat_mnem3(void *pp,pCodeWildBlock *pcwb); -pcPattern altArr[] = { +static pcPattern altArr[] = { {ALT_LABEL, alt_label, cvt_altpat_label}, {ALT_COMMENT, alt_comment,cvt_altpat_comment}, {ALT_MNEM3, alt_mnem3, cvt_altpat_mnem3}, @@ -285,14 +266,14 @@ static pCodeOp *cvt_extract_status(char *reg, char *bit) if(len == 1) { // check C,Z if(toupper((unsigned char)*bit) == 'C') - return PCOP(popCopyGPR2Bit(&pc_status,PIC_C_BIT)); + return PCOP(popCopyGPR2Bit(PCOP(&pc_status),PIC_C_BIT)); if(toupper((unsigned char)*bit) == 'Z') - return PCOP(popCopyGPR2Bit(&pc_status,PIC_Z_BIT)); + return PCOP(popCopyGPR2Bit(PCOP(&pc_status),PIC_Z_BIT)); } // Check DC if(len ==2 && toupper((unsigned char)bit[0]) == 'D' && toupper((unsigned char)bit[1]) == 'C') - return PCOP(popCopyGPR2Bit(&pc_status,PIC_DC_BIT)); + return PCOP(popCopyGPR2Bit(PCOP(&pc_status),PIC_DC_BIT)); return NULL; @@ -820,7 +801,7 @@ static void tokenizeLineNode(char *ln) -void dump1Token(pCodeTokens tt) +static void dump1Token(pCodeTokens tt) { switch(tt) { @@ -865,7 +846,7 @@ void dump1Token(pCodeTokens tt) /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ -int pcComparePattern(pCodeToken *pct, char *pat, int max_tokens) +static int pcComparePattern(pCodeToken *pct, char *pat, int max_tokens) { int i=0; @@ -898,7 +879,7 @@ int pcComparePattern(pCodeToken *pct, char *pat, int max_tokens) /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ -int altComparePattern( char *pct, parsedPattern *pat, int max_tokens) +static int altComparePattern(char *pct, parsedPattern *pat, int max_tokens) { int i=0; @@ -933,7 +914,7 @@ int altComparePattern( char *pct, parsedPattern *pat, int max_tokens) /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ -int advTokIdx(int *v, int amt) +static int advTokIdx(int *v, int amt) { if((unsigned) (*v + amt) > tokIdx) @@ -962,7 +943,7 @@ int advTokIdx(int *v, int amt) /* pcode. */ /*-----------------------------------------------------------------*/ -int parseTokens(pCodeWildBlock *pcwb, pCode **pcret) +static int parseTokens(pCodeWildBlock *pcwb, pCode **pcret) { pCode *pc; int error = 0; @@ -1184,7 +1165,7 @@ int parseTokens(pCodeWildBlock *pcwb, pCode **pcret) /*-----------------------------------------------------------------*/ /* */ /*-----------------------------------------------------------------*/ -void peepRuleBlock2pCodeBlock( lineNode *ln, pCodeWildBlock *pcwb) +static void peepRuleBlock2pCodeBlock(lineNode *ln, pCodeWildBlock *pcwb) { if(!ln) @@ -1208,10 +1189,11 @@ void peepRuleBlock2pCodeBlock( lineNode *ln, pCodeWildBlock *pcwb) } } +#if 0 /*-----------------------------------------------------------------*/ /* */ /*-----------------------------------------------------------------*/ -pCode *AssembleLine(char *line) +static pCode *AssembleLine(char *line) { pCode *pc=NULL; @@ -1228,6 +1210,7 @@ pCode *AssembleLine(char *line) return pc; } +#endif /*-----------------------------------------------------------------*/ /* peepRuleCondition */ @@ -1248,8 +1231,7 @@ static void peepRuleCondition(char *cond, pCodePeep *pcp) } - -void initpCodeWildBlock(pCodeWildBlock *pcwb) +static void initpCodeWildBlock(pCodeWildBlock *pcwb) { // pcwb = Safe_calloc(1,sizeof(pCodeWildBlock)); @@ -1267,7 +1249,7 @@ void initpCodeWildBlock(pCodeWildBlock *pcwb) } -void postinit_pCodeWildBlock(pCodeWildBlock *pcwb) +static void postinit_pCodeWildBlock(pCodeWildBlock *pcwb) { if(!pcwb) @@ -1284,7 +1266,7 @@ void postinit_pCodeWildBlock(pCodeWildBlock *pcwb) } -void initpCodePeep(pCodePeep *pcp) +static void initpCodePeep(pCodePeep *pcp) { // pcwb = Safe_calloc(1,sizeof(pCodeWildBlock)); @@ -1311,9 +1293,7 @@ void initpCodePeep(pCodePeep *pcp) /* taking raw text to produce machine code, it produces pCode. */ /* */ /*-----------------------------------------------------------------*/ -extern void pic14initpCodePeepCommands(void); - -void peepRules2pCode(peepRule *rules) +void peepRules2pCode(peepRule *rules) { peepRule *pr; @@ -1396,7 +1376,8 @@ void peepRules2pCode(peepRule *rules) } -void printpCodeString(FILE *of, pCode *pc, int max) +#if 0 +static void printpCodeString(FILE *of, pCode *pc, int max) { int i=0; @@ -1405,6 +1386,7 @@ void printpCodeString(FILE *of, pCode *pc, int max) pc = pc->next; } } +#endif /*-----------------------------------------------------------------*/ /* _DLL * DLL_append */ @@ -1517,7 +1499,7 @@ int pCodeSearchCondition(pCode *pc, unsigned int cond, int contIfSkip) * * Compare two pCodeOp's and return 1 if they're the same *-----------------------------------------------------------------*/ -int pCodeOpCompare(pCodeOp *pcops, pCodeOp *pcopd) +static int pCodeOpCompare(pCodeOp *pcops, pCodeOp *pcopd) { char b[50], *n2; @@ -1570,7 +1552,7 @@ int pCodeOpCompare(pCodeOp *pcops, pCodeOp *pcopd) return 1; } -int pCodePeepMatchLabels(pCodePeep *peepBlock, pCode *pcs, pCode *pcd) +static int pCodePeepMatchLabels(pCodePeep *peepBlock, pCode *pcs, pCode *pcd) { int labindex; @@ -1653,7 +1635,7 @@ int pCodePeepMatchLabels(pCodePeep *peepBlock, pCode *pcs, pCode *pcd) /* */ /*-----------------------------------------------------------------*/ -int pCodePeepMatchLine(pCodePeep *peepBlock, pCode *pcs, pCode *pcd) +static int pCodePeepMatchLine(pCodePeep *peepBlock, pCode *pcs, pCode *pcd) { int index; // index into wild card arrays @@ -1876,7 +1858,7 @@ int pCodePeepMatchLine(pCodePeep *peepBlock, pCode *pcs, pCode *pcd) /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ -void pCodePeepClrVars(pCodePeep *pcp) +static void pCodePeepClrVars(pCodePeep *pcp) { int i; diff --git a/src/pic/pcoderegs.c b/src/pic/pcoderegs.c index 67521d2c..69f55a7c 100644 --- a/src/pic/pcoderegs.c +++ b/src/pic/pcoderegs.c @@ -26,33 +26,21 @@ pcoderegs.c The purpose of the code in this file is to optimize the register usage. */ -#include -#include "common.h" // Include everything in the SDCC src directory -#include "newalloc.h" -#include "ralloc.h" -#include "device.h" -#include "pcode.h" +#include "main.h" #include "pcoderegs.h" #include "pcodeflow.h" -#include "main.h" +#include "ralloc.h" -extern void dbg_dumpregusage(void); -extern pCode * findPrevInstruction(pCode *pci); -extern pBranch * pBranchAppend(pBranch *h, pBranch *n); -void unlinkpCode(pCode *pc); -extern int pCodeSearchCondition(pCode *pc, unsigned int cond, int contIfSkip); -char *pCode2str(char *str, int size, pCode *pc); -//static int sameRegs (const regs *reg1, const regs *reg2); -int total_registers_saved=0; -int register_optimization=1; +static int total_registers_saved=0; +static int register_optimization=1; /*-----------------------------------------------------------------* * void AddRegToFlow(regs *reg, pCodeFlow *pcfl) *-----------------------------------------------------------------*/ /* -void AddRegToFlow(regs *reg, pCodeFlow *pcfl) +static void AddRegToFlow(regs *reg, pCodeFlow *pcfl) { if(!reg || ! pcfl || !isPCFL(pcflow)) @@ -65,10 +53,11 @@ void AddRegToFlow(regs *reg, pCodeFlow *pcfl) */ +#if 0 /*-----------------------------------------------------------------* * *-----------------------------------------------------------------*/ -void dbg_regusage(set *fregs) +static void dbg_regusage(set *fregs) { regs *reg; pCode *pcfl; @@ -120,11 +109,13 @@ void dbg_regusage(set *fregs) } } } +#endif +#if 0 /*-----------------------------------------------------------------* * *-----------------------------------------------------------------*/ -void dbg_dumpregusage(void) +static void dbg_dumpregusage(void) { fprintf(stderr,"*** Register Usage ***\n"); @@ -142,12 +133,12 @@ void dbg_dumpregusage(void) dbg_regusage(dynProcessorRegs); } - +#endif /*-----------------------------------------------------------------* * void pCodeRegMapLiveRangesInFlow(pCodeFlow *pcfl) *-----------------------------------------------------------------*/ -void pCodeRegMapLiveRangesInFlow(pCodeFlow *pcfl) +static void pCodeRegMapLiveRangesInFlow(pCodeFlow *pcfl) { pCode *pc=NULL; @@ -304,7 +295,7 @@ static void Remove1pcode(pCode *pc, regs *reg, int debug_code) * void RemoveRegsFromSet(set *regset) * *-----------------------------------------------------------------*/ -void RemoveRegsFromSet(set *regset) +static void RemoveRegsFromSet(set *regset) { regs *reg; int used; @@ -371,9 +362,7 @@ void RemoveRegsFromSet(set *regset) } } -void RegsUnMapLiveRanges(void); -extern pFile *the_pFile; -void pic14_ReMapLiveRanges(void) +static void pic14_ReMapLiveRanges(void) { pBlock *pb; if (!the_pFile) return; @@ -454,7 +443,7 @@ static void Remove2pcodes(pCode *pcflow, pCode *pc1, pCode *pc2, regs *reg, int /*-----------------------------------------------------------------* * *-----------------------------------------------------------------*/ -int regUsedinRange(pCode *pc1, pCode *pc2, regs *reg) +static int regUsedinRange(pCode *pc1, pCode *pc2, regs *reg) { int i=0; regs *testreg; @@ -476,7 +465,7 @@ int regUsedinRange(pCode *pc1, pCode *pc2, regs *reg) return 0; } -int regIsSpecial (regs *reg, int mayBeGlobal) +static int regIsSpecial (regs *reg, int mayBeGlobal) { if (!reg) return 0; @@ -513,7 +502,7 @@ static int regIsLocal (regs *reg) * * *-----------------------------------------------------------------*/ -int pCodeOptime2pCodes(pCode *pc1, pCode *pc2, pCode *pcfl_used, regs *reg, int can_free, int optimize_level) +static int pCodeOptime2pCodes(pCode *pc1, pCode *pc2, pCode *pcfl_used, regs *reg, int can_free, int optimize_level) { pCode *pct1, *pct2; regs *reg1, *reg2; @@ -699,7 +688,7 @@ int pCodeOptime2pCodes(pCode *pc1, pCode *pc2, pCode *pcfl_used, regs *reg, int /*-----------------------------------------------------------------* * void pCodeRegOptimeRegUsage(pBlock *pb) *-----------------------------------------------------------------*/ -void OptimizeRegUsage(set *fregs, int optimize_multi_uses, int optimize_level) +static void OptimizeRegUsage(set *fregs, int optimize_multi_uses, int optimize_level) { regs *reg; int used; @@ -832,7 +821,6 @@ void OptimizeRegUsage(set *fregs, int optimize_multi_uses, int optimize_level) if(pc1 && isPCI(pc1) && ( (pcfl1 = PCI(pc1)->pcflow) != NULL) ) { - //while(rset2 && searching) { if(rset2) { pc2 = rset2->item; @@ -1128,7 +1116,7 @@ df_removeStates () } // while } -int regIsDead (regs *reg, int cond, pCode *pc) +static int regIsDead (regs *reg, int cond, pCode *pc) { set *seenStates = NULL; set *todo = NULL; @@ -1201,14 +1189,6 @@ int regIsDead (regs *reg, int cond, pCode *pc) which may not be done for SFRs (side-effects on read possible)). ------------------------------------------------------------------ */ -extern void unBuildFlow (pBlock *pb); -extern void RegsUnMapLiveRanges (); -extern void BuildFlow (pBlock *pb); -extern void LinkFlow (pBlock *pb); -extern void BuildFlowTree (pBlock *pb); -extern void pCodeRegMapLiveRanges (pBlock *pb); -extern pFile *the_pFile; - static int pCodeRemove (pCode *pc, const char *comment) { pCode *pcprev, *pcnext; @@ -1466,7 +1446,7 @@ static void replace_PCI (pCodeInstruction *pc, pCodeInstruction *newpc, char *co Find the first (unique) assignment to `reg' (prior to pc). ------------------------------------------------------------------ */ -pCode *findAssignmentToReg (regs *reg, pCode *pc) +static pCode *findAssignmentToReg (regs *reg, pCode *pc) { pCode *curr; @@ -1493,7 +1473,7 @@ pCode *findAssignmentToReg (regs *reg, pCode *pc) Find a register that holds the same value as `reg' (an alias). ------------------------------------------------------------------ */ -regs *findRegisterAlias (regs *reg, pCode *pc) +static regs *findRegisterAlias (regs *reg, pCode *pc) { pCode *curr; @@ -1553,7 +1533,7 @@ regs *findRegisterAlias (regs *reg, pCode *pc) it with a better variant if possible. ------------------------------------------------------------------ */ -void analyzeAndReplacePCI (pCodeInstruction *pci) +static void analyzeAndReplacePCI (pCodeInstruction *pci) { regs *op_reg, *alias_reg; @@ -1593,8 +1573,6 @@ void analyzeAndReplacePCI (pCodeInstruction *pci) } // switch } -extern pFile *the_pFile; - /* ------------------------------------------------------------------ Find and remove dead pCodes. ------------------------------------------------------------------ */ @@ -1636,7 +1614,7 @@ static int removeDeadPCIs (void) not used) -- these should be removed in a following sweep phase. ------------------------------------------------------------------ */ -void optimizeDataflow (void) +static void optimizeDataflow (void) { pBlock *pb; @@ -1720,7 +1698,7 @@ void pCodeRegOptimizeRegUsage(int level) * void RegsUnMapLiveRanges(set *regset) * *-----------------------------------------------------------------*/ -void RegsSetUnMapLiveRanges(set *regset) +static void RegsSetUnMapLiveRanges(set *regset) { regs *reg; diff --git a/src/pic/pcoderegs.h b/src/pic/pcoderegs.h index cd26f4f7..fb362ea3 100644 --- a/src/pic/pcoderegs.h +++ b/src/pic/pcoderegs.h @@ -23,6 +23,10 @@ #ifndef __PCODEREGS_H__ #define __PCODEREGS_H__ +#include "common.h" + +#include "pcode.h" + /************************************************* pCodeRegLives @@ -38,5 +42,9 @@ typedef struct pCodeRegLives { } pCodeRegLives; +void pCodeRegMapLiveRanges(struct pBlock *pb); +void pCodeRegOptimizeRegUsage(int level); +void RegsUnMapLiveRanges(void); +void RemoveUnusedRegisters(void); #endif // __PCODEREGS_H__ diff --git a/src/pic/ralloc.c b/src/pic/ralloc.c index 9b181ce6..8c4c3e99 100644 --- a/src/pic/ralloc.c +++ b/src/pic/ralloc.c @@ -24,11 +24,17 @@ what you give them. Help stamp out software-hoarding! -------------------------------------------------------------------------*/ -#include "common.h" -#include "ralloc.h" #include "device.h" -#include "pcode.h" #include "gen.h" +#include "ralloc.h" + + +set *dynAllocRegs=NULL; +set *dynStackRegs=NULL; +set *dynProcessorRegs=NULL; +set *dynDirectRegs=NULL; +set *dynDirectBitRegs=NULL; +set *dynInternalRegs=NULL; #define FENTRY2 1 ? (void)0 : printf @@ -45,9 +51,6 @@ /* since the pack the registers depending strictly on the MCU */ /*-----------------------------------------------------------------*/ -extern void genpic14Code (iCode *); -extern void pic14_assignConfigWordValue(int address, int value); - /* Global data */ static struct { @@ -62,38 +65,23 @@ static struct } _G; -/* Shared with gen.c */ -int pic14_ptrRegReq; /* one byte pointer register required */ - - -set *dynAllocRegs=NULL; -set *dynStackRegs=NULL; -set *dynProcessorRegs=NULL; -set *dynDirectRegs=NULL; -set *dynDirectBitRegs=NULL; -set *dynInternalRegs=NULL; +static int pic14_ptrRegReq; /* one byte pointer register required */ static hTab *dynDirectRegNames= NULL; // static hTab *regHash = NULL; /* a hash table containing ALL registers */ static int dynrIdx = 0x1000; -int pic14_nRegs = 128; // = sizeof (regspic14) / sizeof (regs); - int Gstack_base_addr=0; /* The starting address of registers that * are used to pass and return parameters */ -int Gstack_size = 0; - +static int Gstack_size = 0; - - -static void spillThis (symbol *); static int debug = 0; // should be 0 when committed, creates .d files static FILE *debugF = NULL; + /*-----------------------------------------------------------------*/ /* debugLog - open a file for debugging information */ /*-----------------------------------------------------------------*/ -//static void debugLog(char *inst,char *fmt, ...) static void debugLog (char *fmt,...) { @@ -148,7 +136,6 @@ pic14_debugLogClose (void) debugF = NULL; } } -#define AOP(op) op->aop static char * debugAopGet (char *str, operand * op) @@ -316,7 +303,26 @@ static int regname2key(char const *name) } -static regs *regWithIdx (set *dRegs, int idx, int fixed); +/*-----------------------------------------------------------------*/ +/* regWithIdx - Search through a set of registers that matches idx */ +/*-----------------------------------------------------------------*/ +static regs * +regWithIdx (set *dRegs, int idx, int fixed) +{ + regs *dReg; + + for (dReg = setFirstItem(dRegs) ; dReg ; + dReg = setNextItem(dRegs)) { + + if(idx == dReg->rIdx && (fixed == (int)dReg->isFixed)) { + while (dReg->reg_alias) dReg = dReg->reg_alias; + return dReg; + } + } + + return NULL; +} + /*-----------------------------------------------------------------*/ /* newReg - allocate and init memory for a new register */ /*-----------------------------------------------------------------*/ @@ -370,26 +376,6 @@ static regs* newReg(short type, PIC_OPTYPE pc_type, int rIdx, char *name, int si return dReg; } -/*-----------------------------------------------------------------*/ -/* regWithIdx - Search through a set of registers that matches idx */ -/*-----------------------------------------------------------------*/ -static regs * -regWithIdx (set *dRegs, int idx, int fixed) -{ - regs *dReg; - - for (dReg = setFirstItem(dRegs) ; dReg ; - dReg = setNextItem(dRegs)) { - - if(idx == dReg->rIdx && (fixed == (int)dReg->isFixed)) { - while (dReg->reg_alias) dReg = dReg->reg_alias; - return dReg; - } - } - - return NULL; -} - /*-----------------------------------------------------------------*/ /* regWithName - Search through a set of registers that matches name */ /*-----------------------------------------------------------------*/ @@ -576,12 +562,6 @@ dirregWithName (char *name) return NULL; // name wasn't found in the hash table } -int IS_CONFIG_ADDRESS(int address) -{ - - return ((address == 0x2007) || (address == 0x2008)); -} - /*-----------------------------------------------------------------*/ /* allocNewDirReg - allocates a new register of given type */ /*-----------------------------------------------------------------*/ @@ -1042,7 +1022,8 @@ nfreeRegsType (int type) return nFreeRegs (type); } -void writeSetUsedRegs(FILE *of, set *dRegs) +#if 0 +static void writeSetUsedRegs(FILE *of, set *dRegs) { regs *dReg; @@ -1055,9 +1036,9 @@ void writeSetUsedRegs(FILE *of, set *dRegs) } } -extern void dump_map(void); +#endif -void packBits(set *bregs) +static void packBits(set *bregs) { set *regset; regs *breg; @@ -1124,7 +1105,7 @@ void packBits(set *bregs) -void bitEQUs(FILE *of, set *bregs) +static void bitEQUs(FILE *of, set *bregs) { regs *breg,*bytereg; int bit_no=0; @@ -1155,7 +1136,8 @@ void bitEQUs(FILE *of, set *bregs) } -void aliasEQUs(FILE *of, set *fregs, int use_rIdx) +#if 0 +static void aliasEQUs(FILE *of, set *fregs, int use_rIdx) { regs *reg; @@ -1163,7 +1145,6 @@ void aliasEQUs(FILE *of, set *fregs, int use_rIdx) for (reg = setFirstItem(fregs) ; reg ; reg = setNextItem(fregs)) { - //if(!reg->isEmitted && reg->wasUsed) { if(reg->wasUsed) { if(use_rIdx) fprintf (of, "%s\tEQU\t0x%03x\n", @@ -1177,14 +1158,13 @@ void aliasEQUs(FILE *of, set *fregs, int use_rIdx) } } +#endif void writeUsedRegs(FILE *of) { packBits(dynDirectBitRegs); - //dump_map(); - bitEQUs(of,dynDirectBitRegs); } @@ -2716,6 +2696,9 @@ regTypeNum () } } + +#if 0 +static DEFSETFUNC (markRegFree) { ((regs *)item)->isFree = 1; @@ -2723,6 +2706,7 @@ DEFSETFUNC (markRegFree) return 0; } +static DEFSETFUNC (deallocReg) { fprintf(stderr,"deallocting register %s\n",((regs *)item)->name); @@ -2731,10 +2715,11 @@ DEFSETFUNC (deallocReg) return 0; } + /*-----------------------------------------------------------------*/ /* freeAllRegs - mark all registers as free */ /*-----------------------------------------------------------------*/ -void +static void pic14_freeAllRegs () { // int i; @@ -2752,7 +2737,7 @@ pic14_freeAllRegs () /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ -void +static void pic14_deallocateAllRegs () { // int i; @@ -2770,6 +2755,7 @@ pic14_deallocateAllRegs () } */ } +#endif /*-----------------------------------------------------------------*/ @@ -3609,7 +3595,7 @@ packForPush (iCode * ic, eBBlock * ebp) hTabDeleteItem (&iCodehTab, dic->key, dic, DELETE_ITEM, NULL); } -void printSymType(char * str, sym_link *sl) +static void printSymType(char * str, sym_link *sl) { if (debug) { debugLog (" %s Symbol type: ",str); @@ -3623,7 +3609,7 @@ void printSymType(char * str, sym_link *sl) * the function checkSClass in src/SDCCsymt.c dinks with * the S_TYPE in ways the PIC port doesn't fully like...*/ /*-----------------------------------------------------------------*/ -void isData(sym_link *sl) +static void isData(sym_link *sl) { FILE *of = stderr; diff --git a/src/pic/ralloc.h b/src/pic/ralloc.h index 4c85fcee..7835c48f 100644 --- a/src/pic/ralloc.h +++ b/src/pic/ralloc.h @@ -23,11 +23,12 @@ You are forbidden to forbid anyone else to use, share and improve what you give them. Help stamp out software-hoarding! -------------------------------------------------------------------------*/ -#include "SDCCicode.h" -#include "SDCCBBlock.h" + #ifndef SDCCRALLOC_H #define SDCCRALLOC_H 1 +#include "common.h" + #include "pcoderegs.h" @@ -67,7 +68,6 @@ typedef struct regs } regs; extern regs regspic14[]; -extern int pic14_nRegs; extern int Gstack_base_addr; /* @@ -83,16 +83,21 @@ extern set *dynDirectBitRegs; extern set *dynInternalRegs; +void initStack(int base_address, int size, int shared); regs *pic14_regWithIdx (int); regs *dirregWithName (char *name ); -void pic14_freeAllRegs (); -void pic14_deallocateAllRegs (); +void pic14_assignRegisters (ebbIndex *ebbi); regs *pic14_findFreeReg(short type); regs *pic14_allocWithIdx (int idx); regs *typeRegWithIdx (int idx, int type, int fixed); regs *regFindWithName (const char *name); +void pic14_debugLogClose(void); +void writeUsedRegs(FILE *of); + regs *allocDirReg (operand *op ); +regs *allocInternalRegister(int rIdx, char * name, PIC_OPTYPE po_type, int alias); +regs *allocProcessorRegister(int rIdx, char * name, short po_type, int alias); regs *allocRegByName (char *name, int size ); regs *allocNewDirReg (sym_link *symlnk,const char *name); @@ -112,4 +117,6 @@ regs *allocNewDirReg (sym_link *symlnk,const char *name); #define IDX_SSAVE 0x7ffd #define IDX_PSAVE 0x7ffc +#define pic14_nRegs 128 + #endif diff --git a/src/pic16/pcode.c b/src/pic16/pcode.c index cad4ed67..e174f554 100644 --- a/src/pic16/pcode.c +++ b/src/pic16/pcode.c @@ -156,7 +156,6 @@ extern void pic16_RemoveUnusedRegisters(void); extern void pic16_RegsUnMapLiveRanges(void); extern void pic16_BuildFlowTree(pBlock *pb); extern void pic16_pCodeRegOptimizeRegUsage(int level); -extern int mnem2key(unsigned char const *mnem); /****************************************************************/ /* Forward declarations */ @@ -3026,14 +3025,13 @@ void pic16_pCodeInitRegisters(void) } -#if OPT_DISABLE_PIC /*-----------------------------------------------------------------*/ /* mnem2key - convert a pic mnemonic into a hash key */ /* (BTW - this spreads the mnemonics quite well) */ /* */ /*-----------------------------------------------------------------*/ -int mnem2key(unsigned char const *mnem) +static int mnem2key(unsigned char const *mnem) { int key = 0; @@ -3049,7 +3047,6 @@ int mnem2key(unsigned char const *mnem) return (key & 0x1f); } -#endif void pic16initMnemonics(void) { diff --git a/src/z80/gen.c b/src/z80/gen.c index 3554803c..773a4f66 100644 --- a/src/z80/gen.c +++ b/src/z80/gen.c @@ -396,15 +396,15 @@ static void _vemit2 (const char *szFormat, va_list ap) { struct dbuf_s dbuf; - const char *buffer; + char *buffer; dbuf_init(&dbuf, INITIAL_INLINEASM); dbuf_tvprintf (&dbuf, szFormat, ap); - buffer = dbuf_c_str(&dbuf); + buffer = (char *)dbuf_c_str(&dbuf); - _tidyUp ((char *)buffer); + _tidyUp (buffer); _G.lines.current = (_G.lines.current ? connectLine (_G.lines.current, _newLineNode (buffer)) : (_G.lines.head = _newLineNode (buffer))); -- 2.30.2