}
if(pic14Mnemonics[opcode]->bit_inst)
- pcosubtype = newpCodeOpBit(NULL,-1);
+ pcosubtype = newpCodeOpBit(NULL,-1,0);
else
pcosubtype = newpCodeOp(NULL,PO_GPR_REGISTER);
pCodeOp *pcwb;
// Create a new wild operand subtyped as a bit
- pcwb = newpCodeOpWild(0,pcp,newpCodeOpBit(NULL,-1));
+ pcwb = newpCodeOpWild(0,pcp,newpCodeOpBit(NULL,-1,0));
// Create a
pb = newpCodeChain(NULL, 'W',newpCode(POC_BTFSC,pcwb));
/*-----------------------------------------------------------------*/
/* pCodePeepMatchLine - Compare source and destination pCodes to */
/* see they're the same. */
+/* */
+/* In this context, "source" refers to the coded generated by gen.c*/
+/* and "destination" refers to a pcode in a peep rule. If the dest-*/
+/* ination has no wild cards, then MatchLine will compare the two */
+/* pcodes (src and dest) for a one-to-one match. If the destination*/
+/* has wildcards, then those get expanded. When a wild card is */
+/* encountered for the first time it autmatically is considered a */
+/* match and the object that matches it is referenced in the */
+/* variables or opcodes array (depending on the type of match). */
+/* */
+/* */
+/* Inputs: */
+/* *peepBlock - A pointer to the peepBlock that contains the */
+/* entire rule to which the destination pcode belongs*/
+/* *pcs - a pointer to the source pcode */
+/* *pcd - a pointer to the destination pcode */
+/* */
+/* Returns: */
+/* 1 - pcodes match */
+/* 0 - pcodes don't match */
+/* */
+/* */
/*-----------------------------------------------------------------*/
+
int pCodePeepMatchLine(pCodePeep *peepBlock, pCode *pcs, pCode *pcd)
{
int index; // index into wild card arrays
if(peepBlock->vars[index])
return (strcmp(peepBlock->vars[index],n) == 0);
else {
+ fprintf(stderr,"first time for a variable: %d, %s\n",index,n);
peepBlock->vars[index] = n; //PCI(pcs)->pcop->name;
return 1;
}
}
}
+ /* FIXME - need an else to check the case when the destination
+ * isn't a wild card */
} else
/* The pcd has no operand. Lines match if pcs has no operand either*/
return (PCI(pcs)->pcop == NULL);
return 0;
pcl = pcd->label->pc;
-
- labindex = PCOW(pcl)->id;
+ //labindex = PCOW(pcl)->id;
+ labindex = -PCL(pcl)->key;
+ fprintf(stderr,"label id = %d (labindex = %d)\n",PCL(pcl)->key,labindex);
if(peepBlock->vars[labindex] == NULL) {
// First time to encounter this label
peepBlock->vars[labindex] = PCL(pcs->label->pc)->label;
- fprintf(stderr,"first time for a label\n");
+ fprintf(stderr,"first time for a label: %d %s\n",labindex, peepBlock->vars[labindex]);
} else {
if(strcmp(peepBlock->vars[labindex],PCL(pcs->label->pc)->label) != 0) {
fprintf(stderr,"labels don't match\n");
if(pcs) {
fprintf(stderr," (next to match)\n");
pcs->print(stderr,pcs);
+ } else if(pcd->next) {
+ /* oops, we ran out of code, but there's more to the rule */
+ return 0;
}
return 1; /* wild card matches */
case PO_GPR_REGISTER:
case PO_GPR_TEMP:
+ case PO_GPR_BIT:
fprintf(stderr,"pCodeOpCopy GPR register\n");
pcopnew = Safe_calloc(1,sizeof(pCodeOpReg) );
PCOR(pcopnew)->r = PCOR(pcop)->r;
case PO_STATUS:
case PO_FSR:
case PO_INDF:
+ case PO_PCL:
+ case PO_PCLATH:
fprintf(stderr,"pCodeOpCopy register type %d\n", pcop->type);
pcopnew = Safe_calloc(1,sizeof(pCodeOp) );
fprintf(stderr," end of rule\n");
}
- if(matched && pcin) {
+ if(matched) {
/* 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
* the `postFalseCond' as input then we abort the match
*/
fprintf(stderr," matched rule so far, now checking conditions\n");
- if (peepBlock->postFalseCond &&
+ if (pcin && peepBlock->postFalseCond &&
(pCodeSearchCondition(pcin,peepBlock->postFalseCond) > 0) )
matched = 0;
}
- if(matched && pcin) {
+ if(matched) {
pCode *pcprev;
pCode *pcr;
printpCodeString(stderr,peepBlock->target->pcHead,10);
fprintf(stderr,"first thing matched\n");
pc->print(stderr,pc);
- fprintf(stderr,"last thing matched\n");
- pcin->print(stderr,pcin);
+ if(pcin) {
+ fprintf(stderr,"last thing matched\n");
+ pcin->print(stderr,pcin);
+ }
/* Unlink the original code */
pcprev = pc->prev;
pcprev->next = pcin;
- pcin->prev = pc->prev;
+ if(pcin)
+ pcin->prev = pc->prev;
{
/* DEBUG */
}
}
- pCodeDeleteChain(pc,pcin);
+ if(pcin)
+ pCodeDeleteChain(pc,pcin);
/* Generate the replacement code */
pc = pcprev;
pc = pc->next;
- pc->print(stderr,pc);
+ if(pc)
+ pc->print(stderr,pc);
pcr = pcr->next;
}