Emit .line debug directives for stoppoints. The debug location is retrieved by the MachineInstr itself, rather than by custom handling the DBG_STOPPOINT nodes.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@68602 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Target/PIC16/PIC16AsmPrinter.cpp b/lib/Target/PIC16/PIC16AsmPrinter.cpp
index 109504e..2af42cd 100644
--- a/lib/Target/PIC16/PIC16AsmPrinter.cpp
+++ b/lib/Target/PIC16/PIC16AsmPrinter.cpp
@@ -113,6 +113,8 @@
                                                SectionFlags::Code);
   O <<  "\n";
   SwitchToSection (fCodeSection);
+
+  // Emit the frame address of the function at the beginning of code.
   O << CurrentFnName << ":\n";
   O << "    retlw  low(" << CurrentFnName << ".frame)\n";
   O << "    retlw  high(" << CurrentFnName << ".frame)\n"; 
@@ -127,10 +129,23 @@
       O << '\n';
     }
     CurBank = "";
+    
+    // For emitting line directives, we need to keep track of the current
+    // source line. When it changes then only emit the line directive.
+    unsigned CurLine = 0;
     for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end();
          II != E; ++II) {
+      // Emit the line directive if source line changed.
+      const DebugLoc DL = II->getDebugLoc();
+      if (!DL.isUnknown()) {
+        unsigned line = MF.getDebugLocTuple(DL).Line;
+        if (line != CurLine) {
+          O << "\t.line " << line << "\n";
+          CurLine = line;
+        }
+      }
       // Print the assembly for the instruction.
-        printMachineInstruction(II);
+      printMachineInstruction(II);
     }
   }
   return false;  // we didn't modify anything.