Support for enumerations.
authorJim Laskey <jlaskey@mac.com>
Wed, 1 Mar 2006 23:52:37 +0000 (23:52 +0000)
committerJim Laskey <jlaskey@mac.com>
Wed, 1 Mar 2006 23:52:37 +0000 (23:52 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26466 91177308-0d34-0410-b5e6-96231b3b80d8

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

index d9d76fae2af290a2ead18f1a8e5a7eaa62330d89..099cd03a9cb47002a262295c0968b528dcfcedef 100644 (file)
@@ -446,6 +446,44 @@ public:
 #endif
 };
 
+//===----------------------------------------------------------------------===//
+/// EnumeratorDesc - This class packages debug information associated with
+/// named integer constants.
+class EnumeratorDesc : public DebugInfoDesc {
+private:
+  std::string Name;                     // Enumerator name.
+  int64_t Value;                        // Enumerator value.
+
+public:
+  EnumeratorDesc();
+  
+  // Accessors
+  const std::string &getName()               const { return Name; }
+  int64_t getValue()                         const { return Value; }
+  void setName(const std::string &N)               { Name = N; }
+  void setValue(int64_t V)                         { Value = V; }
+
+  // Implement isa/cast/dyncast.
+  static bool classof(const EnumeratorDesc *) { return true; }
+  static bool classof(const DebugInfoDesc *D);
+  
+  /// ApplyToFields - Target the visitor to the fields of the EnumeratorDesc.
+  ///
+  virtual void ApplyToFields(DIVisitor *Visitor);
+
+  /// getDescString - Return a string used to compose global names and labels.
+  ///
+  virtual const char *getDescString() const;
+    
+  /// getTypeString - Return a string used to label this descriptor's type.
+  ///
+  virtual const char *getTypeString() const;
+
+#ifndef NDEBUG
+  virtual void dump();
+#endif
+};
+
 //===----------------------------------------------------------------------===//
 /// GlobalDesc - This class is the base descriptor for global functions and
 /// variables.
index 58dc6dd8135fd9be6882557b8435a07e59771594..dfe94f999fbea2fe661719314fd7591c103a2965 100644 (file)
@@ -1109,8 +1109,8 @@ DIE *DwarfWriter::NewType(DIE *Context, TypeDesc *TyDesc) {
         if (Lo != Hi) {
           Subrange->AddDIEntry(DW_AT_type, DW_FORM_ref4, IndexTy);
           // Only add low if non-zero.
-          if (Lo) Subrange->AddUInt(DW_AT_lower_bound, 0, Lo);
-          Subrange->AddUInt(DW_AT_upper_bound, 0, Hi);
+          if (Lo) Subrange->AddSInt(DW_AT_lower_bound, 0, Lo);
+          Subrange->AddSInt(DW_AT_upper_bound, 0, Hi);
         }
         Ty->AddChild(Subrange);
       }
@@ -1124,6 +1124,17 @@ DIE *DwarfWriter::NewType(DIE *Context, TypeDesc *TyDesc) {
       break;
     }
     case DW_TAG_enumeration_type: {
+      // Add enumerators to enumeration type.
+      for(unsigned i = 0, N = Elements.size(); i < N; ++i) {
+        EnumeratorDesc *ED = cast<EnumeratorDesc>(Elements[i]);
+        const std::string &Name = ED->getName();
+        int64_t Value = ED->getValue();
+        DIE *Enumerator = new DIE(DW_TAG_enumerator);
+        Enumerator->AddString(DW_AT_name, DW_FORM_string, Name);
+        Enumerator->AddSInt(DW_AT_const_value, DW_FORM_sdata, Value);
+        Ty->AddChild(Enumerator);
+      }
+
       break;
     }
     default: break;
index 46163a777e69e3a8fdea185c56d2930a54e113a4..c5309417055fded22a8392589ba1328789bab150 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_enumerator:       return new EnumeratorDesc();
   default: break;
   }
   return NULL;
@@ -909,6 +910,49 @@ void SubrangeDesc::dump() {
 
 //===----------------------------------------------------------------------===//
 
+EnumeratorDesc::EnumeratorDesc()
+: DebugInfoDesc(DW_TAG_enumerator)
+, Name("")
+, Value(0)
+{}
+
+// Implement isa/cast/dyncast.
+bool EnumeratorDesc::classof(const DebugInfoDesc *D) {
+  return D->getTag() == DW_TAG_enumerator;
+}
+
+/// ApplyToFields - Target the visitor to the fields of the EnumeratorDesc.
+///
+void EnumeratorDesc::ApplyToFields(DIVisitor *Visitor) {
+  DebugInfoDesc::ApplyToFields(Visitor);
+
+  Visitor->Apply(Name);
+  Visitor->Apply(Value);
+}
+
+/// getDescString - Return a string used to compose global names and labels.
+///
+const char *EnumeratorDesc::getDescString() const {
+  return "llvm.dbg.enumerator";
+}
+  
+/// getTypeString - Return a string used to label this descriptor's type.
+///
+const char *EnumeratorDesc::getTypeString() const {
+  return "llvm.dbg.enumerator.type";
+}
+
+#ifndef NDEBUG
+void EnumeratorDesc::dump() {
+  std::cerr << getDescString() << " "
+            << "Tag(" << getTag() << "), "
+            << "Name(" << Name << "), "
+            << "Value(" << Value << ")\n";
+}
+#endif
+
+//===----------------------------------------------------------------------===//
+
 GlobalDesc::GlobalDesc(unsigned T)
 : AnchoredDesc(T)
 , Context(0)