Numerous bug fixes in PIC Port (pointers, shifting, bank selection,...)
authorsdattalo <sdattalo@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Fri, 17 May 2002 04:35:09 +0000 (04:35 +0000)
committersdattalo <sdattalo@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Fri, 17 May 2002 04:35:09 +0000 (04:35 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2016 4a8a32a2-be11-0410-ad9d-d568d2c75423

src/pic/gen.c
src/pic/pcode.c
src/pic/pcode.h
src/pic/pcodepeep.c
src/pic/ralloc.c
src/regression/Makefile
src/regression/mult1.c [new file with mode: 0644]
src/regression/rotate5.c [new file with mode: 0644]

index d189a612389d89005aef506cb652cf33afde11c9..41d54342b515c49ca87f1ac27f00bde4843c1864 100644 (file)
@@ -1308,7 +1308,7 @@ pCodeOp *popGet (asmop *aop, int offset) //, bool bit16, bool dname)
        strcpy(pcop->name,aop->aopu.aop_dir);   
        PCOR(pcop)->r = dirregWithName(aop->aopu.aop_dir);
        if(PCOR(pcop)->r == NULL) {
-         fprintf(stderr,"%d - couldn't find %s in allocated registers, size =%d\n",__LINE__,aop->aopu.aop_dir,aop->size);
+         //fprintf(stderr,"%d - couldn't find %s in allocated registers, size =%d\n",__LINE__,aop->aopu.aop_dir,aop->size);
          PCOR(pcop)->r = allocRegByName (aop->aopu.aop_dir,aop->size);
        } 
 
@@ -1334,8 +1334,8 @@ pCodeOp *popGet (asmop *aop, int offset) //, bool bit16, bool dname)
     case AOP_CRY:
       pcop = newpCodeOpBit(aop->aopu.aop_dir,-1,1);
       PCOR(pcop)->r = dirregWithName(aop->aopu.aop_dir);
-      if(PCOR(pcop)->r == NULL)
-       fprintf(stderr,"%d - couldn't find %s in allocated registers\n",__LINE__,aop->aopu.aop_dir);
+      //if(PCOR(pcop)->r == NULL)
+      //fprintf(stderr,"%d - couldn't find %s in allocated registers\n",__LINE__,aop->aopu.aop_dir);
       return pcop;
        
     case AOP_LIT:
@@ -3674,7 +3674,7 @@ static int genChkZeroes(operand *op, int lit,  int size)
 static void genCmp (operand *left,operand *right,
                     operand *result, iCode *ifx, int sign)
 {
-  int size, offset = 0 ;
+  int size; //, offset = 0 ;
   unsigned long lit = 0L,i = 0;
   resolvedIfx rFalseIfx;
   //  resolvedIfx rTrueIfx;
@@ -3702,15 +3702,16 @@ static void genCmp (operand *left,operand *right,
     size = max(AOP_SIZE(left),AOP_SIZE(right));
 
     /* if unsigned char cmp with lit, do cjne left,#right,zz */
-    if((size == 1) && !sign &&
-       (AOP_TYPE(right) == AOP_LIT && AOP_TYPE(left) != AOP_DIR )){
-      symbol *lbl  = newiTempLabel(NULL);
-      pic14_emitcode("cjne","%s,%s,%05d_DS_",
-              aopGet(AOP(left),offset,FALSE,FALSE),
-              aopGet(AOP(right),offset,FALSE,FALSE),
-              lbl->key+100);
-      pic14_emitcode("","%05d_DS_:",lbl->key+100);
-    } else {
+    //if((size == 1) && !sign &&
+    //   (AOP_TYPE(right) == AOP_LIT && AOP_TYPE(left) != AOP_DIR )){
+    //  symbol *lbl  = newiTempLabel(NULL);
+    //  pic14_emitcode("cjne","%s,%s,%05d_DS_",
+    //       aopGet(AOP(left),offset,FALSE,FALSE),
+    //       aopGet(AOP(right),offset,FALSE,FALSE),
+    //       lbl->key+100);
+    //pic14_emitcode("","%05d_DS_:",lbl->key+100);
+    //} else 
+      {
 
       symbol *lbl  = newiTempLabel(NULL);
 
@@ -5867,6 +5868,7 @@ static void genInline (iCode *ic)
         if (*bp == '\n') {
             *bp++ = '\0';
             pic14_emitcode(bp1,"");
+           addpCode2pBlock(pb,newpCodeInlineP(bp1));
             bp1 = bp;
         } else {
             if (*bp == ':') {
@@ -5879,8 +5881,10 @@ static void genInline (iCode *ic)
                 bp++;
         }
     }
-    if (bp1 != bp)
+    if (bp1 != bp) {
         pic14_emitcode(bp1,"");
+       addpCode2pBlock(pb,newpCodeInlineP(bp1));
+    }
     /*     pic14_emitcode("",buffer); */
     _G.inLine -= (!options.asmpeep);
 }
@@ -6121,7 +6125,7 @@ static void shiftR1Left2ResultSigned (operand *left, int offl,
 
   DEBUGpic14_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
 
-  same = (left == result) || (AOP(left) == AOP(result));
+  same = ((left == result) || (AOP(left) == AOP(result))) && (offl == offr);
 
   switch(shCount) {
   case 1:
@@ -6134,6 +6138,90 @@ static void shiftR1Left2ResultSigned (operand *left, int offl,
     }
 
     break;
+  case 2:
+
+    emitpcode(POC_RLFW, popGet(AOP(left),offl));
+    if(same) 
+      emitpcode(POC_RRF, popGet(AOP(result),offr));
+    else {
+      emitpcode(POC_RRFW, popGet(AOP(left),offl));
+      emitpcode(POC_MOVWF, popGet(AOP(result),offr));
+    }
+    emitpcode(POC_RLFW, popGet(AOP(result),offl));
+    emitpcode(POC_RRF,  popGet(AOP(result),offl));
+
+    break;
+
+  case 3:
+    if(same)
+      emitpcode(POC_SWAPF, popGet(AOP(result),offr));
+    else {
+      emitpcode(POC_SWAPFW, popGet(AOP(left),offl));
+      emitpcode(POC_MOVWF, popGet(AOP(result),offr));
+    }
+
+    emitpcode(POC_RLFW,  popGet(AOP(result),offr));
+    emitpcode(POC_RLFW,  popGet(AOP(result),offr));
+    emitpcode(POC_ANDLW, popGetLit(0x1f));
+
+    emitpcode(POC_BTFSC, newpCodeOpBit(aopGet(AOP(result),offr,FALSE,FALSE),3,0));
+    emitpcode(POC_IORLW, popGetLit(0xe0));
+
+    emitpcode(POC_MOVWF, popGet(AOP(result),offr));
+    break;
+
+  case 4:
+    emitpcode(POC_SWAPFW, popGet(AOP(left),offl));
+    emitpcode(POC_ANDLW,  popGetLit(0x0f));
+    emitpcode(POC_BTFSC,  newpCodeOpBit(aopGet(AOP(left),offl,FALSE,FALSE),7,0));
+    emitpcode(POC_IORLW,  popGetLit(0xf0));
+    emitpcode(POC_MOVWF,  popGet(AOP(result),offr));
+    break;
+  case 5:
+    if(same) {
+      emitpcode(POC_SWAPF,  popGet(AOP(result),offr));
+    } else {
+      emitpcode(POC_SWAPFW,  popGet(AOP(result),offr));
+      emitpcode(POC_MOVWF,  popGet(AOP(result),offr));
+    }
+    emitpcode(POC_RRFW,   popGet(AOP(result),offr));
+    emitpcode(POC_ANDLW,  popGetLit(0x07));
+    emitpcode(POC_BTFSC,  newpCodeOpBit(aopGet(AOP(result),offr,FALSE,FALSE),3,0));
+    emitpcode(POC_IORLW,  popGetLit(0xf8));
+    emitpcode(POC_MOVWF,  popGet(AOP(result),offr));
+
+
+
+    break;
+
+  case 6:
+    if(same) {
+      emitpcode(POC_MOVLW, popGetLit(0x00));
+      emitpcode(POC_BTFSC, newpCodeOpBit(aopGet(AOP(left),LSB,FALSE,FALSE),7,0));
+      emitpcode(POC_MOVLW, popGetLit(0xfe));
+      emitpcode(POC_BTFSC, newpCodeOpBit(aopGet(AOP(left),LSB,FALSE,FALSE),6,0));
+      emitpcode(POC_IORLW, popGetLit(0x01));
+      emitpcode(POC_MOVWF, popGet(AOP(result),offr));
+    } else {
+      emitpcode(POC_CLRF,  popGet(AOP(result),offr));
+      emitpcode(POC_BTFSC, newpCodeOpBit(aopGet(AOP(left),offl,FALSE,FALSE),7,0));
+      emitpcode(POC_DECF,  popGet(AOP(result),offr));
+      emitpcode(POC_BTFSS, newpCodeOpBit(aopGet(AOP(left),offl,FALSE,FALSE),6,0));
+      emitpcode(POC_BCF,   newpCodeOpBit(aopGet(AOP(result),offr,FALSE,FALSE),0,0));
+    }
+    break;
+
+  case 7:
+    if(same) {
+      emitpcode(POC_MOVLW, popGetLit(0x00));
+      emitpcode(POC_BTFSC, newpCodeOpBit(aopGet(AOP(left),LSB,FALSE,FALSE),7,0));
+      emitpcode(POC_MOVLW, popGetLit(0xff));
+      emitpcode(POC_MOVWF, popGet(AOP(result),offr));
+    } else {
+      emitpcode(POC_CLRF,  popGet(AOP(result),offr));
+      emitpcode(POC_BTFSC, newpCodeOpBit(aopGet(AOP(left),offl,FALSE,FALSE),7,0));
+      emitpcode(POC_DECF,  popGet(AOP(result),offr));
+    }
 
   default:
     break;
@@ -6184,7 +6272,7 @@ static void shiftR1Left2Result (operand *left, int offl,
 
     break;
   case 3:
-    if(same) 
+    if(same)
       emitpcode(POC_SWAPF, popGet(AOP(result),offr));
     else {
       emitpcode(POC_SWAPFW, popGet(AOP(left),offl));
@@ -6231,19 +6319,6 @@ static void shiftR1Left2Result (operand *left, int offl,
   default:
     break;
   }
-
-
-#if 0
-    
-  MOVA(aopGet(AOP(left),offl,FALSE,FALSE));
-
-  /* shift right accumulator */
-  if(sign)
-    AccSRsh(shCount);
-  else
-    AccRsh(shCount);
-  aopPut(AOP(result),"a",offr);
-#endif
 }
 
 /*-----------------------------------------------------------------*/
@@ -6325,29 +6400,29 @@ static void shiftL1Left2Result (operand *left, int offl,
 static void movLeft2Result (operand *left, int offl,
                             operand *result, int offr, int sign)
 {
-    char *l;
-    DEBUGpic14_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
-    if(!pic14_sameRegs(AOP(left),AOP(result)) || (offl != offr)){
-        l = aopGet(AOP(left),offl,FALSE,FALSE);
+  char *l;
+  DEBUGpic14_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
+  if(!pic14_sameRegs(AOP(left),AOP(result)) || (offl != offr)){
+    l = aopGet(AOP(left),offl,FALSE,FALSE);
 
-        if (*l == '@' && (IS_AOP_PREG(result))) {
-            pic14_emitcode("mov","a,%s",l);
-            aopPut(AOP(result),"a",offr);
-        } else {
-         if(!sign) {
-           emitpcode(POC_MOVFW, popGet(AOP(left),offl));
-           emitpcode(POC_MOVWF, popGet(AOP(result),offr));
-
-           //aopPut(AOP(result),l,offr);
-         }else{
-                /* MSB sign in acc.7 ! */
-                if(pic14_getDataSize(left) == offl+1){
-                    pic14_emitcode("mov","a,%s",l);
-                    aopPut(AOP(result),"a",offr);
-                }
-            }
-        }
+    if (*l == '@' && (IS_AOP_PREG(result))) {
+      pic14_emitcode("mov","a,%s",l);
+      aopPut(AOP(result),"a",offr);
+    } else {
+      //if(!sign) {
+      emitpcode(POC_MOVFW, popGet(AOP(left),offl));
+      emitpcode(POC_MOVWF, popGet(AOP(result),offr));
+
+      //aopPut(AOP(result),l,offr);
+      //}else{
+      /* MSB sign in acc.7 ! */
+      //if(pic14_getDataSize(left) == offl+1){
+      //  pic14_emitcode("mov","a,%s",l);
+      //  aopPut(AOP(result),"a",offr);
+      //}
+      //}
     }
+  }
 }
 
 /*-----------------------------------------------------------------*/
@@ -6542,11 +6617,11 @@ static void shiftR2Left2Result (operand *left, int offl,
       emitpcode(POC_XORWF, popGet(AOP(result),offr+MSB16));
       emitpcode(POC_ADDWF, popGet(AOP(result),offr));
     } else {
-      emitpcode(POC_SWAPFpopGet(AOP(left),offl));
+      emitpcode(POC_SWAPFW,popGet(AOP(left),offl));
       emitpcode(POC_ANDLW, popGetLit(0x0f));
       emitpcode(POC_MOVWF, popGet(AOP(result),offr));
 
-      emitpcode(POC_SWAPFpopGet(AOP(left),offl+MSB16));
+      emitpcode(POC_SWAPFW,popGet(AOP(left),offl+MSB16));
       emitpcode(POC_MOVWF, popGet(AOP(result),offr+MSB16));
       emitpcode(POC_ANDLW, popGetLit(0xf0));
       emitpcode(POC_XORWF, popGet(AOP(result),offr+MSB16));
@@ -7044,25 +7119,27 @@ static void genrshOne (operand *result, operand *left,
 static void genrshTwo (operand *result,operand *left,
                        int shCount, int sign)
 {
-    DEBUGpic14_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
-    /* if shCount >= 8 */
-    if (shCount >= 8) {
-        shCount -= 8 ;
-        if (shCount)
-            shiftR1Left2Result(left, MSB16, result, LSB,
-                               shCount, sign);
-        else 
-            movLeft2Result(left, MSB16, result, LSB, sign);
-       if(sign)
-         addSign(result, MSB16, sign);
-       else
-         emitpcode(POC_CLRF,popGet(AOP(result),MSB16));
+  DEBUGpic14_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
+  /* if shCount >= 8 */
+  if (shCount >= 8) {
+    shCount -= 8 ;
+    if (shCount)
+      shiftR1Left2Result(left, MSB16, result, LSB,
+                        shCount, sign);
+    else
+      movLeft2Result(left, MSB16, result, LSB, sign);
+
+    emitpcode(POC_CLRF,popGet(AOP(result),MSB16));
 
+    if(sign) {
+      emitpcode(POC_BTFSC,newpCodeOpBit(aopGet(AOP(left),LSB,FALSE,FALSE),7,0));
+      emitpcode(POC_DECF, popGet(AOP(result),MSB16));
     }
+  }
 
-    /*  1 <= shCount <= 7 */
-    else
-        shiftR2Left2Result(left, LSB, result, LSB, shCount, sign); 
+  /*  1 <= shCount <= 7 */
+  else
+    shiftR2Left2Result(left, LSB, result, LSB, shCount, sign); 
 }
 
 /*-----------------------------------------------------------------*/
@@ -8217,11 +8294,13 @@ static void genDataPointerSet(operand *right,
     
     l = aopGet(AOP(result),0,FALSE,TRUE);
     size = AOP_SIZE(right);
+/*
     if ( AOP_TYPE(result) == AOP_PCODE) {
       fprintf(stderr,"genDataPointerSet   %s, %d\n",
              AOP(result)->aopu.pcop->name,
              PCOI(AOP(result)->aopu.pcop)->offset);
     }
+*/
 
     // tsd, was l+1 - the underline `_' prefix was being stripped
     while (size--) {
index c1fe76dbd727d92ced168a55e555ea008c84208a..2e1e2b584dca3ebad25c8718a0fd3994306ff8c3 100644 (file)
@@ -70,7 +70,7 @@ static hTab *pic14pCodePeepCommandsHash = NULL;
 
 
 static pFile *the_pFile = NULL;
-static int peepOptimizing = 0;
+static int peepOptimizing = 1;
 static int GpCodeSequenceNumber = 1;
 static int GpcFlowSeq = 1;
 
@@ -101,7 +101,8 @@ static void genericPrint(FILE *of,pCode *pc);
 static void pCodePrintLabel(FILE *of, pCode *pc);
 static void pCodePrintFunction(FILE *of, pCode *pc);
 static void pCodeOpPrint(FILE *of, pCodeOp *pcop);
-static char *get_op( pCodeInstruction *pcc);
+static char *get_op_from_instruction( pCodeInstruction *pcc);
+char *get_op( pCodeOp *pcop);
 int pCodePeepMatchLine(pCodePeep *peepBlock, pCode *pcs, pCode *pcd);
 int pCodePeepMatchRule(pCode *pc);
 void pBlockStats(FILE *of, pBlock *pb);
@@ -1589,6 +1590,36 @@ pCode *newpCodeWild(int pCodeID, pCodeOp *optional_operand, pCodeOp *optional_la
 
   return ( (pCode *)pcw);
   
+}
+
+ /*-----------------------------------------------------------------*/
+/* newPcodeInlineP - create a new pCode from a char string           */
+/*-----------------------------------------------------------------*/
+
+
+pCode *newpCodeInlineP(char *cP)
+{
+
+  pCodeComment *pcc ;
+    
+  pcc = Safe_calloc(1,sizeof(pCodeComment));
+
+  pcc->pc.type = PC_INLINE;
+  pcc->pc.prev = pcc->pc.next = NULL;
+  //pcc->pc.from = pcc->pc.to = pcc->pc.label = NULL;
+  pcc->pc.pb = NULL;
+
+  //  pcc->pc.analyze = genericAnalyze;
+  pcc->pc.destruct = genericDestruct;
+  pcc->pc.print = genericPrint;
+
+  if(cP)
+    pcc->comment = Safe_strdup(cP);
+  else
+    pcc->comment = NULL;
+
+  return ( (pCode *)pcc);
+
 }
 
 /*-----------------------------------------------------------------*/
@@ -1850,7 +1881,7 @@ pCodeOp *newpCodeOpImmd(char *name, int offset, int index, int code_space)
   pcop->type = PO_IMMEDIATE;
   if(name) {
     pcop->name = Safe_strdup(name);
-    fprintf(stderr,"%s %s %d\n",__FUNCTION__,name,offset);
+    //fprintf(stderr,"%s %s %d\n",__FUNCTION__,name,offset);
   } else {
     pcop->name = NULL;
   }
@@ -2163,28 +2194,28 @@ void pBlockRegs(FILE *of, pBlock *pb)
 }
 
 
-static char *get_op( pCodeInstruction *pcc)
+/*-----------------------------------------------------------------*/
+/*-----------------------------------------------------------------*/
+char *get_op(pCodeOp *pcop)
 {
   regs *r;
   static char buffer[50];
   char *s;
   int size;
 
-  if(pcc && pcc->pcop) {
-
 
-    switch(pcc->pcop->type) {
+  if(pcop) {
+    switch(pcop->type) {
     case PO_INDF:
     case PO_FSR:
       //fprintf(stderr,"get_op getting register name rIdx=%d\n",PCOR(pcc->pcop)->rIdx);
       //r = pic14_regWithIdx(PCOR(pcc->pcop)->rIdx);
       //return r->name;
-      return PCOR(pcc->pcop)->r->name;
+      return PCOR(pcop)->r->name;
       break;
     case PO_GPR_TEMP:
-      r = pic14_regWithIdx(PCOR(pcc->pcop)->r->rIdx);
+      r = pic14_regWithIdx(PCOR(pcop)->r->rIdx);
       //fprintf(stderr,"getop: getting %s\nfrom:\n",r->name); //pcc->pcop->name);
-      pBlockRegs(stderr,pcc->pc.pb);
       return r->name;
 
       //    case PO_GPR_BIT:
@@ -2192,25 +2223,24 @@ static char *get_op( pCodeInstruction *pcc)
     case PO_IMMEDIATE:
       s = buffer;
       size = sizeof(buffer);
-      fprintf(stderr,"PO_IMMEDIATE name = %s  offset = %d\n",pcc->pcop->name,
-             PCOI(pcc->pcop)->offset);
-      if(PCOI(pcc->pcop)->_const) {
+      //fprintf(stderr,"PO_IMMEDIATE name = %s  offset = %d\n",pcc->pcop->name,PCOI(pcc->pcop)->offset);
+      if(PCOI(pcop)->_const) {
 
-       if( PCOI(pcc->pcop)->offset && PCOI(pcc->pcop)->offset<4) {
+       if( PCOI(pcop)->offset && PCOI(pcop)->offset<4) {
          SAFE_snprintf(&s,&size,"(((%s+%d) >> %d)&0xff)",
-                       pcc->pcop->name,
-                       PCOI(pcc->pcop)->index,
-                       8 * PCOI(pcc->pcop)->offset );
+                       pcop->name,
+                       PCOI(pcop)->index,
+                       8 * PCOI(pcop)->offset );
        } else
-         SAFE_snprintf(&s,&size,"LOW(%s+%d)",pcc->pcop->name,PCOI(pcc->pcop)->index);
+         SAFE_snprintf(&s,&size,"LOW(%s+%d)",pcop->name,PCOI(pcop)->index);
       } else {
       
-       if( PCOI(pcc->pcop)->index) { // && PCOI(pcc->pcop)->offset<4) {
+       if( PCOI(pcop)->index) { // && PCOI(pcc->pcop)->offset<4) {
          SAFE_snprintf(&s,&size,"(%s + %d)",
-                       pcc->pcop->name,
-                       PCOI(pcc->pcop)->index );
+                       pcop->name,
+                       PCOI(pcop)->index );
        } else
-         SAFE_snprintf(&s,&size,"%s",pcc->pcop->name);
+         SAFE_snprintf(&s,&size,"%s",pcop->name);
       }
 
       return buffer;
@@ -2218,23 +2248,36 @@ static char *get_op( pCodeInstruction *pcc)
     case PO_DIR:
       s = buffer;
       size = sizeof(buffer);
-      if( PCOR(pcc->pcop)->instance) {
+      if( PCOR(pcop)->instance) {
        SAFE_snprintf(&s,&size,"(%s + %d)",
-                     pcc->pcop->name,
-                     PCOR(pcc->pcop)->instance );
-       fprintf(stderr,"PO_DIR %s\n",buffer);
+                     pcop->name,
+                     PCOR(pcop)->instance );
+       //fprintf(stderr,"PO_DIR %s\n",buffer);
       } else
-       SAFE_snprintf(&s,&size,"%s",pcc->pcop->name);
+       SAFE_snprintf(&s,&size,"%s",pcop->name);
       return buffer;
 
     default:
-      if  (pcc->pcop->name)
-       return pcc->pcop->name;
+      if  (pcop->name)
+       return pcop->name;
 
     }
   }
 
   return "NO operand";
+
+}
+
+/*-----------------------------------------------------------------*/
+/*-----------------------------------------------------------------*/
+static char *get_op_from_instruction( pCodeInstruction *pcc)
+{
+
+  if(pcc )
+    return get_op(pcc->pcop);
+  
+  return ("ERROR Null: "__FUNCTION__);
+
 }
 
 /*-----------------------------------------------------------------*/
@@ -2264,23 +2307,23 @@ char *pCode2str(char *str, int size, pCode *pc)
                          PCI(pc)->pcop->name ,
                          PCI(pc)->pcop->name );
          else
-           SAFE_snprintf(&s,&size,"%s,%d", get_op(PCI(pc)), 
+           SAFE_snprintf(&s,&size,"%s,%d", get_op_from_instruction(PCI(pc)), 
                          (((pCodeOpRegBit *)(PCI(pc)->pcop))->bit ));
        } else if(PCI(pc)->pcop->type == PO_GPR_BIT) {
-         SAFE_snprintf(&s,&size,"%s,%d", get_op(PCI(pc)),PCORB(PCI(pc)->pcop)->bit);
+         SAFE_snprintf(&s,&size,"%s,%d", get_op_from_instruction(PCI(pc)),PCORB(PCI(pc)->pcop)->bit);
        }else
-         SAFE_snprintf(&s,&size,"%s,0 ; ?bug", get_op(PCI(pc)));
+         SAFE_snprintf(&s,&size,"%s,0 ; ?bug", get_op_from_instruction(PCI(pc)));
        //PCI(pc)->pcop->t.bit );
       } else {
 
        if(PCI(pc)->pcop->type == PO_GPR_BIT) {
          if( PCI(pc)->num_ops == 2)
-           SAFE_snprintf(&s,&size,"(%s >> 3),%c",get_op(PCI(pc)),((PCI(pc)->isModReg) ? 'F':'W'));
+           SAFE_snprintf(&s,&size,"(%s >> 3),%c",get_op_from_instruction(PCI(pc)),((PCI(pc)->isModReg) ? 'F':'W'));
          else
-           SAFE_snprintf(&s,&size,"(1 << (%s & 7))",get_op(PCI(pc)));
+           SAFE_snprintf(&s,&size,"(1 << (%s & 7))",get_op_from_instruction(PCI(pc)));
 
        }else {
-         SAFE_snprintf(&s,&size,"%s",get_op(PCI(pc)));
+         SAFE_snprintf(&s,&size,"%s",get_op_from_instruction(PCI(pc)));
 
          if( PCI(pc)->num_ops == 2)
            SAFE_snprintf(&s,&size,",%c", ( (PCI(pc)->isModReg) ? 'F':'W'));
@@ -2295,6 +2338,11 @@ char *pCode2str(char *str, int size, pCode *pc)
     SAFE_snprintf(&s,&size,";%s", ((pCodeComment *)pc)->comment);
     break;
 
+  case PC_INLINE:
+    /* assuming that inline code ends with a \n */
+    SAFE_snprintf(&s,&size,"%s", ((pCodeComment *)pc)->comment);
+    break;
+
   case PC_LABEL:
     SAFE_snprintf(&s,&size,";label=%s, key=%d\n",PCL(pc)->label,PCL(pc)->key);
     break;
@@ -2327,6 +2375,10 @@ static void genericPrint(FILE *of, pCode *pc)
     fprintf(of,";%s\n", ((pCodeComment *)pc)->comment);
     break;
 
+  case PC_INLINE:
+    fprintf(of,"%s\n", ((pCodeComment *)pc)->comment);
+     break;
+
   case PC_OPCODE:
     // If the opcode has a label, print that first
     {
@@ -2831,27 +2883,26 @@ regs * getRegFromInstruction(pCode *pc)
 
   case PO_BIT:
   case PO_GPR_TEMP:
-    fprintf(stderr, "getRegFromInstruction - bit or temp\n");
+    //fprintf(stderr, "getRegFromInstruction - bit or temp\n");
     return PCOR(PCI(pc)->pcop)->r;
 
   case PO_IMMEDIATE:
-    fprintf(stderr, "getRegFromInstruction - immediate\n");
+    //fprintf(stderr, "getRegFromInstruction - immediate\n");
     return NULL; // PCOR(PCI(pc)->pcop)->r;
 
   case PO_GPR_BIT:
     return PCOR(PCI(pc)->pcop)->r;
 
   case PO_DIR:
-    fprintf(stderr, "getRegFromInstruction - dir\n");
-    //return NULL; PCOR(PCI(pc)->pcop)->r;
+    //fprintf(stderr, "getRegFromInstruction - dir\n");
     return PCOR(PCI(pc)->pcop)->r;
   case PO_LITERAL:
-    fprintf(stderr, "getRegFromInstruction - literal\n");
+    //fprintf(stderr, "getRegFromInstruction - literal\n");
     break;
 
   default:
-    fprintf(stderr, "getRegFromInstruction - unknown reg type %d\n",PCI(pc)->pcop->type);
-    genericPrint(stderr, pc);
+    //fprintf(stderr, "getRegFromInstruction - unknown reg type %d\n",PCI(pc)->pcop->type);
+    //genericPrint(stderr, pc);
     break;
   }
 
@@ -3380,7 +3431,7 @@ void FixRegisterBanking(pBlock *pb)
 
   int cur_bank;
   regs *reg;
-  return;
+  //  return;
   if(!pb)
     return;
 
@@ -3389,7 +3440,7 @@ void FixRegisterBanking(pBlock *pb)
     return;
   /* loop through all of the flow blocks with in one pblock */
 
-  //  fprintf(stderr,"Register banking\n");
+  //fprintf(stderr,"Register banking\n");
   cur_bank = 0;
   do {
     /* at this point, pc should point to a PC_FLOW object */
@@ -3400,21 +3451,21 @@ void FixRegisterBanking(pBlock *pb)
 
     do {
       if(isPCI(pc)) {
-    genericPrint(stderr, pc);
+       //genericPrint(stderr, pc);
 
        reg = getRegFromInstruction(pc);
-       //#if 0
+       #if 0
        if(reg) {
          fprintf(stderr, "  %s  ",reg->name);
          fprintf(stderr, "addr = 0x%03x, bank = %d\n",reg->address,REG_BANK(reg));
 
        }
-       //#endif
+       #endif
        if(reg && REG_BANK(reg)!=cur_bank) {
          /* Examine the instruction before this one to make sure it is
           * not a skip type instruction */
          pcprev = findPrevpCode(pc->prev, PC_OPCODE);
-         if(pcprev && !isPCI_SKIP(pcprev)) {
+         if(!pcprev || (pcprev && !isPCI_SKIP(pcprev))) {
            int b = cur_bank ^ REG_BANK(reg);
 
            //fprintf(stderr, "Cool! can switch banks\n");
@@ -3435,8 +3486,10 @@ void FixRegisterBanking(pBlock *pb)
 
            }
 
-         } else
-           fprintf(stderr, "Bummer can't switch banks\n");
+         } else {
+           //fprintf(stderr, "Bummer can't switch banks\n");
+           ;
+         }
        }
       }
 
@@ -3792,7 +3845,7 @@ void pBlockStats(FILE *of, pBlock *pb)
 
     while(pc) {
       if(pc->type == PC_OPCODE && PCI(pc)->op == POC_CALL) {
-       fprintf(of,";   %s\n",get_op(PCI(pc)));
+       fprintf(of,";   %s\n",get_op_from_instruction(PCI(pc)));
       }
       pc = setNextItem(pb->function_calls);
     }
@@ -3853,7 +3906,7 @@ set *register_usage(pBlock *pb)
   for( ; pc; pc = setNextItem(pb->function_calls)) {
 
     if(pc->type == PC_OPCODE && PCI(pc)->op == POC_CALL) {
-      char *dest = get_op(PCI(pc));
+      char *dest = get_op_from_instruction(PCI(pc));
 
       pcn = findFunction(dest);
       if(pcn) 
@@ -3975,7 +4028,7 @@ void pct2(FILE *of,pBlock *pb,int indent)
   for( ; pc; pc = setNextItem(pb->function_calls)) {
 
     if(pc->type == PC_OPCODE && PCI(pc)->op == POC_CALL) {
-      char *dest = get_op(PCI(pc));
+      char *dest = get_op_from_instruction(PCI(pc));
 
       pcn = findFunction(dest);
       if(pcn) 
@@ -4097,7 +4150,7 @@ void printCallTree(FILE *of)
       while(pc->next && !ispCodeFunction(pc->next)) {
        pc = pc->next;
        if(pc->type == PC_OPCODE && PCI(pc)->op == POC_CALL)
-         fprintf(of,"\t%s\n",get_op(PCI(pc)));
+         fprintf(of,"\t%s\n",get_op_from_instruction(PCI(pc)));
       }
     }
 
index 007b9a50d5dd1a367e6c2a5415609eeefa0f55bd..55a5e7442ea856c2e8b9df86f50f3f5001e39523 100644 (file)
@@ -228,6 +228,7 @@ typedef enum
 typedef enum
 {
   PC_COMMENT=0,   /* pCode is a comment     */
+  PC_INLINE,      /* user's inline code     */
   PC_OPCODE,      /* PORT dependent opcode  */
   PC_LABEL,       /* assembly label         */
   PC_FLOW,        /* flow analysis          */
@@ -694,6 +695,7 @@ typedef struct peepCommand {
 
 pCode *newpCode (PIC_OPCODE op, pCodeOp *pcop); // Create a new pCode given an operand
 pCode *newpCodeCharP(char *cP);              // Create a new pCode given a char *
+pCode *newpCodeInlineP(char *cP);            // Create a new pCode given a char *
 pCode *newpCodeFunction(char *g, char *f);   // Create a new function
 pCode *newpCodeLabel(char *name,int key);    // Create a new label given a key
 pBlock *newpCodeChain(memmap *cm,char c, pCode *pc); // Create a new pBlock
index ba65ceb5ffd5aa32c74e74f72682b6ef4c907889..a6d1e862a864f06555cbf12158e689826bd35bb3 100644 (file)
@@ -45,6 +45,7 @@ int getpCode(char *mnem,int dest);
 int getpCodePeepCommand(char *cmd);
 void pBlockMergeLabels(pBlock *pb);
 char *pCode2str(char *str, int size, pCode *pc);
+char *get_op( pCodeOp *pcop);
 
 extern pCodeInstruction *pic14Mnemonics[];
 
@@ -1403,6 +1404,49 @@ int pCodeSearchCondition(pCode *pc, unsigned int cond)
   return 0;
 }
 
+/*-----------------------------------------------------------------
+ * int pCodeOpCompare(pCodeOp *pcops, pCodeOp *pcopd)
+ *
+ * Compare two pCodeOp's and return 1 if they're the same
+ *-----------------------------------------------------------------*/
+int pCodeOpCompare(pCodeOp *pcops, pCodeOp *pcopd)
+{
+
+  if(!pcops || !pcopd)
+    return 0;
+
+  fprintf(stderr," Comparing operands %s",
+         get_op( pcops));
+
+  fprintf(stderr," to %s\n",
+         get_op( pcopd));
+
+  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");
+    return 0;  // different names
+  }
+
+  switch(pcops->type) {
+  case PO_DIR:
+    if( PCOR(pcops)->instance != PCOR(pcopd)->instance) {
+      fprintf(stderr, "  - fail different instances\n");
+      return 0;
+    }
+    break;
+  default:
+    break;
+  }
+
+  fprintf(stderr,"  - pass\n");
+
+  return 1;
+}
+
 int pCodePeepMatchLabels(pCodePeep *peepBlock, pCode *pcs, pCode *pcd)
 {
   int labindex;
@@ -1504,13 +1548,24 @@ int pCodePeepMatchLine(pCodePeep *peepBlock, pCode *pcs, pCode *pcd)
            exit(1);
          }
 #endif
+
          PCOW(PCI(pcd)->pcop)->matched = PCI(pcs)->pcop;
          if(!peepBlock->target.wildpCodeOps[index]) {
            peepBlock->target.wildpCodeOps[index] = PCI(pcs)->pcop;
 
            //if(PCI(pcs)->pcop->type == PO_GPR_TEMP) 
 
+         } else {
+           pcs->print(stderr,pcs);
+           pcd->print(stderr,pcd);
+
+           fprintf(stderr, "comparing operands of these instructions, result %d\n",
+                   pCodeOpCompare(PCI(pcs)->pcop, peepBlock->target.wildpCodeOps[index])
+                   );
+
+           return pCodeOpCompare(PCI(pcs)->pcop, peepBlock->target.wildpCodeOps[index]);
          }
+
          {
            char *n;
 
@@ -1533,6 +1588,7 @@ int pCodePeepMatchLine(pCodePeep *peepBlock, pCode *pcs, pCode *pcd)
              return 1;
            }
          }
+
        }
        /* FIXME - need an else to check the case when the destination 
         * isn't a wild card */
@@ -1717,12 +1773,16 @@ pCodeOp *pCodeOpCopy(pCodeOp *pcop)
     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"));
index c0554c039cc9a00759d4df1dc76d2c7e9123d918..58258c9a5d26c27d751e29679cf5d01be7940b86 100644 (file)
@@ -2260,7 +2260,7 @@ rematStr (symbol * sym)
 
   debugLog ("%s\n", __FUNCTION__);
 
-  printf ("%s\n", s);
+  //printf ("%s\n", s);
 
   /* if plus or minus print the right hand side */
 
@@ -2274,7 +2274,7 @@ rematStr (symbol * sym)
             (int) operandLitValue (IC_RIGHT (ic)));
 
 
-    fprintf(stderr, "ralloc.c:%d OOPS %s\n",__LINE__,s);
+    //fprintf(stderr, "ralloc.c:%d OOPS %s\n",__LINE__,s);
 
     psym = newSymbol (OP_SYMBOL (IC_LEFT (ric))->rname, 1);
     psym->offset = (int) operandLitValue (IC_RIGHT (ic));
@@ -2285,7 +2285,7 @@ rematStr (symbol * sym)
   sprintf (s, "%s", OP_SYMBOL (IC_LEFT (ic))->rname);
   psym = newSymbol (OP_SYMBOL (IC_LEFT (ic))->rname, 1);
 
-  printf ("%s\n", buffer);
+  //printf ("ralloc.c:%d %s\n", __LINE__,buffer);
   return psym;
 }
 
index 6561def8418eb6749d7f05368d12a4957e5fc3b9..ecce4316f90a26dcf2be0cfae662420629a948fd 100644 (file)
@@ -80,6 +80,7 @@ SRC = b.c \
        rotate2.c \
        rotate3.c \
        rotate4.c \
+       rotate5.c \
        struct1.c \
        sub.c \
        sub2.c \
diff --git a/src/regression/mult1.c b/src/regression/mult1.c
new file mode 100644 (file)
index 0000000..6bf36e4
--- /dev/null
@@ -0,0 +1,63 @@
+unsigned char success=0;
+unsigned char failures=0;
+unsigned char dummy=0;
+
+
+signed char c1,c2,c3;
+unsigned char uc1,uc2,uc3;
+
+unsigned int ui1,ui2,ui3;
+signed int i1,i2;
+
+void done()
+{
+
+  dummy++;
+
+}
+
+void m1(void)
+{
+
+  c1 = c1*5;       // char = char * lit
+
+  c2 = c1 *c3;     // char = char * char
+
+  uc1= uc1*5;      // uchar = uchar * lit
+  uc2=uc1*uc3;     // uchar = uchar * uchar
+
+  if(c2 != 25)
+    failures++;
+}
+
+void m2(unsigned char uc)
+{
+
+  uc2 = uc1 * uc;
+
+  if(uc2 != 0x20)
+    failures++;
+}
+
+void main(void)
+{
+  dummy = 0;
+
+  c1 = 1;
+  c3 = 5;
+
+  //m1();
+
+  uc1 = 0x10;
+  m2(2);
+
+  ui1 = uc1*uc2;   // uint = uchar * uchar
+
+  i1 = c1*c2;      // int = char * char
+
+  ui3 = ui1*ui2;   // uint = uint * unit
+
+
+  success = failures;
+  done();
+}
diff --git a/src/regression/rotate5.c b/src/regression/rotate5.c
new file mode 100644 (file)
index 0000000..c7446b2
--- /dev/null
@@ -0,0 +1,212 @@
+// Shift bytes left and right by a constant.
+
+unsigned char success=0;
+unsigned char failures=0;
+unsigned char dummy=0;
+
+bit bit0 = 0;
+signed int aint0 = 0;
+signed int aint1 = 0;
+signed char achar0 = 0;
+signed char achar1 = 0;
+signed char achar2 = 0;
+
+void done()
+{
+
+  dummy++;
+
+}
+
+void check(void)
+{
+  if(achar0 != achar1)
+    failures++;
+}
+
+void shift_left_1(void)
+{
+
+  achar0 <<= 1;
+
+  check();
+}
+
+void shift_left_2(void)
+{
+
+  achar0 <<= 2;
+
+  if(achar0 != achar1)
+    failures++;
+}
+
+
+void shift_left_3(void)
+{
+
+  achar0 <<= 3;
+
+  if(achar0 != achar1)
+    failures++;
+}
+
+void shift_left_4(void)
+{
+
+  achar0 <<= 4;
+
+  if(achar0 != achar1)
+    failures++;
+}
+
+void shift_left_5(void)
+{
+
+  achar0 <<= 5;
+
+  if(achar0 != achar1)
+    failures++;
+}
+
+void shift_left_6(void)
+{
+
+  achar0 <<= 6;
+
+  if(achar0 != achar1)
+    failures++;
+}
+
+void shift_left_7(void)
+{
+
+  achar0 <<= 7;
+
+  if(achar0 != achar1)
+    failures++;
+}
+
+void shift_right_1(void)
+{
+
+  achar0 >>= 1;
+
+  check();
+}
+
+void shift_right_2(void)
+{
+
+  achar0 >>= 2;
+
+  check();
+}
+
+void shift_right_3(void)
+{
+
+  achar0 >>= 3;
+
+  check();
+}
+
+void shift_right_4(void)
+{
+
+  achar0 >>= 4;
+
+  check();
+}
+
+void shift_right_5(void)
+{
+
+  achar0 >>= 5;
+
+  check();
+}
+
+void shift_right_6(void)
+{
+
+  achar0 >>= 6;
+
+  check();
+}
+
+void shift_right_7(void)
+{
+
+  achar0 >>= 7;
+
+  check();
+}
+
+
+void main(void)
+{
+
+  // call with both values zero
+  shift_left_1();
+
+  achar0 = 1;
+  achar1 = 2;
+  for(achar2=0; achar2<6; achar2++) {
+    shift_left_1();
+    achar1 <<=1;
+  }
+
+  achar0 = 1;
+  achar1 = 4;
+  shift_left_2();
+
+  achar0 = 1;
+  achar1 = 8;
+  shift_left_3();
+
+  achar0 = 1;
+  achar1 = 0x10;
+  shift_left_4();
+
+  achar0 = 1;
+  achar1 = 0x20;
+  shift_left_5();
+
+  achar0 = 1;
+  achar1 = 0x40;
+  shift_left_6();
+
+  achar0 = 1;
+  achar1 = 0x80;
+  shift_left_7();
+
+
+
+
+  achar0 = 2;
+  achar1 = 1;
+  shift_right_1();
+
+  achar0 = 4;
+  shift_right_2();
+
+  achar0 = 8;
+  shift_right_3();
+
+  achar0 = 0x10;
+  shift_right_4();
+
+  achar0 = 0x20;
+  shift_right_5();
+
+  achar0 = 0x40;
+  shift_right_6();
+
+  achar0 = 0x80;
+  achar1 = 0xff;
+  shift_right_7();
+
+  success=failures;
+  done();
+}