static void pCodePrintFunction(FILE *of, pCode *pc);
static void pCodeOpPrint(FILE *of, pCodeOp *pcop);
static char *get_op_from_instruction( pCodeInstruction *pcc);
-char *get_op( pCodeOp *pcop);
+char *get_op( pCodeOp *pcop,char *buff,int buf_size);
int pCodePeepMatchLine(pCodePeep *peepBlock, pCode *pcs, pCode *pcd);
int pCodePeepMatchRule(pCode *pc);
void pBlockStats(FILE *of, pBlock *pb);
len = strlen(*str);
if(len > *size) {
fprintf(stderr,"WARNING, it looks like %s has overflowed\n",__FUNCTION__);
+ fprintf(stderr,"len = %d is > str size %d\n",len,*size);
}
*str += len;
len = strlen(buffer);
if(len > *size) {
fprintf(stderr,"WARNING, it looks like %s has overflowed\n",__FUNCTION__);
+ fprintf(stderr,"len = %d is > str size %d\n",len,*size);
}
strcpy(*str, buffer);
/*-----------------------------------------------------------------*/
/*-----------------------------------------------------------------*/
-char *get_op(pCodeOp *pcop)
+char *get_op(pCodeOp *pcop,char *buffer, int size)
{
regs *r;
- static char buffer[50];
+ static char b[50];
char *s;
- int size;
+ // int size;
+ if(!buffer) {
+ buffer = b;
+ size = sizeof(b);
+ }
if(pcop) {
switch(pcop->type) {
// return PCOR(pcc->pcop)->r)->name;
case PO_IMMEDIATE:
s = buffer;
- size = sizeof(buffer);
+ //size = sizeof(buffer);
//fprintf(stderr,"PO_IMMEDIATE name = %s offset = %d\n",pcc->pcop->name,PCOI(pcc->pcop)->offset);
if(PCOI(pcop)->_const) {
case PO_DIR:
s = buffer;
- size = sizeof(buffer);
+ //size = sizeof(buffer);
if( PCOR(pcop)->instance) {
SAFE_snprintf(&s,&size,"(%s + %d)",
pcop->name,
{
if(pcc )
- return get_op(pcc->pcop);
+ return get_op(pcc->pcop,NULL,0);
return ("ERROR Null: "__FUNCTION__);
int getpCodePeepCommand(char *cmd);
void pBlockMergeLabels(pBlock *pb);
char *pCode2str(char *str, int size, pCode *pc);
-char *get_op( pCodeOp *pcop);
+char *get_op( pCodeOp *pcop,char *buf,int buf_size);
extern pCodeInstruction *pic14Mnemonics[];
return 0;
if(pc->type == PC_OPCODE) {
+ //fprintf(stderr," checking conditions of: ");
+ //pc->print(stderr,pc);
if(PCI(pc)->inCond & cond)
return 1;
if(PCI(pc)->outCond & cond)
*-----------------------------------------------------------------*/
int pCodeOpCompare(pCodeOp *pcops, pCodeOp *pcopd)
{
+ char b[50], *n2;
if(!pcops || !pcopd)
return 0;
- /*
+/*
fprintf(stderr," Comparing operands %s",
- get_op( pcops));
+ get_op( pcops,NULL,0));
fprintf(stderr," to %s\n",
- get_op( pcopd));
- */
+ get_op( pcopd,NULL,0));
+*/
if(pcops->type != pcopd->type) {
//fprintf(stderr," - fail - diff types\n");
return 0; // different types
}
- if(!pcops->name || !pcopd->name || strcmp(pcops->name,pcopd->name)) {
- //fprintf(stderr," - fail - diff names\n");
+ b[0]=0;
+ get_op(pcops,b,sizeof(b));
+ n2 = get_op(pcopd,NULL,0);
+
+ if( !n2 || strcmp(b,n2)) {
+ //fprintf(stderr," - fail - diff names: %s, len=%d, %s, len=%d\n",b,strlen(b), n2, strlen(n2) );
return 0; // different names
}
break;
}
- //fprintf(stderr," - pass\n");
+ // fprintf(stderr," - pass\n");
return 1;
}
pct = pct->next;
//debug:
//DFPRINTF((stderr," matched\n"));
+
if(!pcin && pct) {
DFPRINTF((stderr," partial match... no more code\n"));
+ fprintf(stderr," partial match... no more code\n");
matched = 0;
}
if(!pct) {
if(matched) {
+ //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.
if (pcin && peepBlock->postFalseCond &&
(pCodeSearchCondition(pcin,peepBlock->postFalseCond) > 0) )
matched = 0;
+
+ 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);