Now with fewer extraneous semicolons!
[oota-llvm.git] / lib / Target / PIC16 / PIC16DebugInfo.cpp
index 877e4ffc6d76bfc0548bbc7938a0f7649c28742a..7a948def3cfe48f696e3fe6691e5828c7765d4f3 100644 (file)
 #include "llvm/GlobalVariable.h"
 #include "llvm/CodeGen/MachineFunction.h"
 #include "llvm/MC/MCAsmInfo.h"
+#include "llvm/MC/MCStreamer.h"
 #include "llvm/Support/DebugLoc.h"
-#include "llvm/Support/FormattedStream.h"
 #include "llvm/ADT/SmallString.h"
-
+#include "llvm/ADT/StringExtras.h"
 using namespace llvm;
 
 /// PopulateDebugInfo - Populate the TypeNo, Aux[] and TagName from Ty.
@@ -70,7 +70,7 @@ void PIC16DbgInfo::PopulateDerivedTypeInfo (DIType Ty, unsigned short &TypeNo,
   
   // We also need to encode the information about the base type of
   // pointer in TypeNo.
-  DIType BaseType = DIDerivedType(Ty.getNode()).getTypeDerivedFrom();
+  DIType BaseType = DIDerivedType(Ty).getTypeDerivedFrom();
   PopulateDebugInfo(BaseType, TypeNo, HasAux, Aux, TagName);
 }
 
