* Makefile.in, configure.in, configure,
[fw/sdcc] / src / pic / pcodepeep.c
index f041796a8831bfe6c60219dff63b8ee535e0a84e..129158937e6f6e782c6f669e0a0e5dc533c6afe0 100644 (file)
    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))
 
-/****************************************************************/
-/*
-* rootRules - defined in SDCCpeep.c
-*  This is a pointer to the (parsed) peephole rules that are
-* defined in peep.def.
-*/
-
-//extern peepRule *rootRules;
-
-
-
 
 /****************************************************************/
 /****************************************************************/
@@ -82,32 +51,6 @@ typedef struct pCodePeepSnippets
 
 static pCodePeepSnippets  *peepSnippets=NULL;
 
-/****************************************************************/
-/*                                                              */
-/* curPeep                                                      */
-/*                                                              */
-/****************************************************************/
-
-//static pCodePeep          *curPeep=NULL;
-
-/****************************************************************/
-/*                                                              */
-/* curBlock                                                     */
-/*                                                              */
-/****************************************************************/
-
-//static pBlock             *curBlock=NULL;
-
-
-/****************************************************************/
-/*                                                              */
-/* max wild cards in a peep rule                                */
-/*                                                              */
-/****************************************************************/
-
-//static int                sMaxWildVar   = 0;
-//static int                sMaxWildMnem  = 0;
-
 
 typedef struct pCodeToken 
 {
@@ -120,8 +63,8 @@ typedef struct pCodeToken
        
 } pCodeToken;
 
-pCodeToken tokArr[50];
-unsigned   tokIdx=0;
+static pCodeToken tokArr[50];
+static unsigned   tokIdx=0;
 
 
 typedef enum  {
@@ -145,9 +88,7 @@ typedef struct parsedPattern {
 } parsedPattern;
 
 #define MAX_PARSEDPATARR 50
-parsedPattern parsedPatArr[MAX_PARSEDPATARR];
-unsigned int parsedPatIdx=0;
-
+static parsedPattern parsedPatArr[MAX_PARSEDPATARR];
 
 typedef enum {
        PCP_LABEL=1,
@@ -174,7 +115,7 @@ typedef struct pcPattern {
        void * (*f) (void *,pCodeWildBlock *);
 } pcPattern;
 
-pcPattern pcpArr[] = {
+static pcPattern pcpArr[] = {
        {PCP_LABEL,     pcpat_label,      NULL},
        {PCP_WILDSTR,   pcpat_wildString, NULL},
        {PCP_STR,       pcpat_string,     NULL},
@@ -222,7 +163,7 @@ static void * cvt_altpat_mnem2(void *pp,pCodeWildBlock *pcwb);
 static void * cvt_altpat_mnem2a(void *pp,pCodeWildBlock *pcwb);
 static void * cvt_altpat_mnem3(void *pp,pCodeWildBlock *pcwb);
 
-pcPattern altArr[] = {
+static pcPattern altArr[] = {
        {ALT_LABEL,        alt_label,  cvt_altpat_label},
        {ALT_COMMENT,      alt_comment,cvt_altpat_comment},
        {ALT_MNEM3,        alt_mnem3,  cvt_altpat_mnem3},
@@ -285,14 +226,14 @@ static pCodeOp *cvt_extract_status(char *reg, char *bit)
        if(len == 1) {
                // check C,Z
                if(toupper((unsigned char)*bit) == 'C')
-                       return PCOP(popCopyGPR2Bit(&pc_status,PIC_C_BIT));
+                       return PCOP(popCopyGPR2Bit(PCOP(&pc_status),PIC_C_BIT));
                if(toupper((unsigned char)*bit) == 'Z')
-                       return PCOP(popCopyGPR2Bit(&pc_status,PIC_Z_BIT));
+                       return PCOP(popCopyGPR2Bit(PCOP(&pc_status),PIC_Z_BIT));
        }
        
        // Check DC
        if(len ==2 && toupper((unsigned char)bit[0]) == 'D' && toupper((unsigned char)bit[1]) == 'C')
-               return PCOP(popCopyGPR2Bit(&pc_status,PIC_DC_BIT));
+               return PCOP(popCopyGPR2Bit(PCOP(&pc_status),PIC_DC_BIT));
        
        return NULL;
        
@@ -386,10 +327,6 @@ static void * cvt_altpat_mnem0a(void *pp, pCodeWildBlock *pcwb)
        DFPRINTF((stderr,"altpat_mnem0a wild mnem # %d\n",  p[0].pct[1].tok.n));
        
        /* Save the index of the maximum wildcard mnemonic */
-       
-       //if(p[0].pct[1].tok.n > sMaxWildVar)
-       //  sMaxWildMnem = p[0].pct[1].tok.n;
-       
        if(p[0].pct[1].tok.n > pcwb->nwildpCodes)
                pcwb->nwildpCodes = p[0].pct[1].tok.n;
        
@@ -497,9 +434,6 @@ static void * cvt_altpat_mnem1a(void *pp,pCodeWildBlock *pcwb)
                newpCodeOpWild(p[1].pct[1].tok.n, pcwb, pcosubtype)));
        
        /* Save the index of the maximum wildcard variable */
-       //if(p[1].pct[1].tok.n > sMaxWildVar)
-       //  sMaxWildVar = p[1].pct[1].tok.n;
-       
        if(p[1].pct[1].tok.n > pcwb->nvars)
                pcwb->nvars = p[1].pct[1].tok.n;
        
@@ -638,9 +572,6 @@ static void * cvt_altpat_mnem2a(void *pp,pCodeWildBlock *pcwb)
                newpCodeOpWild(p[1].pct[1].tok.n, pcwb, pcosubtype)));
        
        /* Save the index of the maximum wildcard variable */
-       //if(p[1].pct[1].tok.n > sMaxWildVar)
-       //  sMaxWildVar = p[1].pct[1].tok.n;
-       
        if(p[1].pct[1].tok.n > pcwb->nvars)
                pcwb->nvars = p[1].pct[1].tok.n;
        
@@ -820,7 +751,7 @@ static void tokenizeLineNode(char *ln)
 
 
 
-void dump1Token(pCodeTokens tt)
+static void dump1Token(pCodeTokens tt)
 {
        
        switch(tt) {
@@ -865,7 +796,7 @@ void dump1Token(pCodeTokens tt)
 /*-----------------------------------------------------------------*/
 /*-----------------------------------------------------------------*/
 
-int pcComparePattern(pCodeToken *pct, char *pat, int max_tokens)
+static int pcComparePattern(pCodeToken *pct, char *pat, int max_tokens)
 {
        int i=0;
        
@@ -898,7 +829,7 @@ int pcComparePattern(pCodeToken *pct, char *pat, int max_tokens)
 /*-----------------------------------------------------------------*/
 /*-----------------------------------------------------------------*/
 
-int altComparePattern( char *pct, parsedPattern *pat, int max_tokens)
+static int altComparePattern(char *pct, parsedPattern *pat, int max_tokens)
 {
        int i=0;
        
@@ -933,7 +864,7 @@ int altComparePattern( char *pct, parsedPattern *pat, int max_tokens)
 /*-----------------------------------------------------------------*/
 /*-----------------------------------------------------------------*/
 
-int advTokIdx(int *v, int amt)
+static int advTokIdx(int *v, int amt)
 {
        
        if((unsigned) (*v + amt) > tokIdx)
@@ -962,7 +893,7 @@ int advTokIdx(int *v, int amt)
 /* pcode.                                                          */
 /*-----------------------------------------------------------------*/
 
-int parseTokens(pCodeWildBlock *pcwb, pCode **pcret)
+static int parseTokens(pCodeWildBlock *pcwb, pCode **pcret)
 {
        pCode *pc;
        int error = 0;
@@ -1145,8 +1076,6 @@ int parseTokens(pCodeWildBlock *pcwb, pCode **pcret)
                                //  pc->print(stderr,pc);
                                //if(pc && pc->destruct) pc->destruct(pc); dumps core?
                                
-                               //if(curBlock && pc)
-                               //addpCode2pBlock(curBlock, pc);
                                if(pc) {
                                        if (pcret) {
                                                *pcret = pc;
@@ -1184,7 +1113,7 @@ int parseTokens(pCodeWildBlock *pcwb, pCode **pcret)
 /*-----------------------------------------------------------------*/
 /*                                                                 */
 /*-----------------------------------------------------------------*/
-void  peepRuleBlock2pCodeBlock(  lineNode *ln, pCodeWildBlock *pcwb)
+static void peepRuleBlock2pCodeBlock(lineNode *ln, pCodeWildBlock *pcwb)
 {
        
        if(!ln)
@@ -1208,27 +1137,6 @@ void  peepRuleBlock2pCodeBlock(  lineNode *ln, pCodeWildBlock *pcwb)
        }
 }
 
-/*-----------------------------------------------------------------*/
-/*                                                                 */
-/*-----------------------------------------------------------------*/
-pCode *AssembleLine(char *line)
-{
-       pCode *pc=NULL;
-       
-       if(!line || !*line) {
-               fprintf(stderr,"WARNING returning NULL in AssembleLine\n");
-               return NULL;
-       }
-       
-       tokenizeLineNode(line);
-
-       if(parseTokens(NULL,&pc))
-               fprintf(stderr, "WARNING: unable to assemble line:\n%s\n",line);
-       
-       return pc;
-       
-}
-
 /*-----------------------------------------------------------------*/
 /* peepRuleCondition                                               */
 /*-----------------------------------------------------------------*/
@@ -1248,8 +1156,7 @@ static void   peepRuleCondition(char *cond, pCodePeep *pcp)
        
 }
 
-
-void initpCodeWildBlock(pCodeWildBlock *pcwb)
+static void initpCodeWildBlock(pCodeWildBlock *pcwb)
 {
        
        //  pcwb = Safe_calloc(1,sizeof(pCodeWildBlock));
@@ -1267,7 +1174,7 @@ void initpCodeWildBlock(pCodeWildBlock *pcwb)
        
 }
 
-void postinit_pCodeWildBlock(pCodeWildBlock *pcwb)
+static void postinit_pCodeWildBlock(pCodeWildBlock *pcwb)
 {
        
        if(!pcwb)
@@ -1284,7 +1191,7 @@ void postinit_pCodeWildBlock(pCodeWildBlock *pcwb)
        
 }
 
-void initpCodePeep(pCodePeep *pcp)
+static void initpCodePeep(pCodePeep *pcp)
 {
        
        //  pcwb = Safe_calloc(1,sizeof(pCodeWildBlock));
@@ -1311,9 +1218,7 @@ void initpCodePeep(pCodePeep *pcp)
 /* taking raw text to produce machine code, it produces pCode.     */
 /*                                                                 */
 /*-----------------------------------------------------------------*/
-extern void pic14initpCodePeepCommands(void);
-
-void  peepRules2pCode(peepRule *rules)
+void peepRules2pCode(peepRule *rules)
 {
        peepRule *pr;
        
@@ -1346,23 +1251,12 @@ void  peepRules2pCode(peepRule *rules)
                //DFPRINTF((stderr,"finished target, here it is in pcode form:\n"));
                //printpBlock(stderr, currentRule->target.pb);
                
-               //DFPRINTF((stderr,"target with labels merged:\n"));
-               //pBlockMergeLabels(curBlock);
                pBlockMergeLabels(currentRule->target.pb);
                //printpBlock(stderr, currentRule->replace.pb);
                
-               //#ifdef PCODE_DEBUG
-               //    printpBlock(stderr, curBlock);
-               //#endif
-               //DFPRINTF((stderr,"\nReplaced by:\n"));
-               
-               
                /* Convert the replace block */
                peepRuleBlock2pCodeBlock(pr->replace, &currentRule->replace);
                
-               //DFPRINTF((stderr,"finished replace block, here it is in pcode form:\n"));
-               //printpBlock(stderr, curBlock);
-               
                //DFPRINTF((stderr,"replace with labels merged:\n"));
                
                pBlockMergeLabels(currentRule->replace.pb);
@@ -1396,16 +1290,6 @@ void  peepRules2pCode(peepRule *rules)
        
 }
 
-void printpCodeString(FILE *of, pCode *pc, int max)
-{
-       int i=0;
-       
-       while(pc && (i++<max)) {
-               pc->print(of,pc);
-               pc = pc->next;
-       }
-}
-
 /*-----------------------------------------------------------------*/
 /* _DLL * DLL_append                                               */
 /*                                                                 */ 
@@ -1517,7 +1401,7 @@ int pCodeSearchCondition(pCode *pc, unsigned int cond, int contIfSkip)
 *
 * Compare two pCodeOp's and return 1 if they're the same
 *-----------------------------------------------------------------*/
-int pCodeOpCompare(pCodeOp *pcops, pCodeOp *pcopd)
+static int pCodeOpCompare(pCodeOp *pcops, pCodeOp *pcopd)
 {
        char b[50], *n2;
        
@@ -1570,7 +1454,7 @@ int pCodeOpCompare(pCodeOp *pcops, pCodeOp *pcopd)
        return 1;
 }
 
-int pCodePeepMatchLabels(pCodePeep *peepBlock, pCode *pcs, pCode *pcd)
+static int pCodePeepMatchLabels(pCodePeep *peepBlock, pCode *pcs, pCode *pcd)
 {
        int labindex;
        
@@ -1653,7 +1537,7 @@ int pCodePeepMatchLabels(pCodePeep *peepBlock, pCode *pcs, pCode *pcd)
 /*                                                                 */
 /*-----------------------------------------------------------------*/
 
-int pCodePeepMatchLine(pCodePeep *peepBlock, pCode *pcs, pCode *pcd)
+static int pCodePeepMatchLine(pCodePeep *peepBlock, pCode *pcs, pCode *pcd)
 {
        int index;   // index into wild card arrays
        
@@ -1876,7 +1760,7 @@ int pCodePeepMatchLine(pCodePeep *peepBlock, pCode *pcs, pCode *pcd)
 
 /*-----------------------------------------------------------------*/
 /*-----------------------------------------------------------------*/
-void pCodePeepClrVars(pCodePeep *pcp)
+static void pCodePeepClrVars(pCodePeep *pcp)
 {
        
        int i;