move sleb printing out of asmprinter into dwarf printer, make clients
handle the comment better, MCize the non-.sleb case.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@94244 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/AsmPrinter/DwarfPrinter.cpp b/lib/CodeGen/AsmPrinter/DwarfPrinter.cpp
index 99b46d6..df8b2d2 100644
--- a/lib/CodeGen/AsmPrinter/DwarfPrinter.cpp
+++ b/lib/CodeGen/AsmPrinter/DwarfPrinter.cpp
@@ -85,6 +85,36 @@
   Asm->OutStreamer.EmitIntValue(Val, 1, 0/*addrspace*/);
 }
 
+/// PrintSLEB128 - Print a series of hexadecimal values (separated by commas)
+/// representing a signed leb128 value.
+static void PrintSLEB128(MCStreamer &O, int Value) {
+  int Sign = Value >> (8 * sizeof(Value) - 1);
+  bool IsMore;
+  
+  do {
+    unsigned char Byte = static_cast<unsigned char>(Value & 0x7f);
+    Value >>= 7;
+    IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0;
+    if (IsMore) Byte |= 0x80;
+    
+    O.EmitIntValue(Byte, 1, /*addrspace*/0);
+  } while (IsMore);
+}
+
+/// EmitSLEB128 - print the specified signed leb128 value.
+void DwarfPrinter::EmitSLEB128(int Value, const char *Desc) const {
+  if (Asm->VerboseAsm && Desc)
+    Asm->OutStreamer.AddComment(Desc);
+    
+  if (MAI->hasLEB128()) {
+    O << "\t.sleb128\t" << Value;
+    Asm->OutStreamer.AddBlankLine();
+  } else {
+    PrintSLEB128(Asm->OutStreamer, Value);
+  }
+}
+
+
 
 /// PrintLabelName - Print label name in form used by Dwarf writer.
 ///
@@ -267,8 +297,7 @@
         Asm->EOL("DW_CFA_offset_extended_sf");
         Asm->EmitULEB128Bytes(Reg);
         Asm->EOL("Reg");
-        Asm->EmitSLEB128Bytes(Offset);
-        Asm->EOL("Offset");
+        EmitSLEB128(Offset, "Offset");
       } else if (Reg < 64) {
         Asm->EmitInt8(dwarf::DW_CFA_offset + Reg);
         Asm->EOL("DW_CFA_offset + Reg (" + Twine(Reg) + ")");