Adding basic structure support.
authorJim Laskey <jlaskey@mac.com>
Fri, 3 Mar 2006 15:06:57 +0000 (15:06 +0000)
committerJim Laskey <jlaskey@mac.com>
Fri, 3 Mar 2006 15:06:57 +0000 (15:06 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26505 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CodeGen/MachineDebugInfo.h
lib/CodeGen/DwarfWriter.cpp
lib/CodeGen/MachineDebugInfo.cpp

index 099cd03a9cb47002a262295c0968b528dcfcedef..3fad875415dafb80cb175d869998a6d124bfb864 100644 (file)
@@ -268,23 +268,25 @@ private:
   std::string Name;                     // Type name (may be empty.)
   CompileUnitDesc *File;                // Declared compile unit (may be NULL.)
   int Line;                             // Declared line# (may be zero.)
-  uint64_t Size;                        // Type size (may be zero.)
+  uint64_t Size;                        // Type bit size (may be zero.)
+  uint64_t Offset;                      // Type bit offset (may be zero.)
 
-protected:
+public:
   TypeDesc(unsigned T);
 
-public:
   // Accessors
   DebugInfoDesc *getContext()                const { return Context; }
   const std::string &getName()               const { return Name; }
   CompileUnitDesc *getFile()                 const { return File; }
   int getLine()                              const { return Line; }
   uint64_t getSize()                         const { return Size; }
+  uint64_t getOffset()                       const { return Offset; }
   void setContext(DebugInfoDesc *C)                { Context = C; }
   void setName(const std::string &N)               { Name = N; }
   void setFile(CompileUnitDesc *U)                 { File = U; }
   void setLine(int L)                              { Line = L; }
   void setSize(uint64_t S)                         { Size = S; }
+  void setOffset(uint64_t O)                       { Offset = O; }
   
   /// ApplyToFields - Target the visitor to the fields of the  TypeDesc.
   ///
@@ -413,8 +415,8 @@ public:
 /// value ranges.
 class SubrangeDesc : public DebugInfoDesc {
 private:
-  int64_t Lo;                           // Low value of range
-  int64_t Hi;                           // High value of range
+  int64_t Lo;                           // Low value of range.
+  int64_t Hi;                           // High value of range.
 
 public:
   SubrangeDesc();
index dfe94f999fbea2fe661719314fd7591c103a2965..e28020fa37bcdc38af02e6cccce97a2a211d653c 100644 (file)
@@ -41,6 +41,8 @@ class CompileUnit;
 class DIE;
 
 //===----------------------------------------------------------------------===//
+// CompileUnit - This dwarf writer support class manages information associate
+// with a source file.
 class CompileUnit {
 private:
   CompileUnitDesc *Desc;                // Compile unit debug descriptor.
@@ -505,6 +507,13 @@ void DIEInteger::EmitValue(const DwarfWriter &DW, unsigned Form) const {
   case DW_FORM_data8: DW.EmitInt64(Integer);        break;
   case DW_FORM_udata: DW.EmitULEB128Bytes(Integer); break;
   case DW_FORM_sdata: DW.EmitSLEB128Bytes(Integer); break;
+  // FIXME - Punting on field offsets.
+  case DW_FORM_block1: {
+    DW.EmitInt8(1 +  DW.SizeULEB128(Integer)); DW.EOL("Form1 Size");
+    DW.EmitInt8(DW_OP_plus_uconst); DW.EOL("DW_OP_plus_uconst");
+    DW.EmitULEB128Bytes(Integer);
+    break;
+  }
   default: assert(0 && "DIE Value form not supported yet"); break;
   }
 }
@@ -520,6 +529,8 @@ unsigned DIEInteger::SizeOf(const DwarfWriter &DW, unsigned Form) const {
   case DW_FORM_data8: return sizeof(int64_t);
   case DW_FORM_udata: return DW.SizeULEB128(Integer);
   case DW_FORM_sdata: return DW.SizeSLEB128(Integer);
+  // FIXME - Punting on field offsets.
+  case DW_FORM_block1:   return 2 + DW.SizeULEB128(Integer);
   default: assert(0 && "DIE Value form not supported yet"); break;
   }
   return 0;
@@ -1117,10 +1128,36 @@ DIE *DwarfWriter::NewType(DIE *Context, TypeDesc *TyDesc) {
       
       break;
     }
-    case DW_TAG_structure_type: {
-      break;
-    }
+    case DW_TAG_structure_type:
     case DW_TAG_union_type: {
+      // FIXME - this is just the basics.
+      // Add elements to structure type.
+      for(unsigned i = 0, N = Elements.size(); i < N; ++i) {
+        DerivedTypeDesc *MemberDesc = cast<DerivedTypeDesc>(Elements[i]);
+        const std::string &Name = MemberDesc->getName();
+        unsigned Line = MemberDesc->getLine();
+        TypeDesc *MemTy = MemberDesc->getFromType();
+        uint64_t Size = MemberDesc->getSize();
+        uint64_t Offset = MemberDesc->getOffset();
+   
+        DIE *Member = new DIE(DW_TAG_member);
+        if (!Name.empty()) Member->AddString(DW_AT_name, DW_FORM_string, Name);
+        if (CompileUnitDesc *File = MemberDesc->getFile()) {
+          CompileUnit *FileUnit = FindCompileUnit(File);
+          unsigned FileID = FileUnit->getID();
+          int Line = TyDesc->getLine();
+          Member->AddUInt(DW_AT_decl_file, 0, FileID);
+          Member->AddUInt(DW_AT_decl_line, 0, Line);
+        }
+        if (TypeDesc *FromTy = MemberDesc->getFromType()) {
+           Member->AddDIEntry(DW_AT_type, DW_FORM_ref4,
+                              NewType(Context, FromTy));
+        }
+        // FIXME - Punt on the Address.
+        Member->AddUInt(DW_AT_data_member_location, DW_FORM_block1,
+                                                    Offset >> 3);
+        Ty->AddChild(Member);
+      }
       break;
     }
     case DW_TAG_enumeration_type: {
index c5309417055fded22a8392589ba1328789bab150..8e1d8f22c25b841d7d812eede420a87f9f7839dc 100644 (file)
@@ -516,6 +516,7 @@ DebugInfoDesc *DebugInfoDesc::DescFactory(unsigned Tag) {
   case DW_TAG_union_type:
   case DW_TAG_enumeration_type: return new CompositeTypeDesc(Tag);
   case DW_TAG_subrange_type:    return new SubrangeDesc();
+  case DW_TAG_member:           return new DerivedTypeDesc(DW_TAG_member);
   case DW_TAG_enumerator:       return new EnumeratorDesc();
   default: break;
   }
@@ -673,6 +674,7 @@ TypeDesc::TypeDesc(unsigned T)
 , Name("")
 , File(NULL)
 , Size(0)
+, Offset(0)
 {}
 
 /// ApplyToFields - Target the visitor to the fields of the TypeDesc.
@@ -685,6 +687,7 @@ void TypeDesc::ApplyToFields(DIVisitor *Visitor) {
   Visitor->Apply((DebugInfoDesc *&)File);
   Visitor->Apply(Line);
   Visitor->Apply(Size);
+  Visitor->Apply(Offset);
 }
 
 /// getDescString - Return a string used to compose global names and labels.
@@ -707,7 +710,8 @@ void TypeDesc::dump() {
             << "Name(\"" << Name << "\"), "
             << "File(" << File << "), "
             << "Line(" << Line << "), "
-            << "Size(" << Size << ")\n";
+            << "Size(" << Size << "), "
+            << "Offset(" << Offset << ")\n";
 }
 #endif
 
@@ -771,6 +775,7 @@ bool DerivedTypeDesc::classof(const DebugInfoDesc *D) {
   case DW_TAG_const_type:
   case DW_TAG_volatile_type:
   case DW_TAG_restrict_type:
+  case DW_TAG_member:
     return true;
   default: break;
   }