{
int size, offset = 0 ;
unsigned long lit = 0L,i = 0;
- resolvedIfx rIfx;
-
+ resolvedIfx rFalseIfx;
+ // resolvedIfx rTrueIfx;
+ symbol *truelbl;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
if(ifx) {
DEBUGpic14_emitcode ("; ***","true ifx is %s",((IC_TRUE(ifx) == NULL) ? "false" : "true"));
DEBUGpic14_emitcode ("; ***","false ifx is %s",((IC_FALSE(ifx) == NULL) ? "false" : "true"));
}
- resolveIfx(&rIfx,ifx);
+ resolveIfx(&rFalseIfx,ifx);
+ truelbl = newiTempLabel(NULL);
+
+ //if(IC_TRUE(ifx) == NULL)
/* if left & right are bit variables */
if (AOP_TYPE(left) == AOP_CRY &&
AOP_TYPE(right) == AOP_CRY ) {
} else {
symbol *lbl = newiTempLabel(NULL);
- int emitFinalCheck=1;
- symbol *truelbl = newiTempLabel(NULL);
-
if(AOP_TYPE(right) == AOP_LIT) {
if(lit == 0) {
if(sign != 0)
- genSkipCond(&rIfx,left,size-1,7);
+ genSkipCond(&rFalseIfx,left,size-1,7);
else
/* no need to compare to 0...*/
/* NOTE: this is a de-generate compare that most certainly
* creates some dead code. */
- emitpcode(POC_GOTO,popGetLabel(rIfx.lbl->key));
+ emitpcode(POC_GOTO,popGetLabel(rFalseIfx.lbl->key));
if(ifx) ifx->generated = 1;
return;
/* lit is 0x7f, all signed chars are less than
* this except for 0x7f itself */
emitpcode(POC_XORLW, popGetLit(0x7f));
- genSkipz2(&rIfx);
+ genSkipz2(&rFalseIfx);
} else {
emitpcode(POC_ADDLW, popGetLit(0x80));
emitpcode(POC_ADDLW, popGetLit(i^0x80));
- genSkipc(&rIfx);
+ genSkipc(&rFalseIfx);
}
} else {
emitpcode(POC_ADDLW, popGetLit(i));
- genSkipc(&rIfx);
+ genSkipc(&rFalseIfx);
}
if(sign) {
if(lit == 0) {
- genSkipCond(&rIfx,left,size,7);
+ genSkipCond(&rFalseIfx,left,size,7);
if(ifx) ifx->generated = 1;
return;
}
if(lit <0x100) {
DEBUGpic14_emitcode(";right lit","line = %d signed compare to 0x%x",__LINE__,lit);
+ //rFalseIfx.condition ^= 1;
+ //genSkipCond(&rFalseIfx,left,size,7);
+ //rFalseIfx.condition ^= 1;
+
emitpcode(POC_BTFSC, newpCodeOpBit(aopGet(AOP(left),size,FALSE,FALSE),7,0));
- emitpcode(POC_GOTO, popGetLabel(truelbl->key));
+ if(rFalseIfx.condition)
+ emitpcode(POC_GOTO, popGetLabel(rFalseIfx.lbl->key));
+ else
+ emitpcode(POC_GOTO, popGetLabel(truelbl->key));
+
emitpcode(POC_MOVLW, popGetLit(0x100-lit));
emitpcode(POC_ADDFW, popGet(AOP(left),0));
emitpcode(POC_MOVFW, popGet(AOP(left),1));
while(size > 1)
emitpcode(POC_IORFW, popGet(AOP(left),size--));
- emitSKPNZ;
+ if(rFalseIfx.condition) {
+ emitSKPZ;
+ emitpcode(POC_GOTO, popGetLabel(truelbl->key));
- genSkipc(&rIfx);
+ } else {
+ emitSKPNZ;
+ }
+
+ genSkipc(&rFalseIfx);
emitpLabel(truelbl->key);
if(ifx) ifx->generated = 1;
return;
emitpcode(POC_MOVFW, popGet(AOP(left),size));
emitpcode(POC_ADDLW, popGetLit( 0x80));
emitpcode(POC_ADDLW, popGetLit(0x100-i));
- genSkipc(&rIfx);
+ genSkipc(&rFalseIfx);
if(ifx) ifx->generated = 1;
emitpcode(POC_MOVFW, popGet(AOP(left),size));
emitpcode(POC_ADDLW, popGetLit( 0x80));
emitpcode(POC_ADDLW, popGetLit(0x100-i));
- genSkipc(&rIfx);
-
-
- if(ifx) ifx->generated = 1;
- return;
-
- }
-
-#if 0
- if( lit < 0x10000) {
- /* upper word is zero */
- DEBUGpic14_emitcode(";right lit","line = %d signed compare to 0x%x",__LINE__,lit);
-
- emitpcode(POC_BTFSC, newpCodeOpBit(aopGet(AOP(left),size,FALSE,FALSE),7,0));
- emitpcode(POC_GOTO, popGetLabel(truelbl->key));
-
- emitpcode(POC_MOVLW, popGetLit((lit >> (1*8)) & 0xff));
- emitpcode(POC_SUBFW, popGet(AOP(left),1));
- emitpcode(POC_MOVLW, popGetLit((lit & 0xff));
- emitSKPNZ;
- emitpcode(POC_SUBFW, popGet(AOP(left),0));
-
- emitpcode(POC_IORFW, popGet(AOP(left),2));
- emitpcode(POC_IORFW, popGet(AOP(left),3));
+ genSkipc(&rFalseIfx);
- emitSKPNZ;
- genSkipc(&rIfx);
- emitpLabel(truelbl->key);
if(ifx) ifx->generated = 1;
return;
}
-#endif
}
/* lit is negative */
DEBUGpic14_emitcode(";right lit","line = %d signed compare to 0x%x",__LINE__,lit);
- genSkipCond(&rIfx,left,size,7);
+ //genSkipCond(&rFalseIfx,left,size,7);
+
+ emitpcode(POC_BTFSS, newpCodeOpBit(aopGet(AOP(left),size,FALSE,FALSE),7,0));
+
+ if(rFalseIfx.condition)
+ emitpcode(POC_GOTO, popGetLabel(truelbl->key));
+ else
+ emitpcode(POC_GOTO, popGetLabel(rFalseIfx.lbl->key));
+
+
} else {
/* lit is positive */
DEBUGpic14_emitcode(";right lit","line = %d signed compare to 0x%x",__LINE__,lit);
emitpcode(POC_BTFSC, newpCodeOpBit(aopGet(AOP(left),size,FALSE,FALSE),7,0));
- emitpcode(POC_GOTO, popGetLabel(truelbl->key));
+ if(rFalseIfx.condition)
+ emitpcode(POC_GOTO, popGetLabel(rFalseIfx.lbl->key));
+ else
+ emitpcode(POC_GOTO, popGetLabel(truelbl->key));
+ //emitpcode(POC_BTFSC, newpCodeOpBit(aopGet(AOP(left),size,FALSE,FALSE),7,0));
+ //emitpcode(POC_GOTO, popGetLabel(truelbl->key));
+ //rFalseIfx.condition ^= 1;
+ //genSkipCond(&rFalseIfx,left,size,7);
+ //rFalseIfx.condition ^= 1;
}
/*
emitpcode(POC_RLFW, popCopyReg(&pc_kzero));
emitpcode(POC_ADDLW, popGetLit( ((mlit>>8) & 0xff)));
emitpcode(POC_ADDFW, popGet(AOP(left),1));
- genSkipc(&rIfx);
+ genSkipc(&rFalseIfx);
emitpLabel(truelbl->key);
if(ifx) ifx->generated = 1;
emitSKPNZ;
emitpcode(POC_SUBFW, popGet(AOP(left),size));
}
-
- genSkipc(&rIfx);
+ //rFalseIfx.condition ^= 1;
+ genSkipc(&rFalseIfx);
emitpLabel(truelbl->key);
emitpLabel(lbl->key);
- if(emitFinalCheck)
- genSkipc(&rIfx);
+ //if(emitFinalCheck)
+ genSkipc(&rFalseIfx);
if(sign)
emitpLabel(truelbl->key);
if(AOP_TYPE(left) == AOP_LIT) {
//symbol *lbl = newiTempLabel(NULL);
- unsigned long mlit;
+
lit = (unsigned long)(floatFromVal(AOP(left)->aopu.aop_lit));
- mlit = -lit;
+
DEBUGpic14_emitcode(";left lit","lit = %d,sign=%d",lit,sign);
while(size)
emitpcode(POC_IORFW, popGet(AOP(right),--size));
- //rIfx.condition ^= 1;
- genSkipz2(&rIfx);
+ //rFalseIfx.condition ^= 1;
+ genSkipz2(&rFalseIfx);
if(ifx) ifx->generated = 1;
return;
}
lit &= 0xff;
if(((lit == 0xff) && !sign) || ((lit==0x7f) && sign)) {
/* degenerate compare can never be true */
- emitpcode(POC_GOTO,popGetLabel(rIfx.lbl->key));
+ if(rFalseIfx.condition == 0)
+ emitpcode(POC_GOTO,popGetLabel(rFalseIfx.lbl->key));
+
if(ifx) ifx->generated = 1;
return;
}
emitpcode(POC_MOVFW, popGet(AOP(right),0));
emitpcode(POC_ADDLW, popGetLit(0x80));
emitpcode(POC_ADDLW, popGetLit(((-(lit+1)) & 0xff) ^ 0x80));
- rIfx.condition ^= 1;
- genSkipc(&rIfx);
+ rFalseIfx.condition ^= 1;
+ genSkipc(&rFalseIfx);
} else {
- rIfx.condition ^= 1;
- genSkipCond(&rIfx,right,0,7);
+ rFalseIfx.condition ^= 1;
+ genSkipCond(&rFalseIfx,right,0,7);
}
} else {
emitpcode(POC_MOVLW, popGetLit((lit+1) & 0xff));
emitpcode(POC_SUBFW, popGet(AOP(right),0));
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- rIfx.condition ^= 1;
- genSkipc(&rIfx);
+ rFalseIfx.condition ^= 1;
+ genSkipc(&rFalseIfx);
} else {
emitpcode(POC_MOVFW, popGet(AOP(right),0));
- genSkipz2(&rIfx);
+ genSkipz2(&rFalseIfx);
}
}
DEBUGpic14_emitcode(";left lit = -1","line = %d ",__LINE__);
- rIfx.condition ^= 1;
- genSkipCond(&rIfx,right,size,7);
+ rFalseIfx.condition ^= 1;
+ genSkipCond(&rFalseIfx,right,size,7);
if(ifx) ifx->generated = 1;
return;
}
if(lit == 0) {
int s = size;
+
+ if(rFalseIfx.condition) {
+ emitpcode(POC_BTFSC, newpCodeOpBit(aopGet(AOP(right),size,FALSE,FALSE),7,0));
+ emitpcode(POC_GOTO, popGetLabel(truelbl->key));
+ }
+
emitpcode(POC_MOVFW, popGet(AOP(right),size));
while(size--)
emitpcode(POC_IORFW, popGet(AOP(right),size));
+
emitSKPZ;
- rIfx.condition ^= 1;
- genSkipCond(&rIfx,right,s,7);
+ if(rFalseIfx.condition) {
+ emitpcode(POC_GOTO, popGetLabel(rFalseIfx.lbl->key));
+ emitpLabel(truelbl->key);
+ }else {
+ rFalseIfx.condition ^= 1;
+ genSkipCond(&rFalseIfx,right,s,7);
+ }
+
if(ifx) ifx->generated = 1;
return;
}
if(lit & (0x80 << (size*8))) {
/* Lit is less than zero */
DEBUGpic14_emitcode(";left lit","line = %d 0x%x is less than 0",__LINE__,lit);
+ //rFalseIfx.condition ^= 1;
+ //genSkipCond(&rFalseIfx,left,size,7);
+ //rFalseIfx.condition ^= 1;
emitpcode(POC_BTFSS, newpCodeOpBit(aopGet(AOP(right),size,FALSE,FALSE),7,0));
- emitpcode(POC_GOTO, popGetLabel(truelbl->key));
+ //emitpcode(POC_GOTO, popGetLabel(truelbl->key));
+
+ if(rFalseIfx.condition)
+ emitpcode(POC_GOTO, popGetLabel(rFalseIfx.lbl->key));
+ else
+ emitpcode(POC_GOTO, popGetLabel(truelbl->key));
+
} else {
/* Lit is greater than or equal to zero */
DEBUGpic14_emitcode(";left lit","line = %d 0x%x is greater than 0",__LINE__,lit);
- rIfx.condition ^= 1;
- genSkipCond(&rIfx,right,size,7);
- rIfx.condition ^= 1;
+ //rFalseIfx.condition ^= 1;
+ //genSkipCond(&rFalseIfx,right,size,7);
+ //rFalseIfx.condition ^= 1;
+
+ //emitpcode(POC_BTFSC, newpCodeOpBit(aopGet(AOP(right),size,FALSE,FALSE),7,0));
+ //emitpcode(POC_GOTO, popGetLabel(rFalseIfx.lbl->key));
+
+ emitpcode(POC_BTFSC, newpCodeOpBit(aopGet(AOP(right),size,FALSE,FALSE),7,0));
+ if(rFalseIfx.condition)
+ emitpcode(POC_GOTO, popGetLabel(truelbl->key));
+ else
+ emitpcode(POC_GOTO, popGetLabel(rFalseIfx.lbl->key));
}
emitpcode(POC_MOVLW, popGetLit((lp1 >> (size*8)) & 0xff));
emitSKPNZ;
emitpcode(POC_SUBFW, popGet(AOP(right),size));
}
- rIfx.condition ^= 1;
- genSkipc(&rIfx);
+ rFalseIfx.condition ^= 1;
+ //rFalseIfx.condition = 1;
+ genSkipc(&rFalseIfx);
emitpLabel(truelbl->key);
emitpLabel(lbl->key);
- rIfx.condition ^= 1;
- genSkipc(&rIfx);
+ rFalseIfx.condition ^= 1;
+ genSkipc(&rFalseIfx);
}
if(sign)
emitpcode(POC_ADDLW, popGetLit(0x80));
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- genSkipc(&rIfx);
+ genSkipc(&rFalseIfx);
if(ifx) ifx->generated = 1;
return;
emitpLabel(lbl->key);
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- genSkipc(&rIfx);
+ genSkipc(&rFalseIfx);
if(ifx) ifx->generated = 1;
return;
memcpy(r,PCOR(PCI(pc)->pcop)->r, sizeof(regs));
addSet(&pb->registers, r);
PCOR(PCI(pc)->pcop)->r = r;
- fprintf(stderr,"added register to pblock: reg %d\n",r->rIdx);
- } else
+ //fprintf(stderr,"added register to pblock: reg %d\n",r->rIdx);
+ }/* else
fprintf(stderr,"found register in pblock: reg %d\n",r->rIdx);
+ */
}
if(PCI(pc)->pcop->type == PO_GPR_REGISTER) {
if(PCOR(PCI(pc)->pcop)->r) {
fprintf(stderr," Optimizing pBlock: %c\n",getpBlock_dbName(pb));
for(pc = pb->pcHead; pc; pc = pc->next)
matches += pCodePeepMatchRule(pc);
-
+ if(matches)
+ fprintf(stderr," Optimizing pBlock: %c - matches=%d\n",getpBlock_dbName(pb),matches);
return matches;
}
for(pc = pb->pcHead; pc; pc = pc->next) {
if(pc->type == PC_LABEL) {
- fprintf(stderr,"Checking label key = %d\n",PCL(pc)->key);
+ //fprintf(stderr,"Checking label key = %d\n",PCL(pc)->key);
if( !(pcnext = findNextInstruction(pc)) )
return; // Couldn't find an instruction associated with this label
// Unlink the pCode label from it's pCode chain
unlinkPC(pc);
- fprintf(stderr,"Merged label key = %d\n",PCL(pc)->key);
+ //fprintf(stderr,"Merged label key = %d\n",PCL(pc)->key);
// And link it into the instruction's pBranch labels. (Note, since
// it's possible to have multiple labels associated with one instruction
// we must provide a means to accomodate the additional labels. Thus
if(!the_pFile)
return;
- fprintf(stderr," Analyzing pCode");
- changes = 0;
i = 0;
do {
+
+ fprintf(stderr," Analyzing pCode: PASS #%d\n",i+1);
+
/* First, merge the labels with the instructions */
for(pb = the_pFile->pbHead; pb; pb = pb->next) {
if('*' == dbName || getpBlock_dbName(pb) == dbName) {
}
}
+ changes = 0;
+
for(pb = the_pFile->pbHead; pb; pb = pb->next) {
if('*' == dbName || getpBlock_dbName(pb) == dbName)
changes += OptimizepBlock(pb);
if( altArr[k].f) {
pc = altArr[k].f(&parsedPatArr[j]);
- if(pc && pc->print)
- pc->print(stderr,pc);
+ //if(pc && pc->print)
+ // pc->print(stderr,pc);
//if(pc && pc->destruct) pc->destruct(pc); dumps core?
if(curBlock && pc)
addpCode2pBlock(curBlock, pc);
for( ; ln; ln = ln->next) {
- fprintf(stderr,"%s\n",ln->line);
+ //fprintf(stderr,"%s\n",ln->line);
tokenizeLineNode(ln->line);
parseTokens();
if(!cond)
return;
- fprintf(stderr,"\nCondition: %s\n",cond);
+ //fprintf(stderr,"\nCondition: %s\n",cond);
/* brute force compares for now */
if(STRCASECMP(cond, "NZ") == 0) {
- fprintf(stderr,"found NZ\n");
+ //fprintf(stderr,"found NZ\n");
curPeep->postFalseCond = PCC_Z;
}
for (pr = rules; pr; pr = pr->next) {
- fprintf(stderr,"\nRule:\n\n");
+ //fprintf(stderr,"\nRule:\n\n");
pcps = Safe_calloc(1,sizeof(pCodePeepSnippets));
curPeep = pcps->peep = Safe_calloc(1,sizeof(pCodePeep));
/* Convert the target block */
peepRuleBlock2pCodeBlock(pr->match);
- fprintf(stderr,"finished target, here it is in pcode form:\n");
- printpBlock(stderr, curBlock);
+ //fprintf(stderr,"finished target, here it is in pcode form:\n");
+ //printpBlock(stderr, curBlock);
- fprintf(stderr,"target with labels merged:\n");
+ //fprintf(stderr,"target with labels merged:\n");
pBlockMergeLabels(curBlock);
printpBlock(stderr, curBlock);
- fprintf(stderr,"\nReplaced by:\n");
+ //fprintf(stderr,"\nReplaced by:\n");
curPeep->replace = curBlock = newpCodeChain(NULL, 'W', NULL);
/* Convert the replace block */
peepRuleBlock2pCodeBlock(pr->replace);
- fprintf(stderr,"finished replace block, here it is in pcode form:\n");
- printpBlock(stderr, curBlock);
+ //fprintf(stderr,"finished replace block, here it is in pcode form:\n");
+ //printpBlock(stderr, curBlock);
- fprintf(stderr,"replace with labels merged:\n");
+ //fprintf(stderr,"replace with labels merged:\n");
pBlockMergeLabels(curBlock);
- printpBlock(stderr, curBlock);
+ //printpBlock(stderr, curBlock);
peepRuleCondition(pr->cond);
return 0;
pcl = pcd->label->pc;
- //labindex = PCOW(pcl)->id;
+
labindex = -PCL(pcl)->key;
- fprintf(stderr,"label id = %d (labindex = %d)\n",PCL(pcl)->key,labindex);
+ //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: %d %s\n",labindex, peepBlock->vars[labindex]);
+ //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");
+ // fprintf(stderr,"labels don't match\n");
return 0;
}
- fprintf(stderr,"matched a label\n");
+ //fprintf(stderr,"matched a label\n");
}
} else {
- fprintf(stderr,"destination doesn't have a label\n");
+ // fprintf(stderr,"destination doesn't have a label\n");
if(pcs->label)
return 0;
if(PCI(pcs)->op != PCI(pcd)->op)
return 0;
+ /*
fprintf(stderr,"%s comparing\n",__FUNCTION__);
pcs->print(stderr,pcs);
pcd->print(stderr,pcd);
+ */
if(!pCodePeepMatchLabels(peepBlock, pcs, pcd))
return 0;
if (PCI(pcd)->pcop->type == PO_WILD) {
index = PCOW(PCI(pcd)->pcop)->id;
- fprintf(stderr,"destination is wild\n");
+ //fprintf(stderr,"destination is wild\n");
#ifdef DEBUG_PCODEPEEP
if (index > peepBlock->nops) {
fprintf(stderr,"%s - variables exceeded\n",__FUNCTION__);
{
char *n;
- fprintf(stderr,"line %d\n",__LINE__);
switch(PCI(pcs)->pcop->type) {
case PO_GPR_TEMP:
case PO_FSR:
break;
default:
- fprintf(stderr,"line %d\n",__LINE__);
n = PCI(pcs)->pcop->name;
}
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;
+ // fprintf(stderr,"first time for a variable: %d, %s\n",index,n);
+ peepBlock->vars[index] = n;
return 1;
}
}
index = PCW(pcd)->id;
- fprintf(stderr,"%s comparing wild cards\n",__FUNCTION__);
- pcs->print(stderr,pcs);
- pcd->print(stderr,pcd);
+ // fprintf(stderr,"%s comparing wild cards\n",__FUNCTION__);
+ //pcs->print(stderr,pcs);
+ //pcd->print(stderr,pcd);
peepBlock->wildpCodes[PCW(pcd)->id] = pcs;
PCOW(PCI(pcd)->pcop)->matched = PCI(pcs)->pcop;
if(peepBlock->vars[index]) {
int i = (strcmp(peepBlock->vars[index],PCI(pcs)->pcop->name) == 0);
+ /*
if(i)
fprintf(stderr," (matched)\n");
else {
peepBlock->vars[index],
PCI(pcs)->pcop->name);
}
+ */
return i;
} else {
peepBlock->vars[index] = PCI(pcs)->pcop->name;
pcs = findNextInstruction(pcs->next);
if(pcs) {
- fprintf(stderr," (next to match)\n");
- pcs->print(stderr,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;
switch(pcop->type) {
case PO_CRY:
case PO_BIT:
- fprintf(stderr,"pCodeOpCopy bit\n");
+ //fprintf(stderr,"pCodeOpCopy bit\n");
pcopnew = Safe_calloc(1,sizeof(pCodeOpBit) );
PCOB(pcopnew)->bit = PCOB(pcop)->bit;
PCOB(pcopnew)->inBitSpace = PCOB(pcop)->inBitSpace;
case PO_WILD:
/* Here we expand the wild card into the appropriate type: */
/* By recursively calling pCodeOpCopy */
- fprintf(stderr,"pCodeOpCopy wild\n");
+ //fprintf(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)->pcp->vars[PCOW(pcop)->id]);
- fprintf(stderr,"copied a wild op named %s\n",pcopnew->name);
+ //fprintf(stderr,"copied a wild op named %s\n",pcopnew->name);
}
return pcopnew;
break;
case PO_LABEL:
- fprintf(stderr,"pCodeOpCopy label\n");
+ //fprintf(stderr,"pCodeOpCopy label\n");
pcopnew = Safe_calloc(1,sizeof(pCodeOpLabel) );
PCOLAB(pcopnew)->key = PCOLAB(pcop)->key;
break;
case PO_LITERAL:
case PO_IMMEDIATE:
- fprintf(stderr,"pCodeOpCopy lit\n");
+ //fprintf(stderr,"pCodeOpCopy lit\n");
pcopnew = Safe_calloc(1,sizeof(pCodeOpLit) );
PCOL(pcopnew)->lit = PCOL(pcop)->lit;
break;
case PO_GPR_BIT:
case PO_FSR:
case PO_INDF:
- fprintf(stderr,"pCodeOpCopy GPR register\n");
+ //fprintf(stderr,"pCodeOpCopy GPR register\n");
pcopnew = Safe_calloc(1,sizeof(pCodeOpReg) );
PCOR(pcopnew)->r = PCOR(pcop)->r;
PCOR(pcopnew)->rIdx = PCOR(pcop)->rIdx;
break;
case PO_DIR:
- fprintf(stderr,"pCodeOpCopy PO_DIR\n");
+ //fprintf(stderr,"pCodeOpCopy PO_DIR\n");
case PO_SFR_REGISTER:
case PO_STR:
case PO_NONE:
case PO_PCL:
case PO_PCLATH:
- fprintf(stderr,"pCodeOpCopy register type %d\n", pcop->type);
+ //fprintf(stderr,"pCodeOpCopy register type %d\n", pcop->type);
pcopnew = Safe_calloc(1,sizeof(pCodeOp) );
}
pcin = findNextInstruction(pcin->next);
pct = pct->next;
//debug:
- fprintf(stderr," matched\n");
+ //fprintf(stderr," matched\n");
if(!pcin)
fprintf(stderr," end of code\n");
if(!pct)
* Is it wild? */
if(PCI(pcr)->pcop->type == PO_WILD) {
int index = PCOW(PCI(pcr)->pcop)->id;
- fprintf(stderr,"copying wildopcode\n");
+ //fprintf(stderr,"copying wildopcode\n");
if(peepBlock->wildpCodeOps[index])
pcop = pCodeOpCopy(peepBlock->wildpCodeOps[index]);
else
} else
pcop = pCodeOpCopy(PCI(pcr)->pcop);
}
- fprintf(stderr,"inserting pCode\n");
+ //fprintf(stderr,"inserting pCode\n");
pCodeInsertAfter(pc, newpCode(PCI(pcr)->op,pcop));
} else if (pcr->type == PC_WILD) {
pCodeInsertAfter(pc,peepBlock->wildpCodes[PCW(pcr)->id]);
pc = pc->next;
- if(pc)
- pc->print(stderr,pc);
+ //if(pc)
+ // pc->print(stderr,pc);
pcr = pcr->next;
}
return 0;
}
-
-
-
-
-
-
-
-
-
-
-#if 0
-/*******************/
-pCode *parseLineNode(char *ln)
-{
- char buffer[50], *s;
- int state=0; //0 label, 1 mnemonic, 2 operand, 3 operand, 4 comment
- int var;
- pCode *pc = NULL;
- // pCodeLabel *pcl = NULL;
-
- if(!ln || !*ln)
- return pc;
-
- s = buffer;
- *s = 0;
-
- while(*ln) {
-
- /* skip white space */
- while (isspace (*ln))
- ln++;
-
- switch(state) {
-
- case 0: // look for a label
- case 1: // look for mnemonic
-
- if(*ln == '%') {
-
- // Wild
-
- ln++;
- if(!isdigit(*ln) )
- break;
- //goto next_state;
-
- var = strtol(ln, &ln, 10);
- if(*ln == ':') {
- // valid wild card label
- fprintf(stderr, " wildcard label: %d\n",var);
- ln++;
- } else
- fprintf(stderr, " wild opcode: %d\n",var), state++;
-
- } else {
- // not wild
- // Extract the label/mnemonic from the line
-
- s = buffer;
- while(*ln && !(isspace(*ln) || *ln == ':'))
- *s++ = *ln++;
-
- *s = 0;
- if(*ln == ':')
- fprintf(stderr," regular label: %s\n",buffer), ln++;
- else
- fprintf(stderr," regular mnem: %s\n",buffer), state++;
- }
- state++;
- break;
-
- default:
- ln++;
-
- }
- }
-
- return pc;
-
-}
-#endif
%2: %4
}
+replace restart {
+ btfss %1
+ goto %4
+%2: %3
+%4: %5
+} by {
+ ;peep 1b - test/jump to test/skip
+ btfsc %1
+%2: %3
+%4: %5
+}
+
+replace restart {
+ btfsc %1
+ goto %4
+%2: %3
+%4: %5
+} by {
+ ;peep 1c - test/jump to test/skip
+ btfss %1
+%2: %3
+%4: %5
+}
+
//bogus test for pcode
//replace restart {
--- /dev/null
+// Signed comparisons of the form: (variable>=LIT)
+//
+// This regression test exercises all of the boundary
+// conditions in literal less than comparisons. There
+// are numerous opportunities to optimize these comparison
+// and each one has an astonishing capability of failing
+// a boundary condition.
+
+unsigned char success = 0;
+unsigned char failures = 0;
+unsigned char dummy = 0;
+unsigned char result = 0;
+
+//bit bit0 = 0;
+int int0 = 0;
+int int1 = 0;
+unsigned char uchar0 = 0;
+unsigned char uchar1 = 0;
+signed char char0 = 0;
+signed char char1 = 0;
+char long0 = 0;
+char long1 = 0;
+
+void
+done ()
+{
+ dummy++;
+}
+
+
+void c_char_gte_lit1(unsigned char expected_result)
+{
+ result = 0;
+
+ if(char0 >= -0x7f)
+ result |= 1;
+
+
+ if(char0 >= -1)
+ result |= 2;
+
+ if(char0 >= 0)
+ result |= 4;
+
+ if(char0 >= 1)
+ result |= 8;
+
+ if(char0 >= 0x7e)
+ result |= 0x10;
+
+ if(char0 >= 0x7f)
+ result |= 0x20;
+
+ if(result != expected_result)
+ failures++;
+}
+
+
+void char_compare(void)
+{
+ char0 = 0x7f;
+ c_char_gte_lit1(0x3f);
+
+ char0 = 0x7e;
+ c_char_gte_lit1(0x1f);
+
+ char0 = 0x40;
+ c_char_gte_lit1(0x0f);
+
+ char0 = 0x2;
+ c_char_gte_lit1(0x0f);
+
+ char0 = 0x1;
+ c_char_gte_lit1(0x0f);
+
+ char0 = 0;
+ c_char_gte_lit1(0x07);
+
+ char0 = -1;
+ c_char_gte_lit1(0x03);
+
+ char0 = -2;
+ c_char_gte_lit1(0x01);
+
+ char0 = -0x40;
+ c_char_gte_lit1(0x01);
+
+ char0 = -0x7e;
+ c_char_gte_lit1(0x01);
+
+ char0 = -0x7f;
+ c_char_gte_lit1(0x01);
+
+ char0 = 0x80;
+ c_char_gte_lit1(0x00);
+
+
+ /* Now test entire range */
+
+ for(char0=1; char0 != 0x7e; char0++)
+ c_char_gte_lit1(0x0f);
+
+ for(char0=-0x7f; char0 != -1; char0++)
+ c_char_gte_lit1(0x01);
+
+}
+
+
+void c_int_gte_lit1(unsigned char expected_result)
+{
+ result = 0;
+
+ if(int0 >= 0)
+ result |= 1;
+
+ if(int0 >= 1)
+ result |= 2;
+
+
+ if(int0 >= 0xff)
+ result |= 4;
+
+ if(int0 >= 0x100)
+ result |= 8;
+
+ if(int0 >= 0x0101)
+ result |= 0x10;
+
+ if(int0 >= 0x01ff)
+ result |= 0x20;
+
+ if(int0 >= 0x0200)
+ result |= 0x40;
+
+ if(int0 >= 0x0201)
+ result |= 0x80;
+
+ if(result != expected_result)
+ failures=1;
+
+}
+
+
+void int_compare1(void)
+{
+ int0 = -1;
+ c_int_gte_lit1(0x00);
+
+ int0 = 0;
+ c_int_gte_lit1(0x01);
+
+ int0 = 1;
+ c_int_gte_lit1(0x03);
+
+ int0 = 2;
+ c_int_gte_lit1(0x03);
+
+ int0 = 0xfe;
+ c_int_gte_lit1(0x03);
+
+ int0 = 0xff;
+ c_int_gte_lit1(0x07);
+
+ int0 = 0x100;
+ c_int_gte_lit1(0x0f);
+
+ int0 = 0x101;
+ c_int_gte_lit1(0x1f);
+
+ int0 = 0x102;
+ c_int_gte_lit1(0x1f);
+
+ int0 = 0x1fe;
+ c_int_gte_lit1(0x1f);
+
+ int0 = 0x1ff;
+ c_int_gte_lit1(0x3f);
+
+ int0 = 0x200;
+ c_int_gte_lit1(0x7f);
+
+ int0 = 0x201;
+ c_int_gte_lit1(0xff);
+
+ int0 = 0x7f00;
+ c_int_gte_lit1(0xff);
+
+ /* now check contiguous ranges */
+
+ for(int0 = -0x7fff; int0 != -1; int0++)
+ c_int_gte_lit1(0x00);
+
+ for(int0 = 1; int0 != 0xff; int0++)
+ c_int_gte_lit1(0x03);
+
+ for(int0 = 0x201; int0 != 0x7fff; int0++)
+ c_int_gte_lit1(0xff);
+
+}
+
+
+void c_int_gte_lit2(unsigned char expected_result)
+{
+ result = 0;
+
+ if(int0 >= -0x7fff)
+ result |= 1;
+
+ if(int0 >= -0x7f00)
+ result |= 2;
+
+ if(int0 >= -0x7eff)
+ result |= 4;
+
+ if(int0 >= -0x7e00)
+ result |= 8;
+
+ if(int0 >= -0x0101)
+ result |= 0x10;
+
+ if(int0 >= -0x0100)
+ result |= 0x20;
+
+ if(int0 >= -0xff)
+ result |= 0x40;
+
+ if(int0 >= -1)
+ result |= 0x80;
+
+ if(result != expected_result)
+ failures=1;
+}
+
+void int_compare2(void)
+{
+ int0 = -0x7fff;
+ c_int_gte_lit2(0x01);
+
+ int0 = -0x7f00;
+ c_int_gte_lit2(0x03);
+
+ int0 = -0x7eff;
+ c_int_gte_lit2(0x07);
+
+ int0 = -0x7e00;
+ c_int_gte_lit2(0x0f);
+
+ int0 = -0x7dff;
+ c_int_gte_lit2(0x0f);
+
+ int0 = -0x4567;
+ c_int_gte_lit2(0x0f);
+
+ int0 = -0x200;
+ c_int_gte_lit2(0x0f);
+
+ int0 = -0x102;
+ c_int_gte_lit2(0x0f);
+
+ int0 = -0x101;
+ c_int_gte_lit2(0x1f);
+
+ int0 = -0x100;
+ c_int_gte_lit2(0x3f);
+
+ int0 = -0xff;
+ c_int_gte_lit2(0x7f);
+
+ int0 = -0x02;
+ c_int_gte_lit2(0x7f);
+
+ int0 = -0x01;
+ c_int_gte_lit2(0xff);
+
+ int0 = 0;
+ c_int_gte_lit2(0xff);
+
+ int0 = 1;
+ c_int_gte_lit2(0xff);
+
+ int0 = 0x7fff;
+ c_int_gte_lit2(0xff);
+
+ /* now check contiguous ranges */
+
+ for(int0 = -0x7fff; int0 != -0x7f00; int0++)
+ c_int_gte_lit2(0x01);
+
+ for(int0 = -0x7e00; int0 != -0x101; int0++)
+ c_int_gte_lit2(0x0f);
+
+ for(int0 = -1; int0 != 0x7fff; int0++)
+ c_int_gte_lit2(0xff);
+
+}
+
+
+
+
+void
+main (void)
+{
+ char_compare();
+ int_compare1();
+ int_compare2();
+
+ success = failures;
+ done ();
+}
unsigned char result = 0;
//bit bit0 = 0;
-long int0 = 0;
-long int1 = 0;
+int int0 = 0;
+int int1 = 0;
signed char char0 = 0;
signed char char1 = 0;
char long0 = 0;
unsigned char result = 0;
//bit bit0 = 0;
-long int0 = 0;
-long int1 = 0;
+int int0 = 0;
+int int1 = 0;
unsigned char uchar0 = 0;
unsigned char uchar1 = 0;
signed char char0 = 0;
--- /dev/null
+// Signed comparisons of the form: (variable<=LIT)
+//
+// This regression test exercises all of the boundary
+// conditions in literal less than or equal comparisons. There
+// are numerous opportunities to optimize these comparison
+// and each one has an astonishing capability of failing
+// a boundary condition.
+
+unsigned char success = 0;
+unsigned char failures = 0;
+unsigned char dummy = 0;
+unsigned char result = 0;
+
+int int0 = 0;
+int int1 = 0;
+signed char char0 = 0;
+signed char char1 = 0;
+
+void
+done ()
+{
+ dummy++;
+}
+
+
+void c_char_lte_lit1(unsigned char expected_result)
+{
+ result = 0;
+
+ if(char0 <= -0x7f)
+ result |= 1;
+
+ if(char0 <= -1)
+ result |= 2;
+
+ if(char0 <= 0)
+ result |= 4;
+
+ if(char0 <= 1)
+ result |= 8;
+
+ if(char0 <= 0x7f)
+ result |= 0x10;
+
+ if(result != expected_result)
+ failures++;
+}
+
+
+void char_compare(void)
+{
+ char0 = 0x7f;
+ c_char_lte_lit1(0x10);
+
+ char0 = 0x7e;
+ c_char_lte_lit1(0x10);
+
+ char0 = 0x40;
+ c_char_lte_lit1(0x10);
+
+ char0 = 0x2;
+ c_char_lte_lit1(0x10);
+
+ char0 = 0x1;
+ c_char_lte_lit1(0x18);
+
+ char0 = 0;
+ c_char_lte_lit1(0x1c);
+
+ char0 = -1;
+ c_char_lte_lit1(0x1e);
+
+ char0 = -2;
+ c_char_lte_lit1(0x1e);
+
+ char0 = -0x40;
+ c_char_lte_lit1(0x1e);
+
+ char0 = -0x7e;
+ c_char_lte_lit1(0x1e);
+
+ char0 = -0x7f;
+ c_char_lte_lit1(0x1f);
+
+ char0 = 0x80;
+ // c_char_lte_lit1(0x1f);
+
+
+ /* Now test entire range */
+
+ for(char0=2; char0 != 0x7f; char0++)
+ c_char_lte_lit1(0x10);
+
+
+ for(char0=-0x7e; char0 != 0; char0++)
+ c_char_lte_lit1(0x1e);
+
+
+}
+
+void c_int_lte_lit1(unsigned char expected_result)
+{
+ result = 0;
+
+ if(int0 <= 0)
+ result |= 1;
+
+ if(int0 <= 1)
+ result |= 2;
+
+
+ if(int0 <= 0xff)
+ result |= 4;
+
+ if(int0 <= 0x100)
+ result |= 8;
+
+ if(int0 <= 0x0101)
+ result |= 0x10;
+
+ if(int0 <= 0x01ff)
+ result |= 0x20;
+
+ if(int0 <= 0x0200)
+ result |= 0x40;
+
+ if(int0 <= 0x0201)
+ result |= 0x80;
+
+ if(result != expected_result)
+ failures=1;
+
+}
+
+
+void int_compare1(void)
+{
+ int0 = -1;
+ c_int_lte_lit1(0xff);
+
+ int0 = 0;
+ c_int_lte_lit1(0xff);
+
+ int0 = 1;
+ c_int_lte_lit1(0xfe);
+
+ int0 = 2;
+ c_int_lte_lit1(0xfc);
+
+ int0 = 0xfe;
+ c_int_lte_lit1(0xfc);
+
+ int0 = 0xff;
+ c_int_lte_lit1(0xfc);
+
+ int0 = 0x100;
+ c_int_lte_lit1(0xf8);
+
+ int0 = 0x101;
+ c_int_lte_lit1(0xf0);
+
+ int0 = 0x1fe;
+ c_int_lte_lit1(0xe0);
+
+ int0 = 0x1ff;
+ c_int_lte_lit1(0xe0);
+
+ int0 = 0x200;
+ c_int_lte_lit1(0xc0);
+
+ int0 = 0x201;
+ c_int_lte_lit1(0x80);
+
+ int0 = 0x7f00;
+ c_int_lte_lit1(0x0);
+
+ /* now check contiguous ranges */
+
+ for(int0 = -0x7fff; int0 != 1; int0++)
+ c_int_lte_lit1(0xff);
+
+ for(int0 = 2; int0 != 0xff; int0++)
+ c_int_lte_lit1(0xfc);
+
+ for(int0 = 0x202; int0 != 0x7fff; int0++)
+ c_int_lte_lit1(0);
+
+}
+
+
+
+void c_int_lte_lit2(unsigned char expected_result)
+{
+ result = 0;
+
+ if(int0 <= -0x7fff)
+ result |= 1;
+
+ if(int0 <= -0x7f00)
+ result |= 2;
+
+ if(int0 <= -0x7eff)
+ result |= 4;
+
+ if(int0 <= -0x7e00)
+ result |= 8;
+
+ if(int0 <= -0x0101)
+ result |= 0x10;
+
+ if(int0 <= -0x0100)
+ result |= 0x20;
+
+ if(int0 <= -0xff)
+ result |= 0x40;
+
+ if(int0 <= -1)
+ result |= 0x80;
+
+ if(result != expected_result)
+ failures=1;
+}
+
+void int_compare2(void)
+{
+ int0 = -0x7fff;
+ c_int_lte_lit2(0xff);
+
+ int0 = -0x7f00;
+ c_int_lte_lit2(0xfe);
+
+ int0 = -0x7eff;
+ c_int_lte_lit2(0xfc);
+
+ int0 = -0x7e00;
+ c_int_lte_lit2(0xf8);
+
+ int0 = -0x4567;
+ c_int_lte_lit2(0xf0);
+
+ int0 = -0x200;
+ c_int_lte_lit2(0xf0);
+
+ int0 = -0x102;
+ c_int_lte_lit2(0xf0);
+
+ int0 = -0x101;
+ c_int_lte_lit2(0xf0);
+
+ int0 = -0x100;
+ c_int_lte_lit2(0xe0);
+
+ int0 = -0xff;
+ c_int_lte_lit2(0xc0);
+
+ int0 = -0x02;
+ c_int_lte_lit2(0x80);
+
+ int0 = -0x01;
+ c_int_lte_lit2(0x80);
+
+ int0 = 0;
+ c_int_lte_lit2(0x00);
+
+ int0 = 1;
+ c_int_lte_lit2(0x00);
+
+ int0 = 0x7fff;
+ c_int_lte_lit2(0x00);
+
+ /* now check contiguous ranges */
+
+ for(int0 = -0x7ffe; int0 != -0x7f00; int0++)
+ c_int_lte_lit2(0xfe);
+
+ for(int0 = -0x7dff; int0 != -0x101; int0++)
+ c_int_lte_lit2(0xf0);
+
+ for(int0 = 0; int0 != 0x7fff; int0++)
+ c_int_lte_lit2(0);
+
+}
+
+
+void
+main (void)
+{
+ char_compare();
+ int_compare1();
+ int_compare2();
+
+ success = failures;
+ done ();
+}