- return i;
- } else {
- DFPRINTF((stderr," (matched %s\n",PCI(pcs)->pcop->name));
- peepBlock->target.vars[index] = PCI(pcs)->pcop->name;
- return 1;
- }
- }
-
- pcs = findNextInstruction(pcs->next);
- if(pcs) {
- //DFPRINTF((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 */
- }
-
- return 0;
-}
-
-/*-----------------------------------------------------------------*/
-/*-----------------------------------------------------------------*/
-void pCodePeepClrVars(pCodePeep *pcp)
-{
-
- 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++)
- pcp->target.wildpCodeOps[i] = NULL;
- for(i=0;i<pcp->target.nwildpCodes; i++)
- pcp->target.wildpCodes[i] = NULL;
-
- for(i=0;i<pcp->replace.nvars; i++)
- pcp->replace.vars[i] = NULL;
- for(i=0;i<pcp->replace.nops; i++)
- pcp->replace.wildpCodeOps[i] = NULL;
- for(i=0;i<pcp->replace.nwildpCodes; i++)
- pcp->replace.wildpCodes[i] = NULL;
-
-
-
-}
-
-/*-----------------------------------------------------------------*/
-/* pCodeInsertAfter - splice in the pCode chain starting with pc2 */
-/* into the pCode chain containing pc1 */
-/*-----------------------------------------------------------------*/
-void pCodeInsertAfter(pCode *pc1, pCode *pc2)
-{
-
- if(!pc1 || !pc2)
- return;
-
- pc2->next = pc1->next;
- if(pc1->next)
- pc1->next->prev = pc2;
-
- pc2->pb = pc1->pb;
- pc2->prev = pc1;
- pc1->next = pc2;
-
-}
-
-/*-----------------------------------------------------------------*/
-/* pCodeOpCopy - copy a pcode operator */
-/*-----------------------------------------------------------------*/
-pCodeOp *pCodeOpCopy(pCodeOp *pcop)
-{
- pCodeOp *pcopnew=NULL;
-
- if(!pcop)
- return NULL;
-
- switch(pcop->type) {
- case PO_CRY:
- case PO_BIT:
- //DFPRINTF((stderr,"pCodeOpCopy bit\n"));
- pcopnew = Safe_calloc(1,sizeof(pCodeOpRegBit) );
- PCORB(pcopnew)->bit = PCORB(pcop)->bit;
- PCORB(pcopnew)->inBitSpace = PCORB(pcop)->inBitSpace;
-
- break;
-
- case PO_WILD:
- /* Here we expand the wild card into the appropriate type: */
- /* By recursively calling pCodeOpCopy */
- //DFPRINTF((stderr,"pCodeOpCopy wild\n"));
- if(PCOW(pcop)->matched)
- pcopnew = pCodeOpCopy(PCOW(pcop)->matched);
- else {
- // Probably a label
- pcopnew = pCodeOpCopy(PCOW(pcop)->subtype);
- pcopnew->name = Safe_strdup(PCOW(pcop)->pcwb->vars[PCOW(pcop)->id]);
- //DFPRINTF((stderr,"copied a wild op named %s\n",pcopnew->name));
- }
-
- return pcopnew;
- break;
-
- case PO_LABEL:
- //DFPRINTF((stderr,"pCodeOpCopy label\n"));
- pcopnew = Safe_calloc(1,sizeof(pCodeOpLabel) );
- PCOLAB(pcopnew)->key = PCOLAB(pcop)->key;
- break;
-
- case PO_IMMEDIATE:
- pcopnew = Safe_calloc(1,sizeof(pCodeOpImmd) );
- PCOI(pcopnew)->index = PCOI(pcop)->index;
- PCOI(pcopnew)->offset = PCOI(pcop)->offset;
- PCOI(pcopnew)->_const = PCOI(pcop)->_const;
- break;
-
- case PO_LITERAL:
- //DFPRINTF((stderr,"pCodeOpCopy lit\n"));
- pcopnew = Safe_calloc(1,sizeof(pCodeOpLit) );
- PCOL(pcopnew)->lit = PCOL(pcop)->lit;
- break;
-
- case PO_GPR_BIT:
-
- pcopnew = newpCodeOpBit(pcop->name, PCORB(pcop)->bit,PCORB(pcop)->inBitSpace);
- PCOR(pcopnew)->r = PCOR(pcop)->r;
- PCOR(pcopnew)->rIdx = PCOR(pcop)->rIdx;
- DFPRINTF((stderr," pCodeOpCopy Bit -register index\n"));
- return pcopnew;
- break;
-
- case PO_GPR_REGISTER:
- case PO_GPR_TEMP:
- case PO_FSR:
- case PO_INDF:
- //DFPRINTF((stderr,"pCodeOpCopy GPR register\n"));
- pcopnew = Safe_calloc(1,sizeof(pCodeOpReg) );
- PCOR(pcopnew)->r = PCOR(pcop)->r;
- PCOR(pcopnew)->rIdx = PCOR(pcop)->rIdx;
- PCOR(pcopnew)->instance = PCOR(pcop)->instance;
- DFPRINTF((stderr," register index %d\n", PCOR(pcop)->r->rIdx));
- break;
-
- case PO_DIR:
- //fprintf(stderr,"pCodeOpCopy PO_DIR\n");
- pcopnew = Safe_calloc(1,sizeof(pCodeOpReg) );
- PCOR(pcopnew)->r = PCOR(pcop)->r;
- PCOR(pcopnew)->rIdx = PCOR(pcop)->rIdx;
- PCOR(pcopnew)->instance = PCOR(pcop)->instance;
- break;
- case PO_STATUS:
- DFPRINTF((stderr,"pCodeOpCopy PO_STATUS\n"));
- case PO_SFR_REGISTER:
- case PO_STR:
- case PO_NONE:
- case PO_W:
- case PO_INTCON:
- case PO_PCL:
- case PO_PCLATH:
-
- //DFPRINTF((stderr,"pCodeOpCopy register type %d\n", pcop->type));
- pcopnew = Safe_calloc(1,sizeof(pCodeOp) );
-
- }
-
- pcopnew->type = pcop->type;
- if(pcop->name)
- pcopnew->name = Safe_strdup(pcop->name);
- else
- pcopnew->name = NULL;