static void tokenizeLineNode(char *ln)
{
-
+ char *lnstart=ln;
tokIdx = 0; // Starting off at the beginning
tokArr[0].tt = PCT_NULL; // and assume invalid character for first token.
if(!ln || !*ln)
return;
+
while(*ln) {
if(isspace(*ln)) {
tokArr[tokIdx].tok.s = Safe_strdup(buffer);
tokArr[tokIdx++].tt = PCT_STRING;
+ } else {
+ fprintf(stderr, "Error while parsing peep rules (check peeph.def)\n");
+ fprintf(stderr, "Line: %s\n",lnstart);
+ fprintf(stderr, "Token: '%c'\n",*ln);
+ exit(1);
}
}
state = PS_HAVE_COMMA;
} else
fprintf(stderr," unexpected comma\n");
+ break;
+
}
matching = 1;
peepRuleBlock2pCodeBlock(pr->match, ¤tRule->target);
//DFPRINTF((stderr,"finished target, here it is in pcode form:\n"));
- //printpBlock(stderr, curBlock);
+ //printpBlock(stderr, currentRule->target.pb);
//DFPRINTF((stderr,"target with labels merged:\n"));
//pBlockMergeLabels(curBlock);
/*-----------------------------------------------------------------*/
int pCodeSearchCondition(pCode *pc, unsigned int cond)
{
-
+ //fprintf(stderr,"Checking conditions %d\n",cond);
while(pc) {
/* If we reach a function end (presumably an end since we most
if(pc->type == PC_OPCODE) {
//fprintf(stderr," checking conditions of: ");
//pc->print(stderr,pc);
+ //fprintf(stderr,"\t\tinCond=%d\toutCond=%d\n",PCI(pc)->inCond,PCI(pc)->outCond);
if(PCI(pc)->inCond & cond)
return 1;
if(PCI(pc)->outCond & cond)
return 0; // different types
}
+ if(pcops->type == PO_LITERAL) {
+
+ if((PCOL(pcops)->lit >= 0) && (PCOL(pcops)->lit == PCOL(pcopd)->lit))
+ return 1;
+
+ return 0;
+ }
+
b[0]=0;
get_op(pcops,b,50);
if(PCI(pcd)->pcop) {
if (PCI(pcd)->pcop->type == PO_WILD) {
index = PCOW(PCI(pcd)->pcop)->id;
-
//DFPRINTF((stderr,"destination is wild\n"));
#ifdef DEBUG_PCODEPEEP
if (index > peepBlock->nops) {
}
}
+ } else if (PCI(pcd)->pcop->type == PO_LITERAL) {
+ return pCodeOpCompare(PCI(pcs)->pcop, PCI(pcd)->pcop);
+
}
/* FIXME - need an else to check the case when the destination
* isn't a wild card */
if((pcd->type == PC_WILD) && (pcs->type == PC_OPCODE)) {
-
index = PCW(pcd)->id;
#ifdef PCODE_DEBUG
DFPRINTF((stderr,"%s comparing wild cards\n",__FUNCTION__));
int i;
if(!pcp)
return;
-
+/*
DFPRINTF((stderr," Clearing peep rule vars\n"));
DFPRINTF((stderr," %d %d %d %d %d %d\n",
pcp->target.nvars,pcp->target.nops,pcp->target.nwildpCodes,
pcp->replace.nvars,pcp->replace.nops,pcp->replace.nwildpCodes));
-
+*/
for(i=0;i<pcp->target.nvars; i++)
pcp->target.vars[i] = NULL;
for(i=0;i<pcp->target.nops; i++)
}
}
- if(matched) {
+ if(matched && pcin) {
- //pCode *pcr = peepBlock->replace.pb->pcHead;
- //if(pcr) pcr->print(stderr,pcr);
-
/* So far we matched the rule up to the point of the conditions .
* In other words, all of the opcodes match. Now we need to see
* if the post conditions are satisfied.
* the `postFalseCond' as input then we abort the match
*/
DFPRINTF((stderr," matched rule so far, now checking conditions\n"));
+ //pcin->print(stderr,pcin);
+
if (pcin && peepBlock->postFalseCond &&
(pCodeSearchCondition(pcin,peepBlock->postFalseCond) > 0) )
matched = 0;
- if(!matched) fprintf(stderr,"failed on conditions\n");
+ //fprintf(stderr," condition results = %d\n",pCodeSearchCondition(pcin,peepBlock->postFalseCond));
+
+
+ //if(!matched) fprintf(stderr,"failed on conditions\n");
}
if(matched) {
pcin->prev = pc->prev;
-#if 0
+ //#if 0
{
/* DEBUG */
/* Converted the deleted pCodes into comments */
if(pc_cline2)
pc_cline2->pc.next = NULL;
}
-#endif
+ //#endif
if(pcin)
pCodeDeleteChain(pc,pcin);