+2008-08-15 Raphael Neider <rneider AT web.de>
+
+ * 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 <pkk AT spth.de>
+
* src/z80/gen.c: fixed #2051348
* support/regression/tests/bug-2051348.c: regression test for #2051348
thanks Mauro Giachero
2008-07-13 Philipp Klaus Krause <pkk AT spth.de>
+
* src/port.h: Fixed typo in comment
2008-07-12 Philipp Klaus Krause <pkk AT spth.de>
+
* src/z80/mappings.i: Implemented RFE #1919415
* src/z80/peeph-z80.def: Implemented RFE #1919415, #1861376,
#1880202, #1914434, prepared for RFE #1703943
Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-------------------------------------------------------------------------*/
-#include <stdio.h>
-#include <stdlib.h>
-#include <ctype.h>
-
-#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
#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;
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 */
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)
*
* 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;
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);
return 1;
}
+#endif
#if 0
/* The following code should be (and is) implemented in the linker. */
}
#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.
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)
*
*
*-----------------------------------------------------------------*/
-int pic14_getConfigWord(int address)
+static int pic14_getConfigWord(int address)
{
switch (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;
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;
/*
* 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;
#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
} 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);
Made everything static
-------------------------------------------------------------------------*/
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-#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 {
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 */
* 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 */
}
-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",
}
}
-void emitpcodeNULLop(PIC_OPCODE poc)
+static void emitpcodeNULLop(PIC_OPCODE poc)
{
addpCode2pBlock(pb,newpCode(poc,NULL));
/*-----------------------------------------------------------------*/
/* newAsmop - creates a new asmOp */
/*-----------------------------------------------------------------*/
-asmop *newAsmop (short type)
+static asmop *newAsmop (short type)
{
asmop *aop;
return aop;
}
-int aopIdx (asmop *aop, int offset)
+static int aopIdx (asmop *aop, int offset)
{
if(!aop)
return -1;
}
}
+/*-----------------------------------------------------------------*/
+/* 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 */
/*-----------------------------------------------------------------*/
/*-----------------------------------------------------------------*/
/* popGetTempReg - create a new temporary pCodeOp */
/*-----------------------------------------------------------------*/
-pCodeOp *popGetTempReg(void)
+static pCodeOp *popGetTempReg(void)
{
pCodeOp *pcop;
/*-----------------------------------------------------------------*/
/* 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)
/*-------------------------------------------------------------------*/
/* 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);
/*-----------------------------------------------------------------*/
/* 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;
/*-----------------------------------------------------------------*/
/* 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) );
/*-----------------------------------------------------------------*/
/*-----------------------------------------------------------------*/
-pCodeOp *popRegFromIdx(int rIdx)
+static pCodeOp *popRegFromIdx(int rIdx)
{
pCodeOp *pcop;
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 ||
/*-----------------------------------------------------------------*/
/* pic14_outBitC - output a bit C */
/*-----------------------------------------------------------------*/
-void pic14_outBitC(operand *result)
+static void pic14_outBitC(operand *result)
{
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
/*-----------------------------------------------------------------*/
/* 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;
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 */
/*-----------------------------------------------------------------*/
#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 */
/*-----------------------------------------------------------------*/
/* 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 {
}
*/
/* 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;
/*-----------------------------------------------------------------*/
/* 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));
/* 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);
#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__);*/ \
} \
} while (0)
-struct pCodeOp;
-
enum
{
AOP_LIT = 1,
}
asmop;
-void genpic14Code (iCode *);
-
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 */
/*-----------------------------------------------------------------*/
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
Made everything static
-------------------------------------------------------------------------*/
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-#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)
{
return "BAD TYPE";
}
-void DebugAop(asmop *aop)
+#if 0
+static void DebugAop(asmop *aop)
{
if(!aop)
return;
break;
}
}
+#endif
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));
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 */
pic14_outAcc(result);
}
}
+#endif
#if 0
/* This is the original version of this code.
what you give them. Help stamp out software-hoarding!
-------------------------------------------------------------------------*/
-#include "../common.h"
-#include <time.h>
-#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
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)
{
/*-----------------------------------------------------------------*/
/* 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)
{
#endif
#if 0
-extern void pCodeConstString(char *name, char *value);
/*-----------------------------------------------------------------*/
/* emitStaticSeg - emitcode for the static segment */
/*-----------------------------------------------------------------*/
/*-----------------------------------------------------------------*/
/* createInterruptVect - creates the interrupt vector */
/*-----------------------------------------------------------------*/
-pCodeOp *popGetExternal (char *str, int isReg);
static void
pic14createInterruptVect (struct dbuf_s * vBuf)
{
}
#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)
{
}
-void
+static void
pic14_emitInterruptHandler (FILE * asmFile)
{
if (pic14_hasInterrupt)
#endif
-void ast_print (ast * tree, FILE *outfile, int indent);
-
#if 0
/*
* Emit all memmaps.
}
#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,
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;
return (in_code);
}
-char *get_op(pCodeOp *pcop,char *buffer, size_t size);
/*
* Actually emit the initial values in .asm format.
*/
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)) {
#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
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 <errno.h>
-//#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 }
};
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)
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. */
return "err";
}
-extern char *processor_base_name(void);
-
static void
_pic14_genAssemblerPreamble (FILE * of)
{
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;
} 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
+
Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-------------------------------------------------------------------------*/
-#include <stdio.h>
-
-#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};
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);
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,
(PCC_REGISTER | PCC_C | PCC_DC | PCC_Z) // outCond
};
-pCodeInstruction pciADDFW = {
+static pCodeInstruction pciADDFW = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
// genericAnalyze,
genericDestruct,
(PCC_W | PCC_C | PCC_DC | PCC_Z) // outCond
};
-pCodeInstruction pciADDLW = {
+static pCodeInstruction pciADDLW = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
// genericAnalyze,
genericDestruct,
(PCC_W | PCC_Z | PCC_C | PCC_DC) // outCond
};
-pCodeInstruction pciANDLW = {
+static pCodeInstruction pciANDLW = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
// genericAnalyze,
genericDestruct,
(PCC_W | PCC_Z) // outCond
};
-pCodeInstruction pciANDWF = {
+static pCodeInstruction pciANDWF = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
// genericAnalyze,
genericDestruct,
(PCC_REGISTER | PCC_Z) // outCond
};
-pCodeInstruction pciANDFW = {
+static pCodeInstruction pciANDFW = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
// genericAnalyze,
genericDestruct,
(PCC_W | PCC_Z) // outCond
};
-pCodeInstruction pciBCF = {
+static pCodeInstruction pciBCF = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
// genericAnalyze,
genericDestruct,
(PCC_REGISTER | PCC_EXAMINE_PCOP) // outCond
};
-pCodeInstruction pciBSF = {
+static pCodeInstruction pciBSF = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
// genericAnalyze,
genericDestruct,
(PCC_REGISTER | PCC_EXAMINE_PCOP) // outCond
};
-pCodeInstruction pciBTFSC = {
+static pCodeInstruction pciBTFSC = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
// AnalyzeSKIP,
genericDestruct,
PCC_NONE // outCond
};
-pCodeInstruction pciBTFSS = {
+static pCodeInstruction pciBTFSS = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
// AnalyzeSKIP,
genericDestruct,
PCC_NONE // outCond
};
-pCodeInstruction pciCALL = {
+static pCodeInstruction pciCALL = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
// genericAnalyze,
genericDestruct,
(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,
PCC_REGISTER | PCC_Z // outCond
};
-pCodeInstruction pciCOMFW = {
+static pCodeInstruction pciCOMFW = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
// genericAnalyze,
genericDestruct,
PCC_W | PCC_Z // outCond
};
-pCodeInstruction pciCLRF = {
+static pCodeInstruction pciCLRF = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
// genericAnalyze,
genericDestruct,
PCC_REGISTER | PCC_Z // outCond
};
-pCodeInstruction pciCLRW = {
+static pCodeInstruction pciCLRW = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
// genericAnalyze,
genericDestruct,
PCC_W | PCC_Z // outCond
};
-pCodeInstruction pciCLRWDT = {
+static pCodeInstruction pciCLRWDT = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
// genericAnalyze,
genericDestruct,
PCC_NONE // outCond
};
-pCodeInstruction pciDECF = {
+static pCodeInstruction pciDECF = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
// genericAnalyze,
genericDestruct,
PCC_REGISTER | PCC_Z // outCond
};
-pCodeInstruction pciDECFW = {
+static pCodeInstruction pciDECFW = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
// genericAnalyze,
genericDestruct,
PCC_W | PCC_Z // outCond
};
-pCodeInstruction pciDECFSZ = {
+static pCodeInstruction pciDECFSZ = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
// AnalyzeSKIP,
genericDestruct,
PCC_REGISTER | PCC_Z // outCond
};
-pCodeInstruction pciDECFSZW = {
+static pCodeInstruction pciDECFSZW = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
// AnalyzeSKIP,
genericDestruct,
PCC_W | PCC_Z // outCond
};
-pCodeInstruction pciGOTO = {
+static pCodeInstruction pciGOTO = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
// AnalyzeGOTO,
genericDestruct,
PCC_NONE // outCond
};
-pCodeInstruction pciINCF = {
+static pCodeInstruction pciINCF = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
// genericAnalyze,
genericDestruct,
PCC_REGISTER | PCC_Z // outCond
};
-pCodeInstruction pciINCFW = {
+static pCodeInstruction pciINCFW = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
// genericAnalyze,
genericDestruct,
PCC_W | PCC_Z // outCond
};
-pCodeInstruction pciINCFSZ = {
+static pCodeInstruction pciINCFSZ = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
// AnalyzeSKIP,
genericDestruct,
PCC_REGISTER | PCC_Z // outCond
};
-pCodeInstruction pciINCFSZW = {
+static pCodeInstruction pciINCFSZW = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
// AnalyzeSKIP,
genericDestruct,
PCC_W | PCC_Z // outCond
};
-pCodeInstruction pciIORWF = {
+static pCodeInstruction pciIORWF = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
// genericAnalyze,
genericDestruct,
(PCC_REGISTER | PCC_Z) // outCond
};
-pCodeInstruction pciIORFW = {
+static pCodeInstruction pciIORFW = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
// genericAnalyze,
genericDestruct,
(PCC_W | PCC_Z) // outCond
};
-pCodeInstruction pciIORLW = {
+static pCodeInstruction pciIORLW = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
// genericAnalyze,
genericDestruct,
(PCC_W | PCC_Z) // outCond
};
-pCodeInstruction pciMOVF = {
+static pCodeInstruction pciMOVF = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
// genericAnalyze,
genericDestruct,
PCC_Z // outCond
};
-pCodeInstruction pciMOVFW = {
+static pCodeInstruction pciMOVFW = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
// genericAnalyze,
genericDestruct,
(PCC_W | PCC_Z) // outCond
};
-pCodeInstruction pciMOVWF = {
+static pCodeInstruction pciMOVWF = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
// genericAnalyze,
genericDestruct,
PCC_REGISTER // outCond
};
-pCodeInstruction pciMOVLW = {
+static pCodeInstruction pciMOVLW = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
genericDestruct,
genericPrint},
PCC_W // outCond
};
-pCodeInstruction pciNOP = {
+static pCodeInstruction pciNOP = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
genericDestruct,
genericPrint},
PCC_NONE // outCond
};
-pCodeInstruction pciRETFIE = {
+static pCodeInstruction pciRETFIE = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
// AnalyzeRETURN,
genericDestruct,
(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,
(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,
(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,
(PCC_REGISTER | PCC_C ) // outCond
};
-pCodeInstruction pciRLFW = {
+static pCodeInstruction pciRLFW = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
// genericAnalyze,
genericDestruct,
(PCC_W | PCC_C) // outCond
};
-pCodeInstruction pciRRF = {
+static pCodeInstruction pciRRF = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
// genericAnalyze,
genericDestruct,
(PCC_REGISTER | PCC_C) // outCond
};
-pCodeInstruction pciRRFW = {
+static pCodeInstruction pciRRFW = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
// genericAnalyze,
genericDestruct,
(PCC_W | PCC_C) // outCond
};
-pCodeInstruction pciSUBWF = {
+static pCodeInstruction pciSUBWF = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
// genericAnalyze,
genericDestruct,
(PCC_REGISTER | PCC_C | PCC_DC | PCC_Z) // outCond
};
-pCodeInstruction pciSUBFW = {
+static pCodeInstruction pciSUBFW = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
// genericAnalyze,
genericDestruct,
(PCC_W | PCC_C | PCC_DC | PCC_Z) // outCond
};
-pCodeInstruction pciSUBLW = {
+static pCodeInstruction pciSUBLW = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
// genericAnalyze,
genericDestruct,
(PCC_W | PCC_Z | PCC_C | PCC_DC) // outCond
};
-pCodeInstruction pciSWAPF = {
+static pCodeInstruction pciSWAPF = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
// genericAnalyze,
genericDestruct,
(PCC_REGISTER) // outCond
};
-pCodeInstruction pciSWAPFW = {
+static pCodeInstruction pciSWAPFW = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
// genericAnalyze,
genericDestruct,
(PCC_W) // outCond
};
-pCodeInstruction pciTRIS = {
+static pCodeInstruction pciTRIS = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
// genericAnalyze,
genericDestruct,
PCC_REGISTER // outCond /* FIXME: what's TRIS doing */
};
-pCodeInstruction pciXORWF = {
+static pCodeInstruction pciXORWF = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
// genericAnalyze,
genericDestruct,
(PCC_REGISTER | PCC_Z) // outCond
};
-pCodeInstruction pciXORFW = {
+static pCodeInstruction pciXORFW = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
// genericAnalyze,
genericDestruct,
(PCC_W | PCC_Z) // outCond
};
-pCodeInstruction pciXORLW = {
+static pCodeInstruction pciXORLW = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
// genericAnalyze,
genericDestruct,
};
-pCodeInstruction pciBANKSEL = {
+static pCodeInstruction pciBANKSEL = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
// genericAnalyze,
genericDestruct,
PCC_NONE // outCond
};
-pCodeInstruction pciPAGESEL = {
+static pCodeInstruction pciPAGESEL = {
{PC_OPCODE, NULL, NULL, 0, 0, NULL,
// genericAnalyze,
genericDestruct,
/*-----------------------------------------------------------------*/
/* 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;
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;
/* */
/*-----------------------------------------------------------------*/
-int mnem2key(unsigned char const *mnem)
+static int mnem2key(unsigned char const *mnem)
{
int key = 0;
}
-void pic14initMnemonics(void)
+static void pic14initMnemonics(void)
{
int i = 0;
int key;
mnemonics_initialized = 1;
}
-int getpCodePeepCommand(char *cmd);
-
int getpCode(char *mnem,unsigned dest)
{
return -1;
}
-char getpBlock_dbName(pBlock *pb)
+static char getpBlock_dbName(pBlock *pb)
{
if(!pb)
return 0;
/* newPcodeInlineP - create a new pCode from a char string */
/*-----------------------------------------------------------------*/
-
-pCode *newpCodeInlineP(char *cP)
+#if 0
+static pCode *newpCodeInlineP(char *cP)
{
pCodeComment *pcc ;
return ( (pCode *)pcc);
}
+#endif
/*-----------------------------------------------------------------*/
/* newPcodeCharP - create a new pCode from a char string */
/*-----------------------------------------------------------------*/
/* newpCodeFlow */
/*-----------------------------------------------------------------*/
-void destructpCodeFlow(pCode *pc)
+static void destructpCodeFlow(pCode *pc)
{
if(!pc || !isPCFL(pc))
return;
}
-pCode *newpCodeFlow(void )
+static pCode *newpCodeFlow(void )
{
pCodeFlow *pcflow;
/*-----------------------------------------------------------------*/
/*-----------------------------------------------------------------*/
-pCodeFlowLink *newpCodeFlowLink(pCodeFlow *pcflow)
+static pCodeFlowLink *newpCodeFlowLink(pCodeFlow *pcflow)
{
pCodeFlowLink *pcflowLink;
/*-----------------------------------------------------------------*/
/* newpBlock - create and return a pointer to a new pBlock */
/*-----------------------------------------------------------------*/
-pBlock *newpBlock(void)
+static pBlock *newpBlock(void)
{
pBlock *PpB;
}
#if 0
-pCodeOp *newpCodeOpBitReg(regs *reg, int ibit, int inBitSpace)
+static pCodeOp *newpCodeOpBitReg(regs *reg, int ibit, int inBitSpace)
{
pCodeOp *pcop;
* for.
*-----------------------------------------------------------------*/
-pCodeOp *newpCodeOpReg(int rIdx)
+static pCodeOp *newpCodeOpReg(int rIdx)
{
pCodeOp *pcop;
return pcop;
}
-pCodeOp *newpCodeOpStr(char *name)
+static pCodeOp *newpCodeOpStr(char *name)
{
pCodeOp *pcop;
return pcop;
}
+#if 0
/*-----------------------------------------------------------------*/
/*-----------------------------------------------------------------*/
-void pCodeConstString(char *name, char *value)
+static void pCodeConstString(char *name, char *value)
{
pBlock *pb;
unsigned i;
/*-----------------------------------------------------------------*/
/*-----------------------------------------------------------------*/
-void pCodeReadCodeTable(void)
+static void pCodeReadCodeTable(void)
{
pBlock *pb;
}
+#endif
/*-----------------------------------------------------------------*/
/* addpCode2pBlock - place the pCode into the pBlock linked list */
/*-----------------------------------------------------------------*/
/* removepBlock - remove a pBlock from the pFile */
/*-----------------------------------------------------------------*/
-void removepBlock(pBlock *pb)
+static void removepBlock(pBlock *pb)
{
pBlock *pbs;
}
}
+#if 0
/*-----------------------------------------------------------------*/
/*-----------------------------------------------------------------*/
-void pBlockRegs(FILE *of, pBlock *pb)
+static void pBlockRegs(FILE *of, pBlock *pb)
{
regs *r;
r = setNextItem(pb->tregisters);
}
}
-
+#endif
/*-----------------------------------------------------------------*/
/*-----------------------------------------------------------------*/
/*-----------------------------------------------------------------*/
/*-----------------------------------------------------------------*/
-int compareLabel(pCode *pc, pCodeOpLabel *pcop_label)
+static int compareLabel(pCode *pc, pCodeOpLabel *pcop_label)
{
pBranch *pbr;
/*-----------------------------------------------------------------*/
/*-----------------------------------------------------------------*/
-int checkLabel(pCode *pc)
+static int checkLabel(pCode *pc)
{
pBranch *pbr;
/*-----------------------------------------------------------------*/
/* 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;
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;
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' */
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) {
return NULL;
}
+#endif
/*-----------------------------------------------------------------*/
/* findNextInstruction - given a pCode, find the next instruction */
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))
fprintf(stderr,"Couldn't find function end\n");
return NULL;
}
+#endif
#if 0
/*-----------------------------------------------------------------*/
/*-----------------------------------------------------------------*/
/*-----------------------------------------------------------------*/
-void AnalyzepBlock(pBlock *pb)
+static void AnalyzepBlock(pBlock *pb)
{
pCode *pc;
/*-----------------------------------------------------------------*/
/* */
/*-----------------------------------------------------------------*/
-void InsertpFlow(pCode *pc, pCode **pflow)
+static void InsertpFlow(pCode *pc, pCode **pflow)
{
if(*pflow)
PCFL(*pflow)->end = pc;
* point the instruction flow changes.
*/
/*-----------------------------------------------------------------*/
-void BuildFlow(pBlock *pb)
+static void BuildFlow(pBlock *pb)
{
pCode *pc;
pCode *last_pci=NULL;
* unBuildFlow removes pCodeFlow objects from a pCode chain
*/
/*-----------------------------------------------------------------*/
-void unBuildFlow(pBlock *pb)
+static void unBuildFlow(pBlock *pb)
{
pCode *pc,*pcnext;
}
+#if 0
/*-----------------------------------------------------------------*/
/*-----------------------------------------------------------------*/
-void dumpCond(int cond)
+static void dumpCond(int cond)
{
static char *pcc_str[] = {
fprintf(stderr, " %s\n",pcc_str[i]);
}
+#endif
+#if 0
/*-----------------------------------------------------------------*/
/*-----------------------------------------------------------------*/
-void FlowStats(pCodeFlow *pcflow)
+static void FlowStats(pCodeFlow *pcflow)
{
pCode *pc;
dumpCond(pcflow->outCond);
}
+#endif
/*-----------------------------------------------------------------*
* int isBankInstruction(pCode *pc) - examine the pCode *pc to determine
*
*-----------------------------------------------------------------*/
/*
-#define SET_BANK_BIT (1 << 16)
-#define CLR_BANK_BIT 0
-
static int isBankInstruction(pCode *pc)
{
regs *reg;
/*-----------------------------------------------------------------*/
/*-----------------------------------------------------------------*/
-void LinkFlow_pCode(pCodeInstruction *from, pCodeInstruction *to)
+static void LinkFlow_pCode(pCodeInstruction *from, pCodeInstruction *to)
{
pCodeFlowLink *fromLink, *toLink;
#if 0
* 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;
/*-----------------------------------------------------------------*/
/*-----------------------------------------------------------------*/
+#if 0
/*-----------------------------------------------------------------*/
/*-----------------------------------------------------------------*/
-int isPCinFlow(pCode *pc, pCode *pcflow)
+static int isPCinFlow(pCode *pc, pCode *pcflow)
{
if(!pc || !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
/*-----------------------------------------------------------------*/
/*-----------------------------------------------------------------*/
}
*/
-void pCodeReplace (pCode *old, pCode *new)
+static void pCodeReplace (pCode *old, pCode *new)
{
pCodeInsertAfter (old, new);
/*-----------------------------------------------------------------*/
/*-----------------------------------------------------------------*/
-void addpCodeComment(pCode *pc, const char *fmt, ...)
+static void addpCodeComment(pCode *pc, const char *fmt, ...)
{
va_list ap;
char buffer[4096];
va_end(ap);
}
-void pBlockMergeLabels(pBlock *pb);
/*-----------------------------------------------------------------*/
/* Inserts a new pCodeInstruction before an existing one */
/*-----------------------------------------------------------------*/
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;
/*-----------------------------------------------------------------*/
/*-----------------------------------------------------------------*/
-void FixRegisterBanking(pBlock *pb)
+static void FixRegisterBanking(pBlock *pb)
{
pCode *pc;
pCodeInstruction *pci;
/*-----------------------------------------------------------------*/
/*-----------------------------------------------------------------*/
-int OptimizepBlock(pBlock *pb)
+static int OptimizepBlock(pBlock *pb)
{
pCode *pc, *pcprev;
int matches =0;
/*-----------------------------------------------------------------*/
/* pBlockRemoveUnusedLabels - remove the pCode labels from the */
/*-----------------------------------------------------------------*/
-pCode * findInstructionUsingLabel(pCodeLabel *pcl, pCode *pcs)
+static pCode * findInstructionUsingLabel(pCodeLabel *pcl, pCode *pcs)
{
pCode *pc;
/*-----------------------------------------------------------------*/
/*-----------------------------------------------------------------*/
-void exchangeLabels(pCodeLabel *pcl, pCode *pc)
+static void exchangeLabels(pCodeLabel *pcl, pCode *pc)
{
char *s=NULL;
/* 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;
* 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 */
/* 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;
/*-----------------------------------------------------------------*/
/*-----------------------------------------------------------------*/
-int OptimizepCode(char dbName)
+static int OptimizepCode(char dbName)
{
#define MAX_PASSES 4
/*-----------------------------------------------------------------*/
/*-----------------------------------------------------------------*/
-void pBlockDestruct(pBlock *pb)
+static void pBlockDestruct(pBlock *pb)
{
if(!pb)
/* name dbName and combine them */
/* into one block */
/*-----------------------------------------------------------------*/
-void mergepBlocks(char dbName)
+static void mergepBlocks(char dbName)
{
pBlock *pb, *pbmerged = NULL,*pbn;
/* 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));
+ }
+ }
+ */
}
/*-----------------------------------------------------------------*/
/*-----------------------------------------------------------------*/
/*-----------------------------------------------------------------*/
-DEFSETFUNC (resetrIdx)
+static DEFSETFUNC (resetrIdx)
{
regs *r = (regs *)item;
if (!r->isFixed) {
/*-----------------------------------------------------------------*/
/* 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 */
/* */
/*-----------------------------------------------------------------*/
-void buildCallTree(void )
+static void buildCallTree(void)
{
pBranch *pbr;
pBlock *pb;
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) {
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)
return 0;
}
+#endif
/*-----------------------------------------------------------------*/
/* findFunction - Search for a function by name (given the name) */
/* (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;
return NULL;
}
-void MarkUsedRegisters(set *regset)
+#if 0
+static void MarkUsedRegisters(set *regset)
{
regs *r1,*r2;
}
}
}
+#endif
-void pBlockStats(FILE *of, pBlock *pb)
+static void pBlockStats(FILE *of, pBlock *pb)
{
pCode *pc;
/*-----------------------------------------------------------------*/
/*-----------------------------------------------------------------*/
/*
-set *register_usage(pBlock *pb)
+static set *register_usage(pBlock *pb)
{
pCode *pc,*pcn;
set *registers=NULL;
/* 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;
}
-
+#if 0
/*-----------------------------------------------------------------*/
/* printCallTree - writes the call tree to a file */
/* */
/*-----------------------------------------------------------------*/
-void printCallTree(FILE *of)
+static void printCallTree(FILE *of)
{
pBranch *pbr;
pBlock *pb;
fprintf(of,"block dbname: %c\n", getpBlock_dbName(pb));
}
}
-
+#endif
/*-----------------------------------------------------------------*/
/* */
/*-----------------------------------------------------------------*/
-void InlineFunction(pBlock *pb)
+static void InlineFunction(pBlock *pb)
{
pCode *pc;
pCode *pc_call;
unBuildFlow(pb);
}
+
-------------------------------------------------------------------------*/
-//#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
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
*
#ifdef PCODE_DEBUG
#define DFPRINTF(args) (fprintf args)
#else
-#define DFPRINTF(args) ;
+#define DFPRINTF(args) ((void)0)
#endif
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);
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);
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);
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__
*/
-#include <stdio.h>
-
-#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
static set *FlowTree=NULL;
-void dbg_dumpFlowTree(set *FlowTree)
+static void dbg_dumpFlowTree(set *FlowTree)
{
set *segment;
pCodeFlow *pcflow;
/*-----------------------------------------------------------------*
* void BuildFlowSegment(set *segment, pCodeFlow *pcflow)
*-----------------------------------------------------------------*/
-void BuildFlowSegment(set *segment, pCodeFlow *pcflow)
+static void BuildFlowSegment(set *segment, pCodeFlow *pcflow)
{
int nNextFlow=0;
}
#endif
-void dbg_dumpFlow(pBlock *pb)
+#if 0
+static void dbg_dumpFlow(pBlock *pb)
{
pCode *pcflow;
}
}
+#endif
+
/*-----------------------------------------------------------------*
* void BuildFlowSegment(set *segment, pCodeFlow *pcflow)
*-----------------------------------------------------------------*/
-void BuildFlowSegment(pCodeFlow *pcflow)
+static void BuildFlowSegment(pCodeFlow *pcflow)
{
static int recursion=0;
pCodeFlow *pcflow_other;
#ifndef __PCODEFLOW_H__
#define __PCODEFLOW_H__
+#include "pcode.h"
+
/*************************************************
* pCode conditions:
*
/*------------------------------------------------------------*/
-void BuildFlowAncestry(pBlock *pb);
+void BuildFlowTree(pBlock *pb);
#endif // __PCODEFLOW_H__
+
Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-------------------------------------------------------------------------*/
-#include <stdio.h>
-#include <stdlib.h>
-
-#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))
} pCodeToken;
-pCodeToken tokArr[50];
-unsigned tokIdx=0;
+static pCodeToken tokArr[50];
+static unsigned tokIdx=0;
typedef enum {
} 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,
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},
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},
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;
-void dump1Token(pCodeTokens tt)
+static void dump1Token(pCodeTokens tt)
{
switch(tt) {
/*-----------------------------------------------------------------*/
/*-----------------------------------------------------------------*/
-int pcComparePattern(pCodeToken *pct, char *pat, int max_tokens)
+static int pcComparePattern(pCodeToken *pct, char *pat, int max_tokens)
{
int i=0;
/*-----------------------------------------------------------------*/
/*-----------------------------------------------------------------*/
-int altComparePattern( char *pct, parsedPattern *pat, int max_tokens)
+static int altComparePattern(char *pct, parsedPattern *pat, int max_tokens)
{
int i=0;
/*-----------------------------------------------------------------*/
/*-----------------------------------------------------------------*/
-int advTokIdx(int *v, int amt)
+static int advTokIdx(int *v, int amt)
{
if((unsigned) (*v + amt) > tokIdx)
/* pcode. */
/*-----------------------------------------------------------------*/
-int parseTokens(pCodeWildBlock *pcwb, pCode **pcret)
+static int parseTokens(pCodeWildBlock *pcwb, pCode **pcret)
{
pCode *pc;
int error = 0;
/*-----------------------------------------------------------------*/
/* */
/*-----------------------------------------------------------------*/
-void peepRuleBlock2pCodeBlock( lineNode *ln, pCodeWildBlock *pcwb)
+static void peepRuleBlock2pCodeBlock(lineNode *ln, pCodeWildBlock *pcwb)
{
if(!ln)
}
}
+#if 0
/*-----------------------------------------------------------------*/
/* */
/*-----------------------------------------------------------------*/
-pCode *AssembleLine(char *line)
+static pCode *AssembleLine(char *line)
{
pCode *pc=NULL;
return pc;
}
+#endif
/*-----------------------------------------------------------------*/
/* peepRuleCondition */
}
-
-void initpCodeWildBlock(pCodeWildBlock *pcwb)
+static void initpCodeWildBlock(pCodeWildBlock *pcwb)
{
// pcwb = Safe_calloc(1,sizeof(pCodeWildBlock));
}
-void postinit_pCodeWildBlock(pCodeWildBlock *pcwb)
+static void postinit_pCodeWildBlock(pCodeWildBlock *pcwb)
{
if(!pcwb)
}
-void initpCodePeep(pCodePeep *pcp)
+static void initpCodePeep(pCodePeep *pcp)
{
// pcwb = Safe_calloc(1,sizeof(pCodeWildBlock));
/* taking raw text to produce machine code, it produces pCode. */
/* */
/*-----------------------------------------------------------------*/
-extern void pic14initpCodePeepCommands(void);
-
-void peepRules2pCode(peepRule *rules)
+void peepRules2pCode(peepRule *rules)
{
peepRule *pr;
}
-void printpCodeString(FILE *of, pCode *pc, int max)
+#if 0
+static void printpCodeString(FILE *of, pCode *pc, int max)
{
int i=0;
pc = pc->next;
}
}
+#endif
/*-----------------------------------------------------------------*/
/* _DLL * DLL_append */
*
* 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;
return 1;
}
-int pCodePeepMatchLabels(pCodePeep *peepBlock, pCode *pcs, pCode *pcd)
+static int pCodePeepMatchLabels(pCodePeep *peepBlock, pCode *pcs, pCode *pcd)
{
int labindex;
/* */
/*-----------------------------------------------------------------*/
-int pCodePeepMatchLine(pCodePeep *peepBlock, pCode *pcs, pCode *pcd)
+static int pCodePeepMatchLine(pCodePeep *peepBlock, pCode *pcs, pCode *pcd)
{
int index; // index into wild card arrays
/*-----------------------------------------------------------------*/
/*-----------------------------------------------------------------*/
-void pCodePeepClrVars(pCodePeep *pcp)
+static void pCodePeepClrVars(pCodePeep *pcp)
{
int i;
The purpose of the code in this file is to optimize the register usage.
*/
-#include <stdio.h>
-#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))
*/
+#if 0
/*-----------------------------------------------------------------*
*
*-----------------------------------------------------------------*/
-void dbg_regusage(set *fregs)
+static void dbg_regusage(set *fregs)
{
regs *reg;
pCode *pcfl;
}
}
}
+#endif
+#if 0
/*-----------------------------------------------------------------*
*
*-----------------------------------------------------------------*/
-void dbg_dumpregusage(void)
+static void dbg_dumpregusage(void)
{
fprintf(stderr,"*** Register Usage ***\n");
dbg_regusage(dynProcessorRegs);
}
-
+#endif
/*-----------------------------------------------------------------*
* void pCodeRegMapLiveRangesInFlow(pCodeFlow *pcfl)
*-----------------------------------------------------------------*/
-void pCodeRegMapLiveRangesInFlow(pCodeFlow *pcfl)
+static void pCodeRegMapLiveRangesInFlow(pCodeFlow *pcfl)
{
pCode *pc=NULL;
* void RemoveRegsFromSet(set *regset)
*
*-----------------------------------------------------------------*/
-void RemoveRegsFromSet(set *regset)
+static void RemoveRegsFromSet(set *regset)
{
regs *reg;
int used;
}
}
-void RegsUnMapLiveRanges(void);
-extern pFile *the_pFile;
-void pic14_ReMapLiveRanges(void)
+static void pic14_ReMapLiveRanges(void)
{
pBlock *pb;
if (!the_pFile) return;
/*-----------------------------------------------------------------*
*
*-----------------------------------------------------------------*/
-int regUsedinRange(pCode *pc1, pCode *pc2, regs *reg)
+static int regUsedinRange(pCode *pc1, pCode *pc2, regs *reg)
{
int i=0;
regs *testreg;
return 0;
}
-int regIsSpecial (regs *reg, int mayBeGlobal)
+static int regIsSpecial (regs *reg, int mayBeGlobal)
{
if (!reg) return 0;
*
*
*-----------------------------------------------------------------*/
-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;
/*-----------------------------------------------------------------*
* 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;
if(pc1 && isPCI(pc1) && ( (pcfl1 = PCI(pc1)->pcflow) != NULL) ) {
- //while(rset2 && searching) {
if(rset2) {
pc2 = rset2->item;
} // while
}
-int regIsDead (regs *reg, int cond, pCode *pc)
+static int regIsDead (regs *reg, int cond, pCode *pc)
{
set *seenStates = NULL;
set *todo = NULL;
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;
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;
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;
it with a better variant if possible.
------------------------------------------------------------------ */
-void analyzeAndReplacePCI (pCodeInstruction *pci)
+static void analyzeAndReplacePCI (pCodeInstruction *pci)
{
regs *op_reg, *alias_reg;
} // switch
}
-extern pFile *the_pFile;
-
/* ------------------------------------------------------------------
Find and remove dead pCodes.
------------------------------------------------------------------ */
not used) -- these should be removed in a following sweep phase.
------------------------------------------------------------------ */
-void optimizeDataflow (void)
+static void optimizeDataflow (void)
{
pBlock *pb;
* void RegsUnMapLiveRanges(set *regset)
*
*-----------------------------------------------------------------*/
-void RegsSetUnMapLiveRanges(set *regset)
+static void RegsSetUnMapLiveRanges(set *regset)
{
regs *reg;
#ifndef __PCODEREGS_H__
#define __PCODEREGS_H__
+#include "common.h"
+
+#include "pcode.h"
+
/*************************************************
pCodeRegLives
} pCodeRegLives;
+void pCodeRegMapLiveRanges(struct pBlock *pb);
+void pCodeRegOptimizeRegUsage(int level);
+void RegsUnMapLiveRanges(void);
+void RemoveUnusedRegisters(void);
#endif // __PCODEREGS_H__
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
/* 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
{
}
_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,...)
{
debugF = NULL;
}
}
-#define AOP(op) op->aop
static char *
debugAopGet (char *str, operand * op)
}
-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 */
/*-----------------------------------------------------------------*/
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 */
/*-----------------------------------------------------------------*/
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 */
/*-----------------------------------------------------------------*/
return nFreeRegs (type);
}
-void writeSetUsedRegs(FILE *of, set *dRegs)
+#if 0
+static void writeSetUsedRegs(FILE *of, set *dRegs)
{
regs *dReg;
}
}
-extern void dump_map(void);
+#endif
-void packBits(set *bregs)
+static void packBits(set *bregs)
{
set *regset;
regs *breg;
-void bitEQUs(FILE *of, set *bregs)
+static void bitEQUs(FILE *of, set *bregs)
{
regs *breg,*bytereg;
int bit_no=0;
}
-void aliasEQUs(FILE *of, set *fregs, int use_rIdx)
+#if 0
+static void aliasEQUs(FILE *of, set *fregs, int use_rIdx)
{
regs *reg;
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",
}
}
+#endif
void writeUsedRegs(FILE *of)
{
packBits(dynDirectBitRegs);
- //dump_map();
-
bitEQUs(of,dynDirectBitRegs);
}
}
}
+
+#if 0
+static
DEFSETFUNC (markRegFree)
{
((regs *)item)->isFree = 1;
return 0;
}
+static
DEFSETFUNC (deallocReg)
{
fprintf(stderr,"deallocting register %s\n",((regs *)item)->name);
return 0;
}
+
/*-----------------------------------------------------------------*/
/* freeAllRegs - mark all registers as free */
/*-----------------------------------------------------------------*/
-void
+static void
pic14_freeAllRegs ()
{
// int i;
/*-----------------------------------------------------------------*/
/*-----------------------------------------------------------------*/
-void
+static void
pic14_deallocateAllRegs ()
{
// int i;
}
*/
}
+#endif
/*-----------------------------------------------------------------*/
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);
* 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;
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"
}
regs;
extern regs regspic14[];
-extern int pic14_nRegs;
extern int Gstack_base_addr;
/*
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);
#define IDX_SSAVE 0x7ffd
#define IDX_PSAVE 0x7ffc
+#define pic14_nRegs 128
+
#endif
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 */
}
-#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;
return (key & 0x1f);
}
-#endif
void pic16initMnemonics(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)));