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);
}
+