DwarfWriter reading basic type information from llvm-gcc4 code.
[oota-llvm.git] / lib / CodeGen / MachineDebugInfo.cpp
index 460ed5c1b1920e4b235e68fd5e2feca5c3537190..44b71fae539d38f2ab91ac073eb611900adb1110 100644 (file)
@@ -197,6 +197,7 @@ public:
   ///
   virtual void Apply(int &Field)             { ++Count; }
   virtual void Apply(unsigned &Field)        { ++Count; }
+  virtual void Apply(uint64_t &Field)        { ++Count; }
   virtual void Apply(bool &Field)            { ++Count; }
   virtual void Apply(std::string &Field)     { ++Count; }
   virtual void Apply(DebugInfoDesc *&Field)  { ++Count; }
@@ -230,6 +231,10 @@ public:
     Constant *C = CI->getOperand(I++);
     Field = cast<ConstantUInt>(C)->getValue();
   }
+  virtual void Apply(uint64_t &Field) {
+    Constant *C = CI->getOperand(I++);
+    Field = cast<ConstantUInt>(C)->getValue();
+  }
   virtual void Apply(bool &Field) {
     Constant *C = CI->getOperand(I++);
     Field = cast<ConstantBool>(C)->getValue();
@@ -271,6 +276,9 @@ public:
   virtual void Apply(unsigned &Field) {
     Elements.push_back(ConstantUInt::get(Type::UIntTy, Field));
   }
+  virtual void Apply(uint64_t &Field) {
+    Elements.push_back(ConstantUInt::get(Type::UIntTy, Field));
+  }
   virtual void Apply(bool &Field) {
     Elements.push_back(ConstantBool::get(Field));
   }
@@ -327,6 +335,9 @@ public:
   virtual void Apply(unsigned &Field) {
     Fields.push_back(Type::UIntTy);
   }
+  virtual void Apply(uint64_t &Field) {
+    Fields.push_back(Type::UIntTy);
+  }
   virtual void Apply(bool &Field) {
     Fields.push_back(Type::BoolTy);
   }
@@ -377,6 +388,10 @@ public:
     Constant *C = CI->getOperand(I++);
     IsValid = IsValid && isa<ConstantInt>(C);
   }
