Pasted ".line" assembly directives patch from David Saxton with quotes around file...
[fw/sdcc] / src / pic / pcode.c
index 4e226db9c1b3a20b130aaf164ab0805217418604..91886caaa23680e8f502859c421922c2c7cce3bf 100644 (file)
@@ -124,6 +124,8 @@ pBlock *newpBlock(void);
 pCodeOp *popCopyGPR2Bit(pCodeOp *pc, int bitval);
 void pCodeRegMapLiveRanges(pBlock *pb);
 
+pBranch * pBranchAppend(pBranch *h, pBranch *n);
+
 
 /****************************************************************/
 /*                    PIC Instructions                          */
@@ -2666,7 +2668,20 @@ void unlinkpCode(pCode *pc)
                        pc->prev->next = pc->next;
                if(pc->next)
                        pc->next->prev = pc->prev;
-               
+
+#if 0
+               /* RN: I believe this should be right here, but this did not
+                *     cure the bug I was hunting... */
+               /* must keep labels -- attach to following instruction */
+               if (isPCI(pc) && PCI(pc)->label && pc->next)
+               {
+                 pCodeInstruction *pcnext = PCI(findNextInstruction (pc->next));
+                 if (pcnext)
+                 {
+                   pBranchAppend (pcnext->label, PCI(pc)->label);
+                 }
+               }
+#endif
                pc->prev = pc->next = NULL;
        }
 }
@@ -3179,7 +3194,8 @@ char *pCode2str(char *str, size_t size, pCode *pc)
     SAFE_snprintf(&s,&size,";\t--FLOW change\n");
     break;
   case PC_CSOURCE:
-    SAFE_snprintf(&s,&size,";#CSRC\t%s %d\n; %s\n", PCCS(pc)->file_name, PCCS(pc)->line_number, PCCS(pc)->line);
+//    SAFE_snprintf(&s,&size,";#CSRC\t%s %d\n; %s\n", PCCS(pc)->file_name, PCCS(pc)->line_number, PCCS(pc)->line);
+    SAFE_snprintf(&s,&size,"%s\t.line\t%d; \"%s\"\t%s\n",(options.debug?"":";"),PCCS(pc)->line_number, PCCS(pc)->file_name, PCCS(pc)->line);
     break;
   case PC_ASMDIR:
     if(PCAD(pc)->directive) {
@@ -3293,7 +3309,8 @@ static void genericPrint(FILE *of, pCode *pc)
     break;
 
   case PC_CSOURCE:
-    fprintf(of,";#CSRC\t%s %d\n;  %s\n", PCCS(pc)->file_name, PCCS(pc)->line_number, PCCS(pc)->line);
+//    fprintf(of,";#CSRC\t%s %d\n;  %s\n", PCCS(pc)->file_name, PCCS(pc)->line_number, PCCS(pc)->line);
+    fprintf(of,"%s\t.line\t%d; \"%s\"\t%s\n", (options.debug?"":";"), PCCS(pc)->line_number, PCCS(pc)->file_name, PCCS(pc)->line);
     break;
 
   case PC_ASMDIR:
@@ -4515,9 +4532,11 @@ static int BankSelect(pCodeInstruction *pci, int cur_bank, regs *reg)
                }
        }
        
+#if 1
        if (LastRegIdx == reg->rIdx) // If this is the same register as last time then it is in same bank
                return cur_bank;
        LastRegIdx = reg->rIdx;
+#endif
        
        if (reg->isFixed) {
                bank = REG_BANK(reg);
@@ -4628,6 +4647,7 @@ static int DoBankSelect(pCode *pc, int cur_bank) {
        
        if (isCALL(pc)) {
                pCode *pcf = findFunction(get_op_from_instruction(PCI(pc)));
+               LastRegIdx = -1; /* do not know which register is touched in the called function... */
                if (pcf && isPCF(pcf)) {
                        pCode *pcfr;
                        int rbank = 'U'; // Undetermined
@@ -4637,9 +4657,9 @@ static int DoBankSelect(pCode *pc, int cur_bank) {
                                if (isPCI(pcfr)) {
                                        if ((PCI(pcfr)->op==POC_RETURN) || (PCI(pcfr)->op==POC_RETLW)) {
                                                if (rbank == 'U')
-                                                       rbank = PCFL(pcfr)->lastBank;
+                                                       rbank = PCI(pcfr)->pcflow->lastBank;
                                                else
-                                                       if (rbank != PCFL(pcfr)->lastBank)
+                                                       if (rbank != PCI(pcfr)->pcflow->lastBank)
                                                                return -1; // Unknown bank - multiple returns with different banks
                                        }
                                }
@@ -4651,6 +4671,8 @@ static int DoBankSelect(pCode *pc, int cur_bank) {
                        /* Extern functions may use registers in different bank - must call banksel */
                        return -1; /* Unknown bank */
                }
+               /* play safe... */
+               return -1;
        }
        
        if ((isPCI(pc)) && (PCI(pc)->op == POC_BANKSEL)) {
@@ -5777,7 +5799,7 @@ void AnalyzepCode(char dbName)
                                pBlockMergeLabels(pb);
                                AnalyzepBlock(pb);
                        } else {
-                               DFPRINTF((stderr," skipping block analysis dbName=%c blockname=%c\n",dbName,getpBlock_dbName));
+                               DFPRINTF((stderr," skipping block analysis dbName=%c blockname=%c\n",dbName,getpBlock_dbName(pb)));
                        }
                }