@@ -79,7 +79,7 @@ void PIC16DbgInfo::PopulateArrayTypeInfo (DIType Ty, unsigned short &TypeNo,
                                           bool &HasAux, int Aux[],
                                           std::string &TagName) {
 
-  DICompositeType CTy = DICompositeType(Ty.getNode());
+  DICompositeType CTy = DICompositeType(Ty);
   DIArray Elements = CTy.getTypeArray();
   unsigned short size = 1;
   unsigned short Dimension[4]={0,0,0,0};
@@ -88,7 +88,7 @@ void PIC16DbgInfo::PopulateArrayTypeInfo (DIType Ty, unsigned short &TypeNo,
     if (Element.getTag() == dwarf::DW_TAG_subrange_type) {
       TypeNo = TypeNo << PIC16Dbg::S_DERIVED;
       TypeNo = TypeNo | PIC16Dbg::DT_ARY;
-      DISubrange SubRange = DISubrange(Element.getNode());
+      DISubrange SubRange = DISubrange(Element);
       Dimension[i] = SubRange.getHi() - SubRange.getLo() + 1;
       // Each dimension is represented by 2 bytes starting at byte 9.
       Aux[8+i*2+0] = Dimension[i];
@@ -111,7 +111,7 @@ void PIC16DbgInfo::PopulateStructOrUnionTypeInfo (DIType Ty,
                                                   unsigned short &TypeNo,
                                                   bool &HasAux, int Aux[],
                                                   std::string &TagName) {
-  DICompositeType CTy = DICompositeType(Ty.getNode());
+  DICompositeType CTy = DICompositeType(Ty);
   TypeNo = TypeNo << PIC16Dbg::S_BASIC;
   if (Ty.getTag() == dwarf::DW_TAG_structure_type)
     TypeNo = TypeNo | PIC16Dbg::T_STRUCT;
@@ -124,7 +124,7 @@ void PIC16DbgInfo::PopulateStructOrUnionTypeInfo (DIType Ty,
   // llvm.dbg.composite* global variable. Since we need to revisit 
   // PIC16DebugInfo implementation anyways after the MDNodes based 
   // framework is done, let us continue with the way it is.
-  std::string UniqueSuffix = "." + Ty.getNode()->getNameStr().substr(18);
+  std::string UniqueSuffix = "." + Ty->getNameStr().substr(18);
   TagName += UniqueSuffix;
   unsigned short size = CTy.getSizeInBits()/8;
   // 7th and 8th byte represent size.
@@ -256,22 +256,19 @@ void PIC16DbgInfo::BeginFunction(const MachineFunction &MF) {
 ///
 void PIC16DbgInfo::ChangeDebugLoc(const MachineFunction &MF,  
                                   const DebugLoc &DL, bool IsInBeginFunction) {
-  if (! EmitDebugDirectives) return;
-  assert (! DL.isUnknown()  && "can't change to invalid debug loc");
+  if (!EmitDebugDirectives) return;
+  assert(!DL.isUnknown() && "can't change to invalid debug loc");
 
-  DILocation Loc = MF.getDILocation(DL);
-  MDNode *CU = Loc.getScope().getNode();
-  unsigned line = Loc.getLineNumber();
-
-  SwitchToCU(CU);
-  SwitchToLine(line, IsInBeginFunction);
+  SwitchToCU(DL.getScope(MF.getFunction()->getContext()));
+  SwitchToLine(DL.getLine(), IsInBeginFunction);
 }
 
 /// SwitchToLine - Emit line directive for a new line.
 ///
 void PIC16DbgInfo::SwitchToLine(unsigned Line, bool IsInBeginFunction) {
   if (CurLine == Line) return;
-  if (!IsInBeginFunction)  O << "\n\t.line " << Line << "\n";
+  if (!IsInBeginFunction)
+    OS.EmitRawText("\n\t.line " + Twine(Line));
   CurLine = Line;
 }
 
@@ -290,7 +287,7 @@ void PIC16DbgInfo::EndFunction(const MachineFunction &MF) {
 void PIC16DbgInfo::EndModule(Module &M) {
   if (! EmitDebugDirectives) return;
   EmitVarDebugInfo(M);
-  if (CurFile != "") O << "\n\t.eof";
+  if (CurFile != "") OS.EmitRawText(StringRef("\n\t.eof"));
 }
  
 /// EmitCompositeTypeElements - Emit debug information for members of a 
@@ -306,7 +303,7 @@ void PIC16DbgInfo::EmitCompositeTypeElements (DICompositeType CTy,
     bool HasAux = false;
     int ElementAux[PIC16Dbg::AuxSize] = { 0 };
     std::string TagName = "";
-    DIDerivedType DITy(Element.getNode());
+    DIDerivedType DITy(Element);
     unsigned short ElementSize = DITy.getSizeInBits()/8;
     // Get mangleddd name for this structure/union  element.
     std::string MangMemName = DITy.getName().str() + SuffixNo;
@@ -333,13 +330,13 @@ void PIC16DbgInfo::EmitCompositeTypeDecls(Module &M) {
   for (DebugInfoFinder::iterator I = DbgFinder.type_begin(),
          E = DbgFinder.type_end(); I != E; ++I) {
     DICompositeType CTy(*I);
-    if (CTy.isNull())
+    if (!CTy.Verify())
       continue;
     if (CTy.getTag() == dwarf::DW_TAG_union_type ||
         CTy.getTag() == dwarf::DW_TAG_structure_type ) {
       // Get the number after llvm.dbg.composite and make UniqueSuffix from 
       // it.
-      std::string DIVar = CTy.getNode()->getNameStr();
+      std::string DIVar = CTy->getNameStr();
       std::string UniqueSuffix = "." + DIVar.substr(18);
       std::string MangledCTyName = CTy.getName().str() + UniqueSuffix;
       unsigned short size = CTy.getSizeInBits()/8;
@@ -414,22 +411,26 @@ void PIC16DbgInfo::EmitFunctEndDI(const Function *F, unsigned Line) {
 ///
 void PIC16DbgInfo::EmitAuxEntry(const std::string VarName, int Aux[], int Num,
                                 std::string TagName) {
-  O << "\n\t.dim " << VarName << ", 1" ;
+  std::string Tmp;
   // TagName is emitted in case of structure/union objects.
-  if (TagName != "")
-    O << ", " << TagName;
+  if (!TagName.empty()) Tmp += ", " + TagName;
+  
   for (int i = 0; i<Num; i++)
-    O << "," << (Aux[i] && 0xff);
+    Tmp += "," + utostr(Aux[i] & 0xff);
+  
+  OS.EmitRawText("\n\t.dim " + Twine(VarName) + ", 1" + Tmp);
 }
 
 /// EmitSymbol - Emit .def for a symbol. Value is offset for the member.
 ///
-void PIC16DbgInfo::EmitSymbol(std::string Name, short Class, unsigned short
-                              Type, unsigned long Value) {
-  O << "\n\t" << ".def "<< Name << ", type = " << Type << ", class = " 
-    << Class;
+void PIC16DbgInfo::EmitSymbol(std::string Name, short Class,
+                              unsigned short Type, unsigned long Value) {
+  std::string Tmp;
   if (Value > 0)
-    O  << ", value = " << Value;
+    Tmp = ", value = " + utostr(Value);
+  
+  OS.EmitRawText("\n\t.def " + Twine(Name) + ", type = " + utostr(Type) +
+                 ", class = " + utostr(Class) + Tmp);
 }
 
 /// EmitVarDebugInfo - Emit debug information for all variables.
@@ -451,14 +452,13 @@ void PIC16DbgInfo::EmitVarDebugInfo(Module &M) {
     PopulateDebugInfo(Ty, TypeNo, HasAux, Aux, TagName);
     // Emit debug info only if type information is availaible.
     if (TypeNo != PIC16Dbg::T_NULL) {
-      O << "\n\t.type " << VarName << ", " << TypeNo;
+      OS.EmitRawText("\t.type " + Twine(VarName) + ", " + Twine(TypeNo));
       short ClassNo = getStorageClass(DIGV);
-      O << "\n\t.class " << VarName << ", " << ClassNo;
-      if (HasAux) 
+      OS.EmitRawText("\t.class " + Twine(VarName) + ", " + Twine(ClassNo));
+      if (HasAux)
         EmitAuxEntry(VarName, Aux, PIC16Dbg::AuxSize, TagName);
     }
   }
-  O << "\n";
 }
 
 /// SwitchToCU - Switch to a new compilation unit.
@@ -474,8 +474,9 @@ void PIC16DbgInfo::SwitchToCU(MDNode *CU) {
   if ( FilePath == CurFile ) return;
 
   // Else, close the current one and start a new.
-  if (CurFile != "") O << "\n\t.eof";
-  O << "\n\t.file\t\"" << FilePath << "\"\n" ;
+  if (CurFile != "")
+    OS.EmitRawText(StringRef("\t.eof"));
+  OS.EmitRawText("\n\t.file\t\"" + Twine(FilePath) + "\"");
   CurFile = FilePath;
   CurLine = 0;
 }
@@ -484,6 +485,6 @@ void PIC16DbgInfo::SwitchToCU(MDNode *CU) {
 ///
 void PIC16DbgInfo::EmitEOF() {
   if (CurFile != "")
-    O << "\n\t.EOF";
+    OS.EmitRawText(StringRef("\t.EOF"));
 }