[llvm-commits] CVS: llvm/lib/CodeGen/DwarfWriter.cpp MachineDebugInfo.cpp

Jim Laskey jlaskey at apple.com
Thu Feb 23 08:58:30 PST 2006



Changes in directory llvm/lib/CodeGen:

DwarfWriter.cpp updated: 1.27 -> 1.28
MachineDebugInfo.cpp updated: 1.15 -> 1.16
---
Log message:

DwarfWriter reading basic type information from llvm-gcc4 code.


---
Diffs of the changes:  (+126 -7)

 DwarfWriter.cpp      |   42 +++++++++++++++++++++--
 MachineDebugInfo.cpp |   91 +++++++++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 126 insertions(+), 7 deletions(-)


Index: llvm/lib/CodeGen/DwarfWriter.cpp
diff -u llvm/lib/CodeGen/DwarfWriter.cpp:1.27 llvm/lib/CodeGen/DwarfWriter.cpp:1.28
--- llvm/lib/CodeGen/DwarfWriter.cpp:1.27	Wed Feb 22 13:02:11 2006
+++ llvm/lib/CodeGen/DwarfWriter.cpp	Thu Feb 23 10:58:18 2006
@@ -1232,7 +1232,40 @@
   GlobalEntities[Name] = Entity;
 }
 
-/// NewCompileUnit - Create new compile unit information.
+/// NewType - Create a new type DIE.
+///
+DIE *DwarfWriter::NewType(DIE *Unit, TypeDesc *TyDesc) {
+  // Check for pre-existence.
+  DIE *&Slot = DescToDieMap[TyDesc];
+  if (Slot) return Slot;
+
+  // Get core information.
+  const std::string &Name = TyDesc->getName();
+  // FIXME - handle larger sizes.
+  unsigned Size = TyDesc->getSize() >> 3;
+  
+  // Determine how to handle.
+  if (BasicTypeDesc *BasicTyDesc = dyn_cast<BasicTypeDesc>(TyDesc)) {
+    unsigned Encoding = BasicTyDesc->getEncoding();
+  
+    DIE *Ty = new DIE(DW_TAG_base_type);
+    if (!Name.empty())  Ty->AddString(DW_AT_name, DW_FORM_string, Name);
+
+    Ty->AddUInt  (DW_AT_byte_size, 0,              Size);
+    Ty->AddUInt  (DW_AT_encoding,  DW_FORM_data1,  Encoding);
+    
+    Slot = Ty;
+  } else {
+    assert(0 && "Type not supported yet");
+  }
+ 
+  // Add to context owner.
+  Unit->AddChild(Slot);
+  
+  return Slot;
+}
+
+/// NewCompileUnit - Create new compile unit DIE.
 ///
 DIE *DwarfWriter::NewCompileUnit(CompileUnitDesc *CompileUnit) {
   // Check for pre-existence.
@@ -1275,9 +1308,10 @@
   unsigned FileID = DebugInfo->RecordSource(CompileUnit);
   unsigned Line = GVD->getLine();
   
-  // FIXME - faking the type for the time being.
-  DIE *Type = NewBasicType(Unit, Type::IntTy); 
-                                    
+  // Get the global's type.
+  DIE *Type = NewType(Unit, GVD->getTypeDesc()); 
+
+  // Create the globale variable DIE.
   DIE *VariableDie = new DIE(DW_TAG_variable);
   VariableDie->AddString     (DW_AT_name,      DW_FORM_string, Name);
   VariableDie->AddUInt       (DW_AT_decl_file, 0,              FileID);


Index: llvm/lib/CodeGen/MachineDebugInfo.cpp
diff -u llvm/lib/CodeGen/MachineDebugInfo.cpp:1.15 llvm/lib/CodeGen/MachineDebugInfo.cpp:1.16
--- llvm/lib/CodeGen/MachineDebugInfo.cpp:1.15	Wed Feb 22 13:02:11 2006
+++ llvm/lib/CodeGen/MachineDebugInfo.cpp	Thu Feb 23 10:58:18 2006
@@ -197,6 +197,7 @@
   ///
   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 @@
     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 @@
   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 @@
   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 @@
     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 @@
   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 @@
 
 //===----------------------------------------------------------------------===//
 
+//===----------------------------------------------------------------------===//
+
+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 @@
 
   Visitor->Apply(Context);
   Visitor->Apply(Name);
-  Visitor->Apply(TyDesc);
+  Visitor->Apply((DebugInfoDesc *&)TyDesc);
   Visitor->Apply(IsStatic);
   Visitor->Apply(IsDefinition);
 }
@@ -606,6 +691,7 @@
             << "Tag(" << getTag() << "), "
             << "Anchor(" << getAnchor() << "), "
             << "Name(\"" << getName() << "\"), "
+            << "Type(\"" << getTypeDesc() << "\"), "
             << "IsStatic(" << (isStatic() ? "true" : "false") << "), "
             << "IsDefinition(" << (isDefinition() ? "true" : "false") << "), "
             << "Global(" << Global << "), "
@@ -649,13 +735,12 @@
             << "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));
 }






More information about the llvm-commits mailing list