Fixed some pointer bugs. Added option to selectively enable/disable function inlining.
authorsdattalo <sdattalo@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Mon, 17 Jun 2002 05:12:11 +0000 (05:12 +0000)
committersdattalo <sdattalo@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Mon, 17 Jun 2002 05:12:11 +0000 (05:12 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2024 4a8a32a2-be11-0410-ad9d-d568d2c75423

src/pic/gen.c
src/pic/gen.h
src/pic/genarith.c
src/pic/pcode.c

index 4ae2f23c69dd9cb61c7b04fd5cc2ec818ec1393f..b734cf6ade538ca62eeaa3b5d1873d87afb905ab 100644 (file)
@@ -824,13 +824,22 @@ void aopOp (operand *op, iCode *ic, bool result)
        }
 
         if (sym->ruonly ) {
-            unsigned i;
-            aop = op->aop = sym->aop = newAsmop(AOP_STR);
-            aop->size = getSize(sym->type);
-            for ( i = 0 ; i < fReturnSizePic ; i++ )
-             aop->aopu.aop_str[i] = fReturn[i];
-           DEBUGpic14_emitcode(";","%d",__LINE__);
-            return;
+         /*
+         sym->aop = op->aop = aop = newAsmop(AOP_PCODE);
+         aop->aopu.pcop = popGetImmd(sym->usl.spillLoc->rname,0,sym->usl.spillLoc->offset);
+         //allocDirReg (IC_LEFT(ic));
+         aop->size = getSize(sym->type);
+         */
+
+         unsigned i;
+
+         aop = op->aop = sym->aop = newAsmop(AOP_STR);
+         aop->size = getSize(sym->type);
+         for ( i = 0 ; i < fReturnSizePic ; i++ )
+           aop->aopu.aop_str[i] = fReturn[i];
+
+         DEBUGpic14_emitcode(";","%d",__LINE__);
+         return;
         }
 
         /* else spill location  */
@@ -842,10 +851,12 @@ void aopOp (operand *op, iCode *ic, bool result)
                            __FUNCTION__,__LINE__,
                            sym->usl.spillLoc->rname,
                            sym->rname, sym->usl.spillLoc->offset);
-        // X sym->aop = op->aop = aop = aopForSym(ic,sym->usl.spillLoc,result);
+
        sym->aop = op->aop = aop = newAsmop(AOP_PCODE);
-       aop->aopu.pcop = popGetImmd(sym->usl.spillLoc->rname,0,sym->usl.spillLoc->offset);
-       //allocDirReg (IC_LEFT(ic));
+       //aop->aopu.pcop = popGetImmd(sym->usl.spillLoc->rname,0,sym->usl.spillLoc->offset);
+       aop->aopu.pcop = popRegFromString(sym->usl.spillLoc->rname, 
+                                         getSize(sym->type), 
+                                         sym->usl.spillLoc->offset);
         aop->size = getSize(sym->type);
 
         return;
@@ -858,6 +869,7 @@ void aopOp (operand *op, iCode *ic, bool result)
     }
 
     /* must be in a register */
+    DEBUGpic14_emitcode(";","%d register type nRegs=%d",__LINE__,sym->nRegs);
     sym->aop = op->aop = aop = newAsmop(AOP_REG);
     aop->size = sym->nRegs;
     for ( i = 0 ; i < sym->nRegs ;i++)
@@ -1105,7 +1117,7 @@ char *aopGet (asmop *aop, int offset, bool bit16, bool dname)
     case AOP_PCODE:
       {
        pCodeOp *pcop = aop->aopu.pcop;
-       DEBUGpic14_emitcode(";","%d: aopGet AOP_PCODE",__LINE__);
+       DEBUGpic14_emitcode(";","%d: aopGet AOP_PCODE type %s",__LINE__,pCodeOpType(pcop));
        if(pcop->name) {
          DEBUGpic14_emitcode(";","%s offset %d",pcop->name,PCOI(pcop)->offset);
          //sprintf(s,"(%s+0x%02x)", pcop->name,PCOI(aop->aopu.pcop)->offset);
@@ -1228,14 +1240,34 @@ pCodeOp *popGetWithString(char *str)
   return pcop;
 }
 
-pCodeOp *popRegFromString(char *str)
+/*-----------------------------------------------------------------*/
+/* popRegFromString -                                              */
+/*-----------------------------------------------------------------*/
+pCodeOp *popRegFromString(char *str, int size, int offset)
 {
 
-  pCodeOp *pcop = Safe_calloc(1,sizeof(pCodeOp) );
+  pCodeOp *pcop = Safe_calloc(1,sizeof(pCodeOpReg) );
   pcop->type = PO_DIR;
 
   DEBUGpic14_emitcode(";","%d",__LINE__);
-  pcop->name = Safe_strdup( ( (str) ? str : "BAD STRING"));
+
+  if(!str)
+    str = "BAD_STRING";
+
+  pcop->name = Safe_calloc(1,strlen(str)+1);
+  strcpy(pcop->name,str);
+
+  //pcop->name = Safe_strdup( ( (str) ? str : "BAD STRING"));
+
+  PCOR(pcop)->r = dirregWithName(pcop->name);
+  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);
+    PCOR(pcop)->r = allocRegByName (pcop->name,size);
+    DEBUGpic14_emitcode(";","%d  %s   offset=%d - had to alloc by reg name",__LINE__,pcop->name,offset);
+  } else {
+    DEBUGpic14_emitcode(";","%d  %s   offset=%d",__LINE__,pcop->name,offset);
+  }
+  PCOR(pcop)->instance = offset;
 
   return pcop;
 }
@@ -1293,6 +1325,8 @@ pCodeOp *popGet (asmop *aop, int offset) //, bool bit16, bool dname)
       return popGetImmd(aop->aopu.aop_immd,offset,0);
 
     case AOP_DIR:
+      return popRegFromString(aop->aopu.aop_dir, aop->size, offset);
+#if 0
        pcop = Safe_calloc(1,sizeof(pCodeOpReg) );
        pcop->type = PO_DIR;
 
@@ -1319,6 +1353,7 @@ pCodeOp *popGet (asmop *aop, int offset) //, bool bit16, bool dname)
        PCOR(pcop)->instance = offset;
 
        return pcop;
+#endif
        
     case AOP_REG:
       {
@@ -1361,7 +1396,8 @@ pCodeOp *popGet (asmop *aop, int offset) //, bool bit16, bool dname)
       */
 
     case AOP_PCODE:
-      DEBUGpic14_emitcode(";","popGet AOP_PCODE %d %s",__LINE__, 
+      DEBUGpic14_emitcode(";","popGet AOP_PCODE (%s) %d %s",pCodeOpType(aop->aopu.pcop),
+                         __LINE__, 
                          ((aop->aopu.pcop->name)? (aop->aopu.pcop->name) : "no name"));
       pcop = pCodeOpCopy(aop->aopu.pcop);
       PCOI(pcop)->offset = offset;
@@ -1603,6 +1639,23 @@ void aopPut (asmop *aop, char *s, int offset)
 
 }
 
+/*-----------------------------------------------------------------*/
+/* mov2w - generate either a MOVLW or MOVFW based operand type     */
+/*-----------------------------------------------------------------*/
+void mov2w (asmop *aop, int offset)
+{
+
+  if(!aop)
+    return;
+
+  if ( aop->type == AOP_PCODE ||
+       aop->type == AOP_LIT )
+    emitpcode(POC_MOVLW,popGet(aop,offset));
+  else
+    emitpcode(POC_MOVFW,popGet(aop,offset));
+
+}
+
 /*-----------------------------------------------------------------*/
 /* reAdjustPreg - points a register back to where it should        */
 /*-----------------------------------------------------------------*/
@@ -2369,13 +2422,14 @@ static void genCall (iCode *ic)
        firstTimeThruLoop=0;
 
        //if (strcmp(l,fReturn[offset])) {
-
+       mov2w (AOP(IC_LEFT(sic)),  offset);
+/*
        if ( ((AOP(IC_LEFT(sic))->type) == AOP_PCODE) ||
             ((AOP(IC_LEFT(sic))->type) == AOP_LIT) )
          emitpcode(POC_MOVLW,popGet(AOP(IC_LEFT(sic)),offset));
        else
          emitpcode(POC_MOVFW,popGet(AOP(IC_LEFT(sic)),offset));
-
+*/
        //}
        offset++;
       }
@@ -8898,16 +8952,21 @@ static void genGenPointerSet (operand *right,
     size = AOP_SIZE(right);
     offset = 0 ;
 
-    while (--size) {
-      //char *l = aopGet(AOP(right),offset++,FALSE,FALSE);
-      if(size)
-       pic14_emitcode("incf","fsr,f");
-      pic14_emitcode("movf","%s,w",aopGet(AOP(right),offset++,FALSE,FALSE));
-      pic14_emitcode("movwf","indf");
-      //MOVA(l);
-      //DEBUGpic14_emitcode(";lcall","__gptrput");
-      //if (size)
-      //    pic14_emitcode("inc","dptr");
+  DEBUGpic14_emitcode ("; ***","%s  %d size=%d",__FUNCTION__,__LINE__,size);
+
+    while (size--) {
+
+      emitpcode(POC_MOVFW,popGet(AOP(result),offset));
+      emitpcode(POC_MOVWF,popCopyReg(&pc_fsr));
+
+      if (AOP_TYPE(right) == AOP_LIT) 
+       emitpcode(POC_MOVLW, popGet(AOP(right),offset));
+      else
+       emitpcode(POC_MOVFW, popGet(AOP(right),offset));
+
+      emitpcode(POC_MOVWF,popCopyReg(&pc_indf));
+
+      offset++;
     }
   }
 
index f256aa72d295e54c19db38a93f164d5522fd9d3e..36c5d15705a17a596054acc9f6a22c21c18d2899 100644 (file)
@@ -163,7 +163,7 @@ pCodeOp *popCopyReg(pCodeOpReg *pc);
 pCodeOp *popCopyGPR2Bit(pCodeOp *pc, int bitval);
 pCodeOp *popGetLit(unsigned int lit);
 pCodeOp *popGetWithString(char *str);
-pCodeOp *popRegFromString(char *str);
+pCodeOp *popRegFromString(char *str, int size, int offset);
 pCodeOp *popGet (asmop *aop, int offset);//, bool bit16, bool dname);
 pCodeOp *popGetTempReg(void);
 void popReleaseTempReg(pCodeOp *pcop);
@@ -175,6 +175,8 @@ void aopOp (operand *op, iCode *ic, bool result);
 void pic14_outBitC(operand *result);
 void pic14_toBoolean(operand *oper);
 void freeAsmop (operand *op, asmop *aaop, iCode *ic, bool pop);
+void mov2w (asmop *aop, int offset);
+const char *pCodeOpType(  pCodeOp *pcop);
 
 
 
index 8b4aa9646260532df65ed693de1a09ff6097bc7a..fb6b94980374aaadcc76acd1d4c10498933a2299 100644 (file)
@@ -113,6 +113,60 @@ const char *AopType(short type)
 
   return "BAD TYPE";
 }
+
+const char *pCodeOpType(  pCodeOp *pcop)
+{
+
+  if(pcop) {
+
+    switch(pcop->type) {
+
+    case  PO_NONE:
+      return "PO_NONE";
+    case  PO_W:
+      return  "PO_W";
+    case  PO_STATUS:
+      return  "PO_STATUS";
+    case  PO_FSR:
+      return  "PO_FSR";
+    case  PO_INDF:
+      return  "PO_INDF";
+    case  PO_INTCON:
+      return  "PO_INTCON";
+    case  PO_GPR_REGISTER:
+      return  "PO_GPR_REGISTER";
+    case  PO_GPR_BIT:
+      return  "PO_GPR_BIT";
+    case  PO_GPR_TEMP:
+      return  "PO_GPR_TEMP";
+    case  PO_SFR_REGISTER:
+      return  "PO_SFR_REGISTER";
+    case  PO_PCL:
+      return  "PO_PCL";
+    case  PO_PCLATH:
+      return  "PO_PCLATH";
+    case  PO_LITERAL:
+      return  "PO_LITERAL";
+    case  PO_IMMEDIATE:
+      return  "PO_IMMEDIATE";
+    case  PO_DIR:
+      return  "PO_DIR";
+    case  PO_CRY:
+      return  "PO_CRY";
+    case  PO_BIT:
+      return  "PO_BIT";
+    case  PO_STR:
+      return  "PO_STR";
+    case  PO_LABEL:
+      return  "PO_LABEL";
+    case  PO_WILD:
+      return  "PO_WILD";
+    }
+  }
+
+  return "BAD PO_TYPE";
+}
+
 /*-----------------------------------------------------------------*/
 /* genPlusIncr :- does addition with increment if possible         */
 /*-----------------------------------------------------------------*/
index 1bdeb311061dc8458873bf2539a70a8f4ccc1c63..bb3ac5ac077085779b6be6b07e2e4dadcef06423 100644 (file)
@@ -70,7 +70,11 @@ static hTab *pic14pCodePeepCommandsHash = NULL;
 
 
 static pFile *the_pFile = NULL;
-static int peepOptimizing = 1;
+
+/* Hardcoded flags to change the behavior of the PIC port */
+static int peepOptimizing = 1;        /* run the peephole optimizer if nonzero */
+static int functionInlining = 1;      /* inline functions if nonzero */
+
 static int GpCodeSequenceNumber = 1;
 static int GpcFlowSeq = 1;
 
@@ -5176,6 +5180,8 @@ void InlinepCode(void)
   if(!the_pFile)
     return;
 
+  if(!functionInlining)
+    return;
 
   /* Loop through all of the function definitions and count the
    * number of times each one is called */
@@ -5202,7 +5208,7 @@ void InlinepCode(void)
 
   /* Now, Loop through the function definitions again, but this
    * time inline those functions that have only been called once. */
-
+  
   InlineFunction(the_pFile->pbHead);
   //fprintf(stderr,"inlining %d\n",__LINE__);