+  virtual void Apply(uint64_t &Field) {
+    Constant *C = CI->getOperand(I++);
+    IsValid = IsValid && isa<ConstantInt>(C);
+  }
   virtual void Apply(bool &Field) {
     Constant *C = CI->getOperand(I++);
     IsValid = IsValid && isa<ConstantBool>(C);
@@ -414,6 +429,7 @@ DebugInfoDesc *DebugInfoDesc::DescFactory(unsigned Tag) {
   case DI_TAG_compile_unit:    return new CompileUnitDesc();
   case DI_TAG_global_variable: return new GlobalVariableDesc();
   case DI_TAG_subprogram:      return new SubprogramDesc();
+  case DI_TAG_basictype:       return new BasicTypeDesc();
   default: break;
   }
   return NULL;
@@ -545,6 +561,75 @@ void CompileUnitDesc::dump() {
 
 //===----------------------------------------------------------------------===//
 
+//===----------------------------------------------------------------------===//
+
+TypeDesc::TypeDesc(unsigned T)
+: DebugInfoDesc(T)
+, Context(NULL)
+, Name("")
+, Size(0)
+{}
+
+/// ApplyToFields - Target the visitor to the fields of the  TypeDesc.
+///
+void TypeDesc::ApplyToFields(DIVisitor *Visitor) {
+  DebugInfoDesc::ApplyToFields(Visitor);
+  
+  Visitor->Apply(Context);
+  Visitor->Apply(Name);
+  Visitor->Apply(Size);
+}
+
+/// getDescString - Return a string used to compose global names and labels.
+///
+const char *TypeDesc::getDescString() const {
+  return "llvm.dbg.type";
+}
+
+/// getTypeString - Return a string used to label this descriptor's type.
+///
+const char *TypeDesc::getTypeString() const {
+  return "llvm.dbg.type.type";
+}
+
+#ifndef NDEBUG
+void TypeDesc::dump() {
+  std::cerr << getDescString() << " "
+            << "Tag(" << getTag() << "), "
+            << "Context(" << Context << "), "
+            << "Name(\"" << Name << "\"), "
+            << "Size(" << Size << ")\n";
+}
+#endif
+
+//===----------------------------------------------------------------------===//
+
+BasicTypeDesc::BasicTypeDesc()
+: TypeDesc(DI_TAG_basictype)
+, Encoding(0)
+{}
+
+/// ApplyToFields - Target the visitor to the fields of the  BasicTypeDesc.
+///
+void BasicTypeDesc::ApplyToFields(DIVisitor *Visitor) {
+  TypeDesc::ApplyToFields(Visitor);
+  
+  Visitor->Apply(Encoding);
+}
+
+#ifndef NDEBUG
+void BasicTypeDesc::dump() {
+  std::cerr << getDescString() << " "
+            << "Tag(" << getTag() << "), "
+            << "Context(" << getContext() << "), "
+            << "Name(\"" << getName() << "\"), "
+            << "Size(" << getSize() << "), "
+            << "Encoding(" << Encoding << ")\n";
+}
+#endif
+
+//===----------------------------------------------------------------------===//
+
 GlobalDesc::GlobalDesc(unsigned T)
 : AnchoredDesc(T)
 , Context(0)
@@ -561,7 +646,7 @@ void GlobalDesc::ApplyToFields(DIVisitor *Visitor) {
 
   Visitor->Apply(Context);
   Visitor->Apply(Name);
-  Visitor->Apply(TyDesc);
+  Visitor->Apply((DebugInfoDesc *&)TyDesc);
   Visitor->Apply(IsStatic);
   Visitor->Apply(IsDefinition);
 }
@@ -579,6 +664,7 @@ void GlobalVariableDesc::ApplyToFields(DIVisitor *Visitor) {
   GlobalDesc::ApplyToFields(Visitor);
 
   Visitor->Apply(Global);
+  Visitor->Apply(Line);
 }
 
 /// getDescString - Return a string used to compose global names and labels.
@@ -605,9 +691,11 @@ void GlobalVariableDesc::dump() {
             << "Tag(" << getTag() << "), "
             << "Anchor(" << getAnchor() << "), "
             << "Name(\"" << getName() << "\"), "
+            << "Type(\"" << getTypeDesc() << "\"), "
             << "IsStatic(" << (isStatic() ? "true" : "false") << "), "
             << "IsDefinition(" << (isDefinition() ? "true" : "false") << "), "
-            << "Global(" << Global << ")\n";
+            << "Global(" << Global << "), "
+            << "Line(" << Line << ")\n";
 }
 #endif
 
@@ -647,13 +735,12 @@ void SubprogramDesc::dump() {
             << "Tag(" << getTag() << "), "
             << "Anchor(" << getAnchor() << "), "
             << "Name(\"" << getName() << "\"), "
+            << "Type(\"" << getTypeDesc() << "\"), "
             << "IsStatic(" << (isStatic() ? "true" : "false") << "), "
             << "IsDefinition(" << (isDefinition() ? "true" : "false") << ")\n";
 }
 #endif
 
-//===----------------------------------------------------------------------===//
-
 DebugInfoDesc *DIDeserializer::Deserialize(Value *V) {
   return Deserialize(getGlobalVariable(V));
 }
@@ -887,9 +974,10 @@ bool MachineDebugInfo::doFinalization() {
   return false;
 }
 
-/// Deserialize - Convert a Value to a debug information descriptor.
+/// getDescFor - Convert a Value to a debug information descriptor.
 ///
-DebugInfoDesc *MachineDebugInfo::Deserialize(Value *V) {
+// FIXME - use new Value type when available.
+DebugInfoDesc *MachineDebugInfo::getDescFor(Value *V) {
   return DR.Deserialize(V);
 }
 
@@ -909,16 +997,10 @@ void MachineDebugInfo::AnalyzeModule(Module &M) {
 /// SetupCompileUnits - Set up the unique vector of compile units.
 ///
 void MachineDebugInfo::SetupCompileUnits(Module &M) {
-  // Get vector of all debug compile units.
-  CompileUnitDesc CompileUnit;
-  std::vector<GlobalVariable*> Globals =
-                      getGlobalVariablesUsing(M, CompileUnit.getAnchorString());
+  std::vector<CompileUnitDesc *>CU = getAnchoredDescriptors<CompileUnitDesc>(M);
   
-  // Scan all compile unit globals.
-  for (unsigned i = 0, N = Globals.size(); i < N; ++i) {
-    // Add compile unit to result.
-    CompileUnits.insert(
-                    static_cast<CompileUnitDesc *>(DR.Deserialize(Globals[i])));
+  for (unsigned i = 0, N = CU.size(); i < N; i++) {
+    CompileUnits.insert(CU[i]);
   }
 }
 
@@ -928,26 +1010,10 @@ const UniqueVector<CompileUnitDesc *> MachineDebugInfo::getCompileUnits()const{
   return CompileUnits;
 }
 
-/// getGlobalVariables - Return a vector of debug GlobalVariables.
-///
-std::vector<GlobalVariableDesc *>
-MachineDebugInfo::getGlobalVariables(Module &M) {
-  // Get vector of all debug global objects.
-  GlobalVariableDesc Global;
-  std::vector<GlobalVariable*> Globals =
-                           getGlobalVariablesUsing(M, Global.getAnchorString());
-  
-  // Accumulation of GlobalVariables.
-  std::vector<GlobalVariableDesc *> GlobalVariables;
-
-  // Scan all globals.
-  for (unsigned i = 0, N = Globals.size(); i < N; ++i) {
-    GlobalVariable *GV = Globals[i];
-    GlobalVariableDesc *GVD =
-                        static_cast<GlobalVariableDesc *>(DR.Deserialize(GV));
-    GlobalVariables.push_back(GVD);
-  }
-
-  return GlobalVariables;
+/// getGlobalVariablesUsing - Return all of the GlobalVariables that use the
+/// named GlobalVariable.
+std::vector<GlobalVariable*>
+MachineDebugInfo::getGlobalVariablesUsing(Module &M,
+                                          const std::string &RootName) {
+  return ::getGlobalVariablesUsing(M, RootName);
 }
-