resIfx->lbl = IC_FALSE(ifx);
resIfx->condition = 0;
}
+ if(IC_TRUE(ifx))
+ DEBUGpic14_emitcode("; ***","ifx true is non-null");
+ if(IC_FALSE(ifx))
+ DEBUGpic14_emitcode("; ***","ifx false is non-null");
}
DEBUGpic14_emitcode("; ***","%s lbl->key=%d, (lab offset=%d)",__FUNCTION__,resIfx->lbl->key,labelOffset);
int offset = 0;
resolvedIfx rIfx;
symbol *lbl;
- symbol *tlbl;
unsigned long lit = 0L;
DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
/*-----------------------------------------------------------------*/
static void genAnd (iCode *ic, iCode *ifx)
{
- operand *left, *right, *result;
- int size, offset=0;
- unsigned long lit = 0L;
- int bytelit = 0;
- // char buffer[10];
+ operand *left, *right, *result;
+ int size, offset=0;
+ unsigned long lit = 0L;
+ int bytelit = 0;
+ resolvedIfx rIfx;
- DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- aopOp((left = IC_LEFT(ic)),ic,FALSE);
- aopOp((right= IC_RIGHT(ic)),ic,FALSE);
- aopOp((result=IC_RESULT(ic)),ic,TRUE);
-#ifdef DEBUG_TYPE
- pic14_emitcode("","; Type res[%d] = l[%d]&r[%d]",
- AOP_TYPE(result),
- AOP_TYPE(left), AOP_TYPE(right));
- pic14_emitcode("","; Size res[%d] = l[%d]&r[%d]",
- AOP_SIZE(result),
- AOP_SIZE(left), AOP_SIZE(right));
-#endif
+ DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ aopOp((left = IC_LEFT(ic)),ic,FALSE);
+ aopOp((right= IC_RIGHT(ic)),ic,FALSE);
+ aopOp((result=IC_RESULT(ic)),ic,TRUE);
- /* if left is a literal & right is not then exchange them */
- if ((AOP_TYPE(left) == AOP_LIT && AOP_TYPE(right) != AOP_LIT) ||
- AOP_NEEDSACC(left)) {
- operand *tmp = right ;
- right = left;
- left = tmp;
- }
+ resolveIfx(&rIfx,ifx);
- /* if result = right then exchange them */
- if(pic14_sameRegs(AOP(result),AOP(right))){
- operand *tmp = right ;
- right = left;
- left = tmp;
- }
+ /* if left is a literal & right is not then exchange them */
+ if ((AOP_TYPE(left) == AOP_LIT && AOP_TYPE(right) != AOP_LIT) ||
+ AOP_NEEDSACC(left)) {
+ operand *tmp = right ;
+ right = left;
+ left = tmp;
+ }
- /* if right is bit then exchange them */
- if (AOP_TYPE(right) == AOP_CRY &&
- AOP_TYPE(left) != AOP_CRY){
- operand *tmp = right ;
- right = left;
- left = tmp;
- }
- if(AOP_TYPE(right) == AOP_LIT)
- lit = (unsigned long)floatFromVal (AOP(right)->aopu.aop_lit);
+ /* if result = right then exchange them */
+ if(pic14_sameRegs(AOP(result),AOP(right))){
+ operand *tmp = right ;
+ right = left;
+ left = tmp;
+ }
- size = AOP_SIZE(result);
+ /* if right is bit then exchange them */
+ if (AOP_TYPE(right) == AOP_CRY &&
+ AOP_TYPE(left) != AOP_CRY){
+ operand *tmp = right ;
+ right = left;
+ left = tmp;
+ }
+ if(AOP_TYPE(right) == AOP_LIT)
+ lit = (unsigned long)floatFromVal (AOP(right)->aopu.aop_lit);
- // if(bit & yy)
- // result = bit & yy;
- if (AOP_TYPE(left) == AOP_CRY){
- // c = bit & literal;
- if(AOP_TYPE(right) == AOP_LIT){
- if(lit & 1) {
- if(size && pic14_sameRegs(AOP(result),AOP(left)))
- // no change
- goto release;
- pic14_emitcode("mov","c,%s",AOP(left)->aopu.aop_dir);
- } else {
- // bit(result) = 0;
- if(size && (AOP_TYPE(result) == AOP_CRY)){
- pic14_emitcode("clr","%s",AOP(result)->aopu.aop_dir);
- goto release;
- }
- if((AOP_TYPE(result) == AOP_CRY) && ifx){
- jumpIfTrue(ifx);
- goto release;
- }
- pic14_emitcode("clr","c");
- }
- } else {
- if (AOP_TYPE(right) == AOP_CRY){
- // c = bit & bit;
- pic14_emitcode("mov","c,%s",AOP(right)->aopu.aop_dir);
- pic14_emitcode("anl","c,%s",AOP(left)->aopu.aop_dir);
- } else {
- // c = bit & val;
- MOVA(aopGet(AOP(right),0,FALSE,FALSE));
- // c = lsb
- pic14_emitcode("rrc","a");
- pic14_emitcode("anl","c,%s",AOP(left)->aopu.aop_dir);
- }
- }
- // bit = c
- // val = c
- if(size)
- pic14_outBitC(result);
- // if(bit & ...)
- else if((AOP_TYPE(result) == AOP_CRY) && ifx)
- genIfxJump(ifx, "c");
- goto release ;
+ size = AOP_SIZE(result);
+
+ DEBUGpic14_emitcode ("; ","result %s=%s, left %s=%s, right %s=%s, size = %d",
+ AopType(AOP_TYPE(result)),
+ aopGet(AOP(result),0,TRUE,FALSE),
+ AopType(AOP_TYPE(left)),
+ aopGet(AOP(left),0,TRUE,FALSE),
+ AopType(AOP_TYPE(right)),
+ aopGet(AOP(right),0,FALSE,FALSE),
+ size);
+ // if(bit & yy)
+ // result = bit & yy;
+ if (AOP_TYPE(left) == AOP_CRY){
+ // c = bit & literal;
+ if(AOP_TYPE(right) == AOP_LIT){
+ if(lit & 1) {
+ if(size && pic14_sameRegs(AOP(result),AOP(left)))
+ // no change
+ goto release;
+ pic14_emitcode("mov","c,%s",AOP(left)->aopu.aop_dir);
+ } else {
+ // bit(result) = 0;
+ if(size && (AOP_TYPE(result) == AOP_CRY)){
+ pic14_emitcode("clr","%s",AOP(result)->aopu.aop_dir);
+ goto release;
+ }
+ if((AOP_TYPE(result) == AOP_CRY) && ifx){
+ jumpIfTrue(ifx);
+ goto release;
+ }
+ pic14_emitcode("clr","c");
+ }
+ } else {
+ if (AOP_TYPE(right) == AOP_CRY){
+ // c = bit & bit;
+ pic14_emitcode("mov","c,%s",AOP(right)->aopu.aop_dir);
+ pic14_emitcode("anl","c,%s",AOP(left)->aopu.aop_dir);
+ } else {
+ // c = bit & val;
+ MOVA(aopGet(AOP(right),0,FALSE,FALSE));
+ // c = lsb
+ pic14_emitcode("rrc","a");
+ pic14_emitcode("anl","c,%s",AOP(left)->aopu.aop_dir);
+ }
}
+ // bit = c
+ // val = c
+ if(size)
+ pic14_outBitC(result);
+ // if(bit & ...)
+ else if((AOP_TYPE(result) == AOP_CRY) && ifx)
+ genIfxJump(ifx, "c");
+ goto release ;
+ }
- // if(val & 0xZZ) - size = 0, ifx != FALSE -
- // bit = val & 0xZZ - size = 1, ifx = FALSE -
- if((AOP_TYPE(right) == AOP_LIT) &&
- (AOP_TYPE(result) == AOP_CRY) &&
- (AOP_TYPE(left) != AOP_CRY)){
- int posbit = isLiteralBit(lit);
- /* left & 2^n */
- if(posbit){
- posbit--;
- //MOVA(aopGet(AOP(left),posbit>>3,FALSE,FALSE));
- // bit = left & 2^n
- if(size)
- pic14_emitcode("mov","c,acc.%d",posbit&0x07);
- // if(left & 2^n)
+ // if(val & 0xZZ) - size = 0, ifx != FALSE -
+ // bit = val & 0xZZ - size = 1, ifx = FALSE -
+ if((AOP_TYPE(right) == AOP_LIT) &&
+ (AOP_TYPE(result) == AOP_CRY) &&
+ (AOP_TYPE(left) != AOP_CRY)){
+ int posbit = isLiteralBit(lit);
+ /* left & 2^n */
+ if(posbit){
+ posbit--;
+ //MOVA(aopGet(AOP(left),posbit>>3,FALSE,FALSE));
+ // bit = left & 2^n
+ if(size)
+ pic14_emitcode("mov","c,acc.%d",posbit&0x07);
+ // if(left & 2^n)
+ else{
+ if(ifx){
+/*
+ if(IC_TRUE(ifx)) {
+ emitpcode(POC_BTFSC,newpCodeOpBit(aopGet(AOP(left),0,FALSE,FALSE),posbit,0));
+ emitpcode(POC_GOTO,popGetLabel(IC_TRUE(ic)->key));
+ } else {
+ emitpcode(POC_BTFSS,newpCodeOpBit(aopGet(AOP(left),0,FALSE,FALSE),posbit,0));
+ emitpcode(POC_GOTO,popGetLabel(IC_FALSE(ic)->key));
+ }
+*/
+ emitpcode(((rIfx.condition) ? POC_BTFSC : POC_BTFSS),
+ newpCodeOpBit(aopGet(AOP(left),0,FALSE,FALSE),posbit,0));
+ emitpcode(POC_GOTO,popGetLabel(rIfx.lbl->key));
+
+ ifx->generated = 1;
+ }
+ goto release;
+ }
+ } else {
+ symbol *tlbl = newiTempLabel(NULL);
+ int sizel = AOP_SIZE(left);
+ if(size)
+ pic14_emitcode("setb","c");
+ while(sizel--){
+ if((bytelit = ((lit >> (offset*8)) & 0x0FFL)) != 0x0L){
+ MOVA( aopGet(AOP(left),offset,FALSE,FALSE));
+ // byte == 2^n ?
+ if((posbit = isLiteralBit(bytelit)) != 0)
+ pic14_emitcode("jb","acc.%d,%05d_DS_",(posbit-1)&0x07,tlbl->key+100);
else{
- if(ifx){
- if(IC_TRUE(ifx)) {
- emitpcode(POC_BTFSC,newpCodeOpBit(aopGet(AOP(left),0,FALSE,FALSE),posbit,0));
- emitpcode(POC_GOTO,popGetLabel(IC_TRUE(ic)->key));
- } else {
- emitpcode(POC_BTFSS,newpCodeOpBit(aopGet(AOP(left),0,FALSE,FALSE),posbit,0));
- emitpcode(POC_GOTO,popGetLabel(IC_FALSE(ic)->key));
- }
- ifx->generated = 1;
- }
- goto release;
+ if(bytelit != 0x0FFL)
+ pic14_emitcode("anl","a,%s",
+ aopGet(AOP(right),offset,FALSE,TRUE));
+ pic14_emitcode("jnz","%05d_DS_",tlbl->key+100);
}
- } else {
- symbol *tlbl = newiTempLabel(NULL);
- int sizel = AOP_SIZE(left);
- if(size)
- pic14_emitcode("setb","c");
- while(sizel--){
- if((bytelit = ((lit >> (offset*8)) & 0x0FFL)) != 0x0L){
- MOVA( aopGet(AOP(left),offset,FALSE,FALSE));
- // byte == 2^n ?
- if((posbit = isLiteralBit(bytelit)) != 0)
- pic14_emitcode("jb","acc.%d,%05d_DS_",(posbit-1)&0x07,tlbl->key+100);
- else{
- if(bytelit != 0x0FFL)
- pic14_emitcode("anl","a,%s",
- aopGet(AOP(right),offset,FALSE,TRUE));
- pic14_emitcode("jnz","%05d_DS_",tlbl->key+100);
- }
- }
- offset++;
- }
- // bit = left & literal
- if(size){
- pic14_emitcode("clr","c");
- pic14_emitcode("","%05d_DS_:",tlbl->key+100);
- }
- // if(left & literal)
- else{
- if(ifx)
- jmpTrueOrFalse(ifx, tlbl);
- goto release ;
- }
- }
- pic14_outBitC(result);
- goto release ;
+ }
+ offset++;
+ }
+ // bit = left & literal
+ if(size){
+ pic14_emitcode("clr","c");
+ pic14_emitcode("","%05d_DS_:",tlbl->key+100);
+ }
+ // if(left & literal)
+ else{
+ if(ifx)
+ jmpTrueOrFalse(ifx, tlbl);
+ goto release ;
+ }
}
+ pic14_outBitC(result);
+ goto release ;
+ }
- /* if left is same as result */
- if(pic14_sameRegs(AOP(result),AOP(left))){
- int know_W = -1;
- for(;size--; offset++,lit>>=8) {
+ /* if left is same as result */
+ if(pic14_sameRegs(AOP(result),AOP(left))){
+ int know_W = -1;
+ for(;size--; offset++,lit>>=8) {
+ if(AOP_TYPE(right) == AOP_LIT){
+ switch(lit & 0xff) {
+ case 0x00:
+ /* and'ing with 0 has clears the result */
+ pic14_emitcode("clrf","%s",aopGet(AOP(result),offset,FALSE,FALSE));
+ emitpcode(POC_CLRF,popGet(AOP(result),offset,FALSE,FALSE));
+ break;
+ case 0xff:
+ /* and'ing with 0xff is a nop when the result and left are the same */
+ break;
+
+ default:
+ {
+ int p = my_powof2( (~lit) & 0xff );
+ if(p>=0) {
+ /* only one bit is set in the literal, so use a bcf instruction */
+ pic14_emitcode("bcf","%s,%d",aopGet(AOP(left),offset,FALSE,TRUE),p);
+ //emitpcode(POC_BCF,popGet(AOP(left),offset,FALSE,TRUE));
+ emitpcode(POC_BCF,newpCodeOpBit(aopGet(AOP(left),offset,FALSE,FALSE),p,0));
+
+ } else {
+ pic14_emitcode("movlw","0x%x", (lit & 0xff));
+ pic14_emitcode("andwf","%s,f",aopGet(AOP(left),offset,FALSE,TRUE));
+ if(know_W != (lit&0xff))
+ emitpcode(POC_MOVLW, popGetLit(lit & 0xff));
+ know_W = lit &0xff;
+ emitpcode(POC_ANDWF,popGet(AOP(left),offset,FALSE,TRUE));
+ }
+ }
+ }
+ } else {
+ if (AOP_TYPE(left) == AOP_ACC) {
+ emitpcode(POC_ANDFW,popGet(AOP(right),offset,FALSE,FALSE));
+ } else {
+ emitpcode(POC_MOVFW,popGet(AOP(right),offset,FALSE,FALSE));
+ emitpcode(POC_ANDWF,popGet(AOP(left),offset,FALSE,FALSE));
+
+ }
+ }
+ }
+
+ } else {
+ // left & result in different registers
+ if(AOP_TYPE(result) == AOP_CRY){
+ // result = bit
+ // if(size), result in bit
+ // if(!size && ifx), conditional oper: if(left & right)
+ symbol *tlbl = newiTempLabel(NULL);
+ int sizer = min(AOP_SIZE(left),AOP_SIZE(right));
+ if(size)
+ pic14_emitcode("setb","c");
+ while(sizer--){
+ MOVA(aopGet(AOP(right),offset,FALSE,FALSE));
+ pic14_emitcode("anl","a,%s",
+ aopGet(AOP(left),offset,FALSE,FALSE));
+ pic14_emitcode("jnz","%05d_DS_",tlbl->key+100);
+ offset++;
+ }
+ if(size){
+ CLRC;
+ pic14_emitcode("","%05d_DS_:",tlbl->key+100);
+ pic14_outBitC(result);
+ } else if(ifx)
+ jmpTrueOrFalse(ifx, tlbl);
+ } else {
+ for(;(size--);offset++) {
+ // normal case
+ // result = left & right
if(AOP_TYPE(right) == AOP_LIT){
- switch(lit & 0xff) {
+ int t = (lit >> (offset*8)) & 0x0FFL;
+ switch(t) {
case 0x00:
- /* and'ing with 0 has clears the result */
- pic14_emitcode("clrf","%s",aopGet(AOP(result),offset,FALSE,FALSE));
+ pic14_emitcode("clrf","%s",
+ aopGet(AOP(result),offset,FALSE,FALSE));
emitpcode(POC_CLRF,popGet(AOP(result),offset,FALSE,FALSE));
break;
case 0xff:
- /* and'ing with 0xff is a nop when the result and left are the same */
+ pic14_emitcode("movf","%s,w",
+ aopGet(AOP(left),offset,FALSE,FALSE));
+ pic14_emitcode("movwf","%s",
+ aopGet(AOP(result),offset,FALSE,FALSE));
+ emitpcode(POC_MOVFW,popGet(AOP(left),offset,FALSE,FALSE));
+ emitpcode(POC_MOVWF,popGet(AOP(result),offset,FALSE,FALSE));
break;
-
default:
- {
- int p = my_powof2( (~lit) & 0xff );
- if(p>=0) {
- /* only one bit is set in the literal, so use a bcf instruction */
- pic14_emitcode("bcf","%s,%d",aopGet(AOP(left),offset,FALSE,TRUE),p);
- //emitpcode(POC_BCF,popGet(AOP(left),offset,FALSE,TRUE));
- emitpcode(POC_BCF,newpCodeOpBit(aopGet(AOP(left),offset,FALSE,FALSE),p,0));
-
- } else {
- pic14_emitcode("movlw","0x%x", (lit & 0xff));
- pic14_emitcode("andwf","%s,f",aopGet(AOP(left),offset,FALSE,TRUE));
- if(know_W != (lit&0xff))
- emitpcode(POC_MOVLW, popGetLit(lit & 0xff));
- know_W = lit &0xff;
- emitpcode(POC_ANDWF,popGet(AOP(left),offset,FALSE,TRUE));
- }
- }
- }
- } else {
- if (AOP_TYPE(left) == AOP_ACC) {
- emitpcode(POC_ANDFW,popGet(AOP(right),offset,FALSE,FALSE));
- } else {
- emitpcode(POC_MOVFW,popGet(AOP(right),offset,FALSE,FALSE));
- emitpcode(POC_ANDWF,popGet(AOP(left),offset,FALSE,FALSE));
-
+ pic14_emitcode("movlw","0x%x",t);
+ pic14_emitcode("andwf","%s,w",
+ aopGet(AOP(left),offset,FALSE,FALSE));
+ pic14_emitcode("movwf","%s",
+ aopGet(AOP(result),offset,FALSE,FALSE));
+
+ emitpcode(POC_MOVLW, popGetLit(t));
+ emitpcode(POC_ANDFW,popGet(AOP(left),offset,FALSE,FALSE));
+ emitpcode(POC_MOVWF,popGet(AOP(result),offset,FALSE,FALSE));
}
+ continue;
}
- }
- } else {
- // left & result in different registers
- if(AOP_TYPE(result) == AOP_CRY){
- // result = bit
- // if(size), result in bit
- // if(!size && ifx), conditional oper: if(left & right)
- symbol *tlbl = newiTempLabel(NULL);
- int sizer = min(AOP_SIZE(left),AOP_SIZE(right));
- if(size)
- pic14_emitcode("setb","c");
- while(sizer--){
- MOVA(aopGet(AOP(right),offset,FALSE,FALSE));
- pic14_emitcode("anl","a,%s",
- aopGet(AOP(left),offset,FALSE,FALSE));
- pic14_emitcode("jnz","%05d_DS_",tlbl->key+100);
- offset++;
- }
- if(size){
- CLRC;
- pic14_emitcode("","%05d_DS_:",tlbl->key+100);
- pic14_outBitC(result);
- } else if(ifx)
- jmpTrueOrFalse(ifx, tlbl);
- } else {
- for(;(size--);offset++) {
- // normal case
- // result = left & right
- if(AOP_TYPE(right) == AOP_LIT){
- int t = (lit >> (offset*8)) & 0x0FFL;
- switch(t) {
- case 0x00:
- pic14_emitcode("clrf","%s",
- aopGet(AOP(result),offset,FALSE,FALSE));
- emitpcode(POC_CLRF,popGet(AOP(result),offset,FALSE,FALSE));
- break;
- case 0xff:
- pic14_emitcode("movf","%s,w",
- aopGet(AOP(left),offset,FALSE,FALSE));
- pic14_emitcode("movwf","%s",
- aopGet(AOP(result),offset,FALSE,FALSE));
- emitpcode(POC_MOVFW,popGet(AOP(left),offset,FALSE,FALSE));
- emitpcode(POC_MOVWF,popGet(AOP(result),offset,FALSE,FALSE));
- break;
- default:
- pic14_emitcode("movlw","0x%x",t);
- pic14_emitcode("andwf","%s,w",
+ if (AOP_TYPE(left) == AOP_ACC) {
+ pic14_emitcode("andwf","%s,w",aopGet(AOP(right),offset,FALSE,FALSE));
+ emitpcode(POC_ANDFW,popGet(AOP(right),offset,FALSE,FALSE));
+ } else {
+ pic14_emitcode("movf","%s,w",aopGet(AOP(right),offset,FALSE,FALSE));
+ pic14_emitcode("andwf","%s,w",
aopGet(AOP(left),offset,FALSE,FALSE));
- pic14_emitcode("movwf","%s",
- aopGet(AOP(result),offset,FALSE,FALSE));
-
- emitpcode(POC_MOVLW, popGetLit(t));
- emitpcode(POC_ANDFW,popGet(AOP(left),offset,FALSE,FALSE));
- emitpcode(POC_MOVWF,popGet(AOP(result),offset,FALSE,FALSE));
- }
- continue;
- }
-
- if (AOP_TYPE(left) == AOP_ACC) {
- pic14_emitcode("andwf","%s,w",aopGet(AOP(right),offset,FALSE,FALSE));
- emitpcode(POC_ANDFW,popGet(AOP(right),offset,FALSE,FALSE));
- } else {
- pic14_emitcode("movf","%s,w",aopGet(AOP(right),offset,FALSE,FALSE));
- pic14_emitcode("andwf","%s,w",
- aopGet(AOP(left),offset,FALSE,FALSE));
- emitpcode(POC_MOVFW,popGet(AOP(right),offset,FALSE,FALSE));
- emitpcode(POC_ANDFW,popGet(AOP(left),offset,FALSE,FALSE));
- }
- pic14_emitcode("movwf","%s",aopGet(AOP(result),offset,FALSE,FALSE));
- emitpcode(POC_MOVWF,popGet(AOP(result),offset,FALSE,FALSE));
- }
+ emitpcode(POC_MOVFW,popGet(AOP(right),offset,FALSE,FALSE));
+ emitpcode(POC_ANDFW,popGet(AOP(left),offset,FALSE,FALSE));
}
+ pic14_emitcode("movwf","%s",aopGet(AOP(result),offset,FALSE,FALSE));
+ emitpcode(POC_MOVWF,popGet(AOP(result),offset,FALSE,FALSE));
+ }
}
+ }
-release :
+ release :
freeAsmop(left,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(right,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
- freeAsmop(result,NULL,ic,TRUE);
+ freeAsmop(right,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
+ freeAsmop(result,NULL,ic,TRUE);
}
/*-----------------------------------------------------------------*/
ic->level,ic->block);
_G.debugLine = 0;
}
- pic14_emitcode(";","%s %d",FileBaseName(ic->filename),ic->lineno);
+ pic14_emitcode("#CSRC","%s %d",FileBaseName(ic->filename),ic->lineno);
cln = ic->lineno ;
}
/* if the result is marked as
-----------------------------------------------------------------*/
-#if 0
-/*-----------------------------------------------------------------*/
-/* pCodePeep */
-/*-----------------------------------------------------------------*/
-int pCodePeepCompare(pCode *pc, pCodePeep *pcp)
-{
- pCode *pcfrom,*pcto;
-
- pcfrom = pc;
- for( pcto=pcp->target; pcto; pcto=pcto->next) {
-
- pcfrom = findNextInstruction(pcfrom);
-
- if( pcfrom &&
- (PCI(pcfrom)->op == PCI(pcto)->op ||
- PCI(pcto)->op == POC_WILD))
- continue;
- return 0;
- }
- return 0;
-}
-
-/*-----------------------------------------------------------------*/
-/* pCodePeep */
-/*-----------------------------------------------------------------*/
-void pCodePeepSearch(pCodePeep *snippet)
-{
- pBlock *pb;
- pCode *pc;
-
- if(!the_pFile)
- return;
-
- /* compare the chain to the pCode that we've
- got so far. If a match is found, then replace
- the pCode chain.
- */
- for(pb = the_pFile->pbHead; pb; pb = pb->next) {
- for(pc = pb->pcHead; pc; pc = pc->next) {
- pCodePeepCompare(pc,snippet);
- }
- }
-
-}
-#endif
-
-#if 0
-pBlock *pBlockAppend(pBlock *pb1, pBlock *pb2)
-{
- pBlock *pb;
-
- if(!pb1->tail)
- return pb2;
-
- pb = pb1->tail;
-
- pb2->head = pb1;
- pb2->tail = NULL;
- pb1->tail = pb2;
-
-}
-
-#endif
-
-void pCodePeepInit(void)
-{
-#if 0
- pBlock *pb;
- // pCode *pc;
- pCodePeep *pcp;
- pCodePeepSnippets *pcps;
-
- /* Declare a peep code snippet */
- /* <FIXME> do I really need a separate struct just to DLL the snippets? */
- /* e.g. I could put the DLL into the pCodePeep structure */
-
- /*
-
- target:
-
- movwf %1
- movf %1,w
-
- replace:
-
- movwf %1
-
- Condition:
- false condition - PCC_Z (Z bit is not used as input to subsequent code)
- true condition - none
- */
- pcps = Safe_calloc(1,sizeof(pCodePeepSnippets));
- pcp = pcps->peep = Safe_calloc(1,sizeof(pCodePeep));
- peepSnippets = DLL_append((_DLL*)peepSnippets,(_DLL*)pcps);
-
-
- pb = newpCodeChain(NULL, 'W', newpCode(POC_MOVWF, newpCodeOpWild(0,pcp,newpCodeOp(NULL,PO_GPR_REGISTER))) );
- addpCode2pBlock( pb, newpCode(POC_MOVFW, newpCodeOpWild(0,pcp,newpCodeOp(NULL,PO_GPR_REGISTER))) );
- pcp->target = pb;
-
- pcp->replace = newpCodeChain(NULL, 'W',newpCode(POC_MOVWF, newpCodeOpWild(0,pcp,newpCodeOp(NULL,PO_GPR_REGISTER))) );
-
- /* Allocate space to store pointers to the wildcard variables */
- pcp->nvars = 1;
- pcp->vars = Safe_calloc(pcp->nvars, sizeof(char *));
- pcp->nwildpCodes = 0;
- pcp->wildpCodes = NULL;
-
- pcp->postFalseCond = PCC_Z;
- pcp->postTrueCond = PCC_NONE;
-
- fprintf(stderr,"Peep rule\nTarget:\n");
- printpCodeString(stderr,pcp->target->pcHead, 10);
- fprintf(stderr,"Replaced with:\n");
- printpCodeString(stderr,pcp->replace->pcHead, 10);
-
- /* Now for another peep example */
- pcps = Safe_calloc(1,sizeof(pCodePeepSnippets));
- pcp = pcps->peep = Safe_calloc(1,sizeof(pCodePeep));
- peepSnippets = DLL_append((_DLL*)peepSnippets,(_DLL*)pcps);
-
- {
- /*
- target:
-
- btfsc %0
- goto %1
- %3
- %1: %4
-
- replace:
- btfss %0
- %3
- %1: %4
-
- The %3 and %4 are wild opcodes. Since the opcodes
- are stored in a different array than the wild operands,
- they can have the same indices and not conflict. So
- below, the %3 is really a %0, %4 is a %1.
-
- */
- pCodeOp *pcl;
- pCodeOp *pcw;
- pCodeOp *pcwb;
-
- // Create a new wild operand subtyped as a bit
- pcwb = newpCodeOpWild(0,pcp,newpCodeOpBit(NULL,-1,0));
-
- // Create a
- pb = newpCodeChain(NULL, 'W',newpCode(POC_BTFSC,pcwb));
-
- pcl = newpCodeOpLabel(-1);
- pcw = newpCodeOpWild(1, pcp, pcl);
- addpCode2pBlock( pb, newpCode(POC_GOTO, pcw));
- addpCode2pBlock( pb, newpCodeWild(0,NULL,NULL));
- addpCode2pBlock( pb, newpCodeWild(1,NULL,pcw));
-
-
- pcp->target = pb;
-
- pb = newpCodeChain(NULL, 'W',newpCode(POC_BTFSS, pcwb));
- addpCode2pBlock( pb, newpCodeWild(0,NULL,NULL));
- addpCode2pBlock( pb, newpCodeWild(1,NULL,pcw));
-
- pcp->replace = pb;
-
- /* Allocate space to store pointers to the wildcard variables */
- pcp->nvars = 2;
- pcp->vars = Safe_calloc(pcp->nvars, sizeof(char *));
- pcp->nwildpCodes = 2;
- pcp->wildpCodes = Safe_calloc(pcp->nwildpCodes, sizeof(pCode *));
-
- pcp->postFalseCond = PCC_NONE;
- pcp->postTrueCond = PCC_NONE;
- }
-
-
-
-
-
-
-
-
-
-
- //-------------
-
- /* Now for another peep example */
- pcps = Safe_calloc(1,sizeof(pCodePeepSnippets));
- pcp = pcps->peep = Safe_calloc(1,sizeof(pCodePeep));
- peepSnippets = DLL_append((_DLL*)peepSnippets,(_DLL*)pcps);
-
- {
- pCodeOp *pcw;
-
- pcw = newpCodeOpWild(0,pcp,newpCodeOp(NULL,PO_GPR_REGISTER));
-
- pb = newpCodeChain(NULL, 'W', newpCode(POC_MOVWF, pcw));
- addpCode2pBlock( pb, newpCode(POC_MOVWF, pcw));
-
- pcp->target = pb;
-
- pb = newpCodeChain(NULL, 'W',newpCode(POC_MOVWF, pcw));
-
- pcp->replace = pb;
-
- /* Allocate space to store pointers to the wildcard variables */
- pcp->nvars = 1;
- pcp->vars = Safe_calloc(pcp->nvars, sizeof(char *));
- pcp->nwildpCodes = 0;
- pcp->wildpCodes = NULL;
-
- pcp->postFalseCond = PCC_NONE;
- pcp->postTrueCond = PCC_NONE;
- }
-
-
-
-#endif
-}
/*-----------------------------------------------------------------*/
/* pCodeSearchCondition - Search a pCode chain for a 'condition' */