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"
-#if defined(__BORLANDC__) || defined(_MSC_VER)
-#define STRCASECMP stricmp
-#else
-#define STRCASECMP strcasecmp
-#endif
-
-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;
-
-
-
/****************************************************************/
/****************************************************************/
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
{
} 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];
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},
// just check first letter for now
- if(toupper(*pp->pct[0].tok.s) == 'F')
+ if(toupper((unsigned char)*pp->pct[0].tok.s) == 'F')
return 1;
} else if (pp->pct[0].tt == PCT_NUMBER) {
if(len == 1) {
// check C,Z
- if(toupper(*bit) == 'C')
- return PCOP(popCopyGPR2Bit(&pc_status,PIC_C_BIT));
- if(toupper(*bit) == 'Z')
- return PCOP(popCopyGPR2Bit(&pc_status,PIC_Z_BIT));
+ if(toupper((unsigned char)*bit) == 'C')
+ return PCOP(popCopyGPR2Bit(PCOP(&pc_status),PIC_C_BIT));
+ if(toupper((unsigned char)*bit) == 'Z')
+ return PCOP(popCopyGPR2Bit(PCOP(&pc_status),PIC_Z_BIT));
}
// Check DC
- if(len ==2 && toupper(bit[0]) == 'D' && toupper(bit[1]) == 'C')
- return PCOP(popCopyGPR2Bit(&pc_status,PIC_DC_BIT));
+ if(len ==2 && toupper((unsigned char)bit[0]) == 'D' && toupper((unsigned char)bit[1]) == 'C')
+ return PCOP(popCopyGPR2Bit(PCOP(&pc_status),PIC_DC_BIT));
return NULL;
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;
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;
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;
while(*ln) {
- if(isspace(*ln)) {
+ if(isspace((unsigned char)*ln)) {
// add a SPACE token and eat the extra spaces.
tokArr[tokIdx++].tt = PCT_SPACE;
- while (isspace (*ln))
+ while (isspace ((unsigned char)*ln))
ln++;
continue;
}
- if(isdigit(*ln)) {
+ if(isdigit((unsigned char)*ln)) {
tokArr[tokIdx].tt = PCT_NUMBER;
tokArr[tokIdx++].tok.n = strtol(ln, &ln, 0);
default:
- if(isalpha(*ln) || (*ln == '_') ) {
+ if(isalpha((unsigned char)*ln) || (*ln == '_') ) {
char buffer[50];
int i=0;
- while( (isalpha(*ln) || isdigit(*ln) || (*ln == '_')) && i<49)
+ while( (isalpha((unsigned char)*ln) || isdigit((unsigned char)*ln) || (*ln == '_')) && i<49)
buffer[i++] = *ln++;
ln--;
-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;
// 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;
/*-----------------------------------------------------------------*/
/* */
/*-----------------------------------------------------------------*/
-void peepRuleBlock2pCodeBlock( lineNode *ln, pCodeWildBlock *pcwb)
+static void peepRuleBlock2pCodeBlock(lineNode *ln, pCodeWildBlock *pcwb)
{
if(!ln)
}
}
-/*-----------------------------------------------------------------*/
-/* */
-/*-----------------------------------------------------------------*/
-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 */
/*-----------------------------------------------------------------*/
}
-
-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;
//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, ¤tRule->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);
}
-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 */
/* */
*
* 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;
/* We have just replaced the inefficient code with the rule.
* Now, we need to re-add the C-source symbols if there are any */
pc = pcprev;
- while(pc_cline ) {
+ while(pc && pc_cline ) {
pc = findNextInstruction(pc->next);
+ if (!pc) break;
PCI(pc)->cline = pc_cline;
pc_cline = PCCS(pc_cline->pc.next);
/* Copy C code comments to new code. */
pc = pcprev->next;
if (pc) {
- for (; pcout!=pcin; pcout=pcout->next) {
+ for (; pc && pcout!=pcin; pcout=pcout->next) {
if (pcout->type==PC_OPCODE && PCI(pcout)->cline) {
while (pc->type!=PC_OPCODE || PCI(pc)->cline) {
pc = pc->next;
if (!pc)
break;
}
+ if (!pc) break;
PCI(pc)->cline = PCI(pcout)->cline;
}
}