fixed bug #635354
[fw/sdcc] / src / pic / pcode.c
index 17030df1fc49882b6d63429eaf7167697aa71324..f99510028e5701f78eb612ef2b9ce7e648635da8 100644 (file)
@@ -75,9 +75,9 @@ static pBlock *pb_dead_pcodes = NULL;
 /* 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 */
-int debug_verbose = 0;                /* Set true to inundate .asm file */
+int debug_verbose = 1;                /* Set true to inundate .asm file */
 
-static int GpCodeSequenceNumber = 1;
+// static int GpCodeSequenceNumber = 1;
 int GpcFlowSeq = 1;
 
 extern void RemoveUnusedRegisters(void);
@@ -105,7 +105,7 @@ 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_from_instruction( pCodeInstruction *pcc);
-char *get_op( pCodeOp *pcop,char *buff,int buf_size);
+char *get_op( pCodeOp *pcop,char *buff,size_t buf_size);
 int pCodePeepMatchLine(pCodePeep *peepBlock, pCode *pcs, pCode *pcd);
 int pCodePeepMatchRule(pCode *pc);
 void pBlockStats(FILE *of, pBlock *pb);
@@ -1200,10 +1200,8 @@ pCodeInstruction pciXORLW = {
 #define MAX_PIC14MNEMONICS 100
 pCodeInstruction *pic14Mnemonics[MAX_PIC14MNEMONICS];
 
-/* This definition needs to be part of configure.in */
-// #define USE_VSNPRINTF
 
-#ifdef USE_VSNPRINTF
+#ifdef HAVE_VSNPRINTF
   // Alas, vsnprintf is not ANSI standard, and does not exist
   // on Solaris (and probably other non-Gnu flavored Unixes).
 
@@ -1230,7 +1228,7 @@ void SAFE_snprintf(char **str, size_t *size, const  char  *format, ...)
   len = strlen(*str);
   if(len > *size) {
     fprintf(stderr,"WARNING, it looks like %s has overflowed\n",__FUNCTION__);
-    fprintf(stderr,"len = %d is > str size %d\n",len,*size);
+    fprintf(stderr,"len = %d is > str size %d\n",len,(int)*size);
   }
 
   *str += len;
@@ -1238,7 +1236,7 @@ void SAFE_snprintf(char **str, size_t *size, const  char  *format, ...)
 
 }
 
-#else  //  USE_VSNPRINTF
+#else  //  HAVE_VSNPRINTF
 
 // This version is *not* safe, despite the name.
 
@@ -1268,7 +1266,7 @@ void SAFE_snprintf(char **str, size_t *size, const  char  *format, ...)
 
 }
 
-#endif    //  USE_VSNPRINTF
+#endif    //  HAVE_VSNPRINTF
     
 
 extern  void initStack(int base_address, int size);
@@ -1587,7 +1585,7 @@ void pcode_test(void)
     char buffer[100];
 
     /* create the file name */
-    strcpy(buffer,srcFileName);
+    strcpy(buffer,dstFileName);
     strcat(buffer,".p");
 
     if( !(pFile = fopen(buffer, "w" ))) {
@@ -2084,15 +2082,19 @@ pCodeOp *newpCodeOpLit(int lit)
 
 /*-----------------------------------------------------------------*/
 /*-----------------------------------------------------------------*/
-pCodeOp *newpCodeOpImmd(char *name, int offset, int index, int code_space)
+pCodeOp *newpCodeOpImmd(char *name, int offset, int index, int code_space, int is_func)
 {
   pCodeOp *pcop;
 
   pcop = Safe_calloc(1,sizeof(pCodeOpImmd) );
   pcop->type = PO_IMMEDIATE;
   if(name) {
-    regs *r = dirregWithName(name);
+    regs *r = NULL;
     pcop->name = Safe_strdup(name);
+
+    if(!is_func) 
+     r = dirregWithName(name);
+
     PCOI(pcop)->r = r;
     if(r) {
       //fprintf(stderr, " newpCodeOpImmd reg %s exists\n",name);
@@ -2109,6 +2111,7 @@ pCodeOp *newpCodeOpImmd(char *name, int offset, int index, int code_space)
   PCOI(pcop)->index = index;
   PCOI(pcop)->offset = offset;
   PCOI(pcop)->_const = code_space;
+  PCOI(pcop)->_function = is_func;
 
   return pcop;
 }
@@ -2229,6 +2232,7 @@ pCodeOp *newpCodeOp(char *name, PIC_OPTYPE type)
     pcop = newpCodeOpReg(-1);
     break;
 
+  case PO_GPR_POINTER:
   case PO_GPR_REGISTER:
     if(name)
       pcop = newpCodeOpRegFromStr(name);
@@ -2492,7 +2496,7 @@ void pBlockRegs(FILE *of, pBlock *pb)
 
 /*-----------------------------------------------------------------*/
 /*-----------------------------------------------------------------*/
-char *get_op(pCodeOp *pcop,char *buffer, int size)
+char *get_op(pCodeOp *pcop,char *buffer, size_t size)
 {
   regs *r;
   static char b[50];
@@ -2513,7 +2517,8 @@ char *get_op(pCodeOp *pcop,char *buffer, int size)
        SAFE_snprintf(&buffer,&size,"%s",PCOR(pcop)->r->name);
        return buffer;
       }
-      return PCOR(pcop)->r->name;
+      //return PCOR(pcop)->r->name;
+      return pcop->name;
       break;
     case PO_GPR_TEMP:
       r = pic14_regWithIdx(PCOR(pcop)->r->rIdx);
@@ -2589,8 +2594,11 @@ static char *get_op_from_instruction( pCodeInstruction *pcc)
 
   if(pcc )
     return get_op(pcc->pcop,NULL,0);
-  
+
+  /* gcc 3.2:  warning: concatenation of string literals with __FUNCTION__ is deprecated 
   return ("ERROR Null: "__FUNCTION__);
+  */
+  return ("ERROR Null: get_op_from_instruction");
 
 }
 
@@ -2604,7 +2612,7 @@ static void pCodeOpPrint(FILE *of, pCodeOp *pcop)
 
 /*-----------------------------------------------------------------*/
 /*-----------------------------------------------------------------*/
-char *pCode2str(char *str, int size, pCode *pc)
+char *pCode2str(char *str, size_t size, pCode *pc)
 {
   char *s = str;