[llvm-commits] [llvm] r62104 - in /llvm/trunk: include/llvm/Analysis/DebugInfo.h lib/Analysis/DebugInfo.cpp

Devang Patel dpatel at apple.com
Mon Jan 12 13:38:43 PST 2009


Author: dpatel
Date: Mon Jan 12 15:38:43 2009
New Revision: 62104

URL: http://llvm.org/viewvc/llvm-project?rev=62104&view=rev
Log:
Add classof() methods to support isa<> and other related facilities.

Modified:
    llvm/trunk/include/llvm/Analysis/DebugInfo.h
    llvm/trunk/lib/Analysis/DebugInfo.cpp

Modified: llvm/trunk/include/llvm/Analysis/DebugInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/DebugInfo.h?rev=62104&r1=62103&r2=62104&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Analysis/DebugInfo.h (original)
+++ llvm/trunk/include/llvm/Analysis/DebugInfo.h Mon Jan 12 15:38:43 2009
@@ -17,6 +17,7 @@
 
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/DenseMap.h"
+#include "llvm/Support/Dwarf.h"
 
 namespace llvm {
   class BasicBlock;
@@ -95,10 +96,9 @@
     
     int64_t getLo() const { return (int64_t)getUInt64Field(1); }
     int64_t getHi() const { return (int64_t)getUInt64Field(2); }
-    static bool isSubrange(unsigned);
     static inline bool classof(const DISubrange *) { return true; }
     static inline bool classof(const DIDescriptor *D) {
-      return isSubrange(D->getTag());
+      return D->getTag() == dwarf::DW_TAG_subrange_type;
     }
   };
   
@@ -111,6 +111,12 @@
     DIDescriptor getElement(unsigned Idx) const {
       return getDescriptorField(Idx);
     }
+
+    static inline bool classof(const DIArray *) { return true; }
+    static inline bool classof(const DIDescriptor *D) {
+      return D->getTag() == dwarf::DW_TAG_array_type 
+        || D->getTag() == dwarf::DW_AT_GNU_vector;
+    }
   };
   
   /// DICompileUnit - A wrapper for a compile unit.
@@ -122,6 +128,11 @@
     std::string getFilename() const  { return getStringField(3); }
     std::string getDirectory() const { return getStringField(4); }
     std::string getProducer() const  { return getStringField(5); }
+
+    static inline bool classof(const DICompileUnit *) { return true; }
+    static inline bool classof(const DIDescriptor *D) {
+      return D->getTag() == dwarf::DW_TAG_compile_unit;
+    }
   };
 
   /// DIEnumerator - A wrapper for an enumerator (e.g. X and Y in 'enum {X,Y}').
@@ -133,6 +144,10 @@
     
     std::string getName() const  { return getStringField(1); }
     uint64_t getEnumValue() const { return getUInt64Field(2); }
+    static inline bool classof(const DIEnumerator *) { return true; }
+    static inline bool classof(const DIDescriptor *D) {
+      return D->getTag() == dwarf::DW_TAG_enumerator;
+    }
   };
   
   /// DIType - This is a wrapper for a type.
@@ -144,6 +159,21 @@
     // This ctor is used when the Tag has already been validated by a derived
     // ctor.
     DIType(GlobalVariable *GV, bool, bool) : DIDescriptor(GV) {}
+
+    /// isDerivedType - Return true if the specified tag is legal for
+    /// DIDerivedType.
+    static bool isDerivedType(unsigned TAG);
+
+    /// isCompositeType - Return true if the specified tag is legal for
+    /// DICompositeType.
+    static bool isCompositeType(unsigned TAG);
+
+    /// isBasicType - Return true if the specified tag is legal for
+    /// DIBasicType.
+    static bool isBasicType(unsigned TAG) {
+      return TAG == dwarf::DW_TAG_base_type;
+    }
+
   public:
     explicit DIType(GlobalVariable *GV);
     explicit DIType() {}
@@ -169,6 +199,13 @@
       assert (0 && "Invalid DIDescriptor");
       return "";
     }
+
+    static inline bool classof(const DIType *) { return true; }
+    static inline bool classof(const DIDescriptor *D) {
+      unsigned Tag = D->getTag();
+      return isBasicType(Tag) || isDerivedType(Tag) || isCompositeType(Tag);
+    }
+
   };
   
   /// DIBasicType - A basic type, like 'int' or 'float'.
@@ -194,10 +231,6 @@
     std::string getFilename() const { return getStringField(10); }
     std::string getDirectory() const { return getStringField(11); }
 
-    /// isDerivedType - Return true if the specified tag is legal for
-    /// DIDerivedType.
-    static bool isDerivedType(unsigned TAG);
-
     static inline bool classof(const DIDerivedType *) { return true; }
     static inline bool classof(const DIDescriptor *D) {
       return isDerivedType(D->getTag());
@@ -216,9 +249,6 @@
     std::string getFilename() const { return getStringField(11); }
     std::string getDirectory() const { return getStringField(12); }
     
-    /// isCompositeType - Return true if the specified tag is legal for
-    /// DICompositeType.
-    static bool isCompositeType(unsigned TAG);
     static inline bool classof(const DIDerivedType *) { return true; }
     static inline bool classof(const DIDescriptor *D) {
       return isCompositeType(D->getTag());
@@ -230,6 +260,19 @@
   protected:
     explicit DIGlobal(GlobalVariable *GV, unsigned RequiredTag)
       : DIDescriptor(GV, RequiredTag) {}
+
+    /// isSubprogram - Return true if the specified tag is legal for
+    /// DISubprogram.
+    static bool isSubprogram(unsigned TAG) {
+      return TAG == dwarf::DW_TAG_subprogram;
+    }
+
+    /// isGlobalVariable - Return true if the specified tag is legal for
+    /// DIGlobalVariable.
+    static bool isGlobalVariable(unsigned TAG) {
+      return TAG == dwarf::DW_TAG_variable;
+    }
+
   public:
     virtual ~DIGlobal() {}
 
@@ -256,6 +299,12 @@
       assert (0 && "Invalid DIDescriptor");
       return "";
     }
+
+    static inline bool classof(const DIGlobal *) { return true; }
+    static inline bool classof(const DIDescriptor *D) {
+      unsigned Tag = D->getTag();
+      return isSubprogram(Tag) || isGlobalVariable(Tag);
+    }
   };
   
   
@@ -266,6 +315,10 @@
     std::string getFilename() const { return getStringField(11); }
     std::string getDirectory() const { return getStringField(12); }
     DICompositeType getType() const { return getFieldAs<DICompositeType>(8); }
+    static inline bool classof(const DISubprogram *) { return true; }
+    static inline bool classof(const DIDescriptor *D) {
+      return isSubprogram(D->getTag());
+    }
   };
   
   /// DIGlobalVariable - This is a wrapper for a global variable.
@@ -276,6 +329,10 @@
     GlobalVariable *getGlobal() const { return getGlobalVariableField(11); }
     std::string getFilename() const { return getStringField(12); }
     std::string getDirectory() const { return getStringField(13); }
+    static inline bool classof(const DIGlobalVariable *) { return true; }
+    static inline bool classof(const DIDescriptor *D) {
+      return isGlobalVariable(D->getTag());
+    }
   };
   
   
@@ -296,6 +353,10 @@
     
     /// isVariable - Return true if the specified tag is legal for DIVariable.
     static bool isVariable(unsigned Tag);
+    static inline bool classof(const DIVariable *) { return true; }
+    static inline bool classof(const DIDescriptor *D) {
+      return isVariable(D->getTag());
+    }
   };
   
   
@@ -305,6 +366,10 @@
     explicit DIBlock(GlobalVariable *GV = 0);
     
     DIDescriptor getContext() const { return getDescriptorField(1); }
+    static inline bool classof(const DIBlock *) { return true; }
+    static inline bool classof(const DIDescriptor *D) {
+      return D->getTag() == dwarf::DW_TAG_lexical_block;
+    }
   };
   
   /// DIFactory - This object assists with the construction of the various

Modified: llvm/trunk/lib/Analysis/DebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/DebugInfo.cpp?rev=62104&r1=62103&r2=62104&view=diff

==============================================================================
--- llvm/trunk/lib/Analysis/DebugInfo.cpp (original)
+++ llvm/trunk/lib/Analysis/DebugInfo.cpp Mon Jan 12 15:38:43 2009
@@ -20,7 +20,6 @@
 #include "llvm/Instructions.h"
 #include "llvm/Module.h"
 #include "llvm/Analysis/ValueTracking.h"
-#include "llvm/Support/Dwarf.h"
 using namespace llvm;
 
 //===----------------------------------------------------------------------===//
@@ -112,7 +111,7 @@
 
 /// isDerivedType - Return true if the specified tag is legal for
 /// DIDerivedType.
-bool DIDerivedType::isDerivedType(unsigned Tag) {
+bool DIType::isDerivedType(unsigned Tag) {
   switch (Tag) {
   case dwarf::DW_TAG_typedef:
   case dwarf::DW_TAG_pointer_type:
@@ -137,7 +136,7 @@
 
 /// isCompositeType - Return true if the specified tag is legal for
 /// DICompositeType.
-bool DICompositeType::isCompositeType(unsigned TAG) {
+bool DIType::isCompositeType(unsigned TAG) {
   switch (TAG) {
   case dwarf::DW_TAG_array_type:
   case dwarf::DW_TAG_structure_type:
@@ -181,11 +180,6 @@
   return C->getNumOperands();
 }
 
-/// isSubrange - Return true if the specified tag is legal for DISubrange.
-bool DISubrange::isSubrange(unsigned Tag) {
-  return Tag == dwarf::DW_TAG_subrange_type;
-}
-
 //===----------------------------------------------------------------------===//
 // DIFactory: Basic Helpers
 //===----------------------------------------------------------------------===//





More information about the llvm-commits mailing list