- Added ;#CSRC labels so that a 3rd party tool can parse the .asm output
authorsdattalo <sdattalo@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Thu, 1 Nov 2001 15:26:09 +0000 (15:26 +0000)
committersdattalo <sdattalo@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Thu, 1 Nov 2001 15:26:09 +0000 (15:26 +0000)
  and ascertain the C source line numbers. (The Tool is gpsim).
- Label generation bug for & was fixed
- Redundant/unnecessary labels weren't properly removed.
- pcode optimization was happening twice.

git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1483 4a8a32a2-be11-0410-ad9d-d568d2c75423

src/pic/gen.c
src/pic/glue.c
src/pic/pcode.c
src/pic/pcodepeep.c

index 592ad92b070d7864e0440fc3042c54d3ad0dabf1..2052de5f95ce7b19a687fe531a9c64395d17cc7f 100644 (file)
@@ -392,6 +392,10 @@ static void resolveIfx(resolvedIfx *resIfx, iCode *ifx)
       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);
@@ -3761,7 +3765,6 @@ static void gencjne(operand *left, operand *right, iCode *ifx)
   int offset = 0;
   resolvedIfx rIfx;
   symbol *lbl;
-  symbol *tlbl;
 
   unsigned long lit = 0L;
   DEBUGpic14_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
@@ -4446,283 +4449,291 @@ static void jmpTrueOrFalse (iCode *ic, symbol *tlbl)
 /*-----------------------------------------------------------------*/
 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);     
 }
 
 /*-----------------------------------------------------------------*/
@@ -9016,7 +9027,7 @@ void genpic14Code (iCode *lic)
                         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
index ff62132beacfffec3115b2408e60b1aa891210d5..8837ef66a93b23cef3d030e61503db610c9595c4 100644 (file)
@@ -1039,9 +1039,9 @@ picglue ()
   AnalyzepCode('*'); //code->dbName);
   printCallTree(stderr);
 
-  pCodePeepInit();
+  //pCodePeepInit();
 
-  OptimizepCode(code->dbName);
+  //OptimizepCode(code->dbName);
 
 
   /* print the global struct definitions */
index cd3265583066a357a50479ad39dad918f3791f68..24f624bb028d818c8aaf1e3312710d9672bf1a51 100644 (file)
@@ -1181,8 +1181,6 @@ static void pCodeLabelDestruct(pCode *pc)
   if(!pc)
     return;
 
-  unlinkPC(pc);
-
   if((pc->type == PC_LABEL) && PCL(pc)->label)
     free(PCL(pc)->label);
 
@@ -1648,7 +1646,7 @@ static void genericPrint(FILE *of, pCode *pc)
     // If the opcode has a label, print that first
     {
       pBranch *pbl = pc->label;
-      while(pbl) {
+      while(pbl && pbl->pc) {
        if(pbl->pc->type == PC_LABEL)
          pCodePrintLabel(of, pbl->pc);
        pbl = pbl->next;
@@ -1758,16 +1756,28 @@ static void pCodePrintLabel(FILE *of, pCode *pc)
 
 }
 /*-----------------------------------------------------------------*/
-static void  unlinkpCodeFromBranch(pBranch *pb , pCode *pc)
+/* unlinkpCodeFromBranch - Search for a label in a pBranch and     */
+/*                         remove it if it is found.               */
+/*-----------------------------------------------------------------*/
+static void unlinkpCodeFromBranch(pCode *pcl , pCode *pc)
 {
   pBranch *b, *bprev;
 
   bprev = NULL;
-  b = pb;
+  b = pcl->label;
   while(b) {
     if(b->pc == pc) {
-      if(bprev)
-       bprev->next = b->next;
+
+      /* Found a label */
+      if(bprev) {
+       bprev->next = b->next;  /* Not first pCode in chain */
+       free(b);
+      } else {
+       pc->destruct(pc);
+       pcl->label = b->next;   /* First pCode in chain */
+       free(b);
+      }
+      return;  /* A label can't occur more than once */
     }
     bprev = b;
     b = b->next;
@@ -2131,13 +2141,13 @@ void pBlockRemoveUnusedLabels(pBlock *pb)
       fprintf(stderr," !!! REMOVED A LABEL !!! key = %d\n", pcl->key);
 
       if(pc->type == PC_LABEL) {
-       //unlinkPC(pc);
+       unlinkPC(pc);
        pCodeLabelDestruct(pc);
       } else {
-       unlinkpCodeFromBranch(pc->label, pc);
-       if(pc->label->next == NULL && pc->label->pc == NULL) {
+       unlinkpCodeFromBranch(pc, PCODE(pcl));
+       /*if(pc->label->next == NULL && pc->label->pc == NULL) {
          free(pc->label);
-       }
+       }*/
       }
 
     }
@@ -2237,25 +2247,32 @@ void AnalyzepCode(char dbName)
   pCode *pc;
   pBranch *pbr;
 
+  int i,changes;
+
   if(!the_pFile)
     return;
 
   fprintf(stderr," Analyzing pCode");
 
-  /* First, merge the labels with the instructions */
-  for(pb = the_pFile->pbHead; pb; pb = pb->next) {
-    if('*' == dbName || getpBlock_dbName(pb) == dbName) {
+  changes = 0;
+  i = 0;
+  do {
+    /* First, merge the labels with the instructions */
+    for(pb = the_pFile->pbHead; pb; pb = pb->next) {
+      if('*' == dbName || getpBlock_dbName(pb) == dbName) {
 
-      fprintf(stderr," analyze and merging block %c\n",dbName);
-      pBlockMergeLabels(pb);
-      AnalyzepBlock(pb);
+       fprintf(stderr," analyze and merging block %c\n",dbName);
+       pBlockMergeLabels(pb);
+       AnalyzepBlock(pb);
+      }
     }
-  }
 
-  for(pb = the_pFile->pbHead; pb; pb = pb->next) {
-    if('*' == dbName || getpBlock_dbName(pb) == dbName)
-      OptimizepBlock(pb);
-  }
+    for(pb = the_pFile->pbHead; pb; pb = pb->next) {
+      if('*' == dbName || getpBlock_dbName(pb) == dbName)
+       changes += OptimizepBlock(pb);
+    }
+      
+  } while(changes && (i++ < MAX_PASSES));
 
   /* Now build the call tree.
      First we examine all of the pCodes for functions.
index 5b4b23604661448e289d2a152fc4666e307ed32c..80cb0ceb563a07c1d0d04d4d3b3025937e91f1ff 100644 (file)
@@ -1219,227 +1219,7 @@ static void * DLL_append(_DLL *list, _DLL *next)
 
   -----------------------------------------------------------------*/
 
-#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'   */