mirror of
				https://github.com/c64scene-ar/llvm-6502.git
				synced 2025-10-27 09:17:11 +00:00 
			
		
		
		
	DebugInfo: Create MDTypeRef, etc., to replace DITypeRef
Create a string-based wrapper in the debug info hierarchy for type references. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@234188 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
		| @@ -290,6 +290,12 @@ template <typename T> class DIRef { | |||||||
|   explicit DIRef(const Metadata *V); |   explicit DIRef(const Metadata *V); | ||||||
|  |  | ||||||
| public: | public: | ||||||
|  |   template <class U> | ||||||
|  |   DIRef(const TypedDebugNodeRef<U> &Ref, | ||||||
|  |         typename std::enable_if<std::is_convertible<U *, T>::value>::type * = | ||||||
|  |             nullptr) | ||||||
|  |       : Val(Ref) {} | ||||||
|  |  | ||||||
|   T resolve(const DITypeIdentifierMap &Map) const; |   T resolve(const DITypeIdentifierMap &Map) const; | ||||||
|   operator Metadata *() const { return const_cast<Metadata *>(Val); } |   operator Metadata *() const { return const_cast<Metadata *>(Val); } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -41,6 +41,54 @@ | |||||||
|  |  | ||||||
| namespace llvm { | namespace llvm { | ||||||
|  |  | ||||||
|  | /// \brief Pointer union between a subclass of DebugNode and MDString. | ||||||
|  | /// | ||||||
|  | /// \a MDCompositeType can be referenced via an \a MDString unique identifier. | ||||||
|  | /// This class allows some type safety in the face of that, requiring either a | ||||||
|  | /// node of a particular type or an \a MDString. | ||||||
|  | template <class T> class TypedDebugNodeRef { | ||||||
|  |   const Metadata *MD = nullptr; | ||||||
|  |  | ||||||
|  | public: | ||||||
|  |   TypedDebugNodeRef(std::nullptr_t) {} | ||||||
|  |  | ||||||
|  |   /// \brief Construct from a raw pointer. | ||||||
|  |   explicit TypedDebugNodeRef(const Metadata *MD) : MD(MD) { | ||||||
|  |     assert((!MD || isa<MDString>(MD) || isa<T>(MD)) && "Expected valid ref"); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   template <class U> | ||||||
|  |   TypedDebugNodeRef( | ||||||
|  |       const TypedDebugNodeRef<U> &X, | ||||||
|  |       typename std::enable_if<std::is_convertible<U *, T *>::value>::type * = | ||||||
|  |           nullptr) | ||||||
|  |       : MD(X) {} | ||||||
|  |  | ||||||
|  |   operator Metadata *() const { return const_cast<Metadata *>(MD); } | ||||||
|  |  | ||||||
|  |   bool operator==(const TypedDebugNodeRef<T> &X) const { return MD == X.MD; }; | ||||||
|  |   bool operator!=(const TypedDebugNodeRef<T> &X) const { return MD != X.MD; }; | ||||||
|  |  | ||||||
|  |   /// \brief Create a reference. | ||||||
|  |   /// | ||||||
|  |   /// Get a reference to \c N, using an \a MDString reference if available. | ||||||
|  |   static TypedDebugNodeRef get(const T *N); | ||||||
|  |  | ||||||
|  |   template <class MapTy> T *resolve(const MapTy &Map) const { | ||||||
|  |     if (auto *Typed = dyn_cast<T>(MD)) | ||||||
|  |       return const_cast<T *>(Typed); | ||||||
|  |  | ||||||
|  |     auto *S = cast<MDString>(MD); | ||||||
|  |     auto I = Map.find(S); | ||||||
|  |     assert(I != Map.end() && "Missing identifier in type map"); | ||||||
|  |     return cast<T>(I->second); | ||||||
|  |   } | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | typedef TypedDebugNodeRef<DebugNode> DebugNodeRef; | ||||||
|  | typedef TypedDebugNodeRef<MDScope> MDScopeRef; | ||||||
|  | typedef TypedDebugNodeRef<MDType> MDTypeRef; | ||||||
|  |  | ||||||
| /// \brief Tagged DWARF-like metadata node. | /// \brief Tagged DWARF-like metadata node. | ||||||
| /// | /// | ||||||
| /// A metadata node with a DWARF tag (i.e., a constant named \c DW_TAG_*, | /// A metadata node with a DWARF tag (i.e., a constant named \c DW_TAG_*, | ||||||
| @@ -88,6 +136,8 @@ public: | |||||||
|     FlagAccessibility = FlagPrivate | FlagProtected | FlagPublic |     FlagAccessibility = FlagPrivate | FlagProtected | FlagPublic | ||||||
|   }; |   }; | ||||||
|  |  | ||||||
|  |   DebugNodeRef getRef() const { return DebugNodeRef::get(this); } | ||||||
|  |  | ||||||
|   static bool classof(const Metadata *MD) { |   static bool classof(const Metadata *MD) { | ||||||
|     switch (MD->getMetadataID()) { |     switch (MD->getMetadataID()) { | ||||||
|     default: |     default: | ||||||
| @@ -116,6 +166,18 @@ public: | |||||||
|   } |   } | ||||||
| }; | }; | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | struct simplify_type<const TypedDebugNodeRef<T>> { | ||||||
|  |   typedef Metadata *SimpleType; | ||||||
|  |   static SimpleType getSimplifiedValue(const TypedDebugNodeRef<T> &MD) { | ||||||
|  |     return MD; | ||||||
|  |   } | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | template <class T> | ||||||
|  | struct simplify_type<TypedDebugNodeRef<T>> | ||||||
|  |     : simplify_type<const TypedDebugNodeRef<T>> {}; | ||||||
|  |  | ||||||
| /// \brief Generic tagged DWARF-like metadata node. | /// \brief Generic tagged DWARF-like metadata node. | ||||||
| /// | /// | ||||||
| /// An un-specialized DWARF-like metadata node.  The first operand is a | /// An un-specialized DWARF-like metadata node.  The first operand is a | ||||||
| @@ -305,6 +367,8 @@ public: | |||||||
|                              : static_cast<Metadata *>(getOperand(0)); |                              : static_cast<Metadata *>(getOperand(0)); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |   MDScopeRef getRef() const { return MDScopeRef::get(this); } | ||||||
|  |  | ||||||
|   static bool classof(const Metadata *MD) { |   static bool classof(const Metadata *MD) { | ||||||
|     switch (MD->getMetadataID()) { |     switch (MD->getMetadataID()) { | ||||||
|     default: |     default: | ||||||
| @@ -414,6 +478,8 @@ public: | |||||||
|     Flags = NewFlags; |     Flags = NewFlags; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |   MDTypeRef getRef() const { return MDTypeRef::get(this); } | ||||||
|  |  | ||||||
|   static bool classof(const Metadata *MD) { |   static bool classof(const Metadata *MD) { | ||||||
|     switch (MD->getMetadataID()) { |     switch (MD->getMetadataID()) { | ||||||
|     default: |     default: | ||||||
| @@ -724,6 +790,14 @@ public: | |||||||
|   } |   } | ||||||
| }; | }; | ||||||
|  |  | ||||||
|  | template <class T> TypedDebugNodeRef<T> TypedDebugNodeRef<T>::get(const T *N) { | ||||||
|  |   if (N) | ||||||
|  |     if (auto *Composite = dyn_cast<MDCompositeType>(N)) | ||||||
|  |       if (auto *S = Composite->getRawIdentifier()) | ||||||
|  |         return TypedDebugNodeRef<T>(S); | ||||||
|  |   return TypedDebugNodeRef<T>(N); | ||||||
|  | } | ||||||
|  |  | ||||||
| /// \brief Type array for a subprogram. | /// \brief Type array for a subprogram. | ||||||
| /// | /// | ||||||
| /// TODO: Detach from CompositeType, and fold the array of types in directly | /// TODO: Detach from CompositeType, and fold the array of types in directly | ||||||
|   | |||||||
| @@ -253,14 +253,7 @@ void DICompositeType::setArraysHelper(MDNode *Elements, MDNode *TParams) { | |||||||
|   DbgNode = N; |   DbgNode = N; | ||||||
| } | } | ||||||
|  |  | ||||||
| DIScopeRef DIScope::getRef() const { | DIScopeRef DIScope::getRef() const { return MDScopeRef::get(get()); } | ||||||
|   if (!isCompositeType()) |  | ||||||
|     return DIScopeRef(*this); |  | ||||||
|   DICompositeType DTy(DbgNode); |  | ||||||
|   if (!DTy.getIdentifier()) |  | ||||||
|     return DIScopeRef(*this); |  | ||||||
|   return DIScopeRef(DTy.getIdentifier()); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| void DICompositeType::setContainingType(DICompositeType ContainingType) { | void DICompositeType::setContainingType(DICompositeType ContainingType) { | ||||||
|   TypedTrackingMDRef<MDCompositeTypeBase> N(get()); |   TypedTrackingMDRef<MDCompositeTypeBase> N(get()); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user