/// This should not be stored in a container, because the underlying MDNode may
/// change in certain situations.
class DIDescriptor {
- // Befriends DIRef so DIRef can befriend the protected member
- // function: getFieldAs<DIRef>.
- template <typename T> friend class DIRef;
-
public:
/// \brief Duplicated debug info flags.
///
protected:
const MDNode *DbgNode;
- DIDescriptor getDescriptorField(unsigned Elt) const;
- template <typename DescTy> DescTy getFieldAs(unsigned Elt) const {
- return DescTy(getDescriptorField(Elt));
- }
-
public:
explicit DIDescriptor(const MDNode *N = nullptr) : DbgNode(N) {}
+ DIDescriptor(const DebugNode *N) : DbgNode(N) {}
MDNode *get() const { return const_cast<MDNode *>(DbgNode); }
operator MDNode *() const { return get(); }
DECLARE_SIMPLIFY_DESCRIPTOR(DIImportedEntity)
#undef DECLARE_SIMPLIFY_DESCRIPTOR
+typedef DebugNodeArray DIArray;
+typedef MDTypeRefArray DITypeArray;
+
/// \brief This is used to represent ranges, for array bounds.
class DISubrange : public DIDescriptor {
public:
int64_t getCount() const { return get()->getCount(); }
};
-/// \brief This descriptor holds an array of nodes with type T.
-template <typename T> class DITypedArray : public DIDescriptor {
-public:
- explicit DITypedArray(const MDNode *N = nullptr) : DIDescriptor(N) {}
- operator MDTuple *() const {
- return const_cast<MDTuple *>(cast_or_null<MDTuple>(DbgNode));
- }
- unsigned getNumElements() const {
- return DbgNode ? DbgNode->getNumOperands() : 0;
- }
- T getElement(unsigned Idx) const { return getFieldAs<T>(Idx); }
-};
-
-typedef DITypedArray<DIDescriptor> DIArray;
-
/// \brief A wrapper for an enumerator (e.g. X and Y in 'enum {X,Y}').
///
/// FIXME: it seems strange that this doesn't have either a reference to the
typedef DIRef<DIDescriptor> DIDescriptorRef;
typedef DIRef<DIScope> DIScopeRef;
typedef DIRef<DIType> DITypeRef;
-typedef DITypedArray<DITypeRef> DITypeArray;
/// \brief A base class for various scopes.
///
///
/// If the scope node has a name, return that, else return an empty string.
StringRef getName() const;
- StringRef getFilename() const;
- StringRef getDirectory() const;
+ StringRef getFilename() const { return get()->getFilename(); }
+ StringRef getDirectory() const { return get()->getDirectory(); }
/// \brief Generate a reference to this DIScope.
///
///
/// Abstracts over direct and identifier-based metadata references.
template <typename T> class DIRef {
- template <typename DescTy>
- friend DescTy DIDescriptor::getFieldAs(unsigned Elt) const;
- friend DIScopeRef DIScope::getContext() const;
- friend DIScopeRef DIScope::getRef() const;
- friend class DIType;
-
/// \brief Val can be either a MDNode or a MDString.
///
/// In the latter, MDString specifies the type identifier.
const Metadata *Val;
- explicit DIRef(const Metadata *V);
public:
template <class U>
T resolve(const DITypeIdentifierMap &Map) const;
operator Metadata *() const { return const_cast<Metadata *>(Val); }
-
- static DIRef get(const Metadata *MD) { return DIRef(MD); }
};
template <>
DIScope DIRef<DIScope>::resolve(const DITypeIdentifierMap &Map) const;
template <> DIType DIRef<DIType>::resolve(const DITypeIdentifierMap &Map) const;
-/// \brief Handle fields that are references to DIDescriptors.
-template <>
-DIDescriptorRef DIDescriptor::getFieldAs<DIDescriptorRef>(unsigned Elt) const;
-/// \brief Specialize DIRef constructor for DIDescriptorRef.
-template <> DIRef<DIDescriptor>::DIRef(const Metadata *V);
-
-/// \brief Handle fields that are references to DIScopes.
-template <> DIScopeRef DIDescriptor::getFieldAs<DIScopeRef>(unsigned Elt) const;
-/// \brief Specialize DIRef constructor for DIScopeRef.
-template <> DIRef<DIScope>::DIRef(const Metadata *V);
-
-/// \brief Handle fields that are references to DITypes.
-template <> DITypeRef DIDescriptor::getFieldAs<DITypeRef>(unsigned Elt) const;
-/// \brief Specialize DIRef constructor for DITypeRef.
-template <> DIRef<DIType>::DIRef(const Metadata *V);
-
/// \brief This is a wrapper for a type.
///
/// FIXME: Types should be factored much better so that CV qualifiers and
return *get();
}
- DIScopeRef getContext() const { return DIScopeRef::get(get()->getScope()); }
+ DIScopeRef getContext() const { return get()->getScope(); }
StringRef getName() const { return get()->getName(); }
unsigned getLineNumber() const { return get()->getLine(); }
uint64_t getSizeInBits() const { return get()->getSizeInBits(); }
return *get();
}
- DITypeRef getTypeDerivedFrom() const {
- return DITypeRef::get(get()->getBaseType());
- }
+ DITypeRef getTypeDerivedFrom() const { return get()->getBaseType(); }
/// \brief Return property node, if this ivar is associated with one.
MDNode *getObjCProperty() const {
DITypeRef getClassType() const {
assert(getTag() == dwarf::DW_TAG_ptr_to_member_type);
if (auto *N = dyn_cast<MDDerivedType>(get()))
- return DITypeRef::get(N->getExtraData());
- return DITypeRef::get(nullptr);
+ return MDTypeRef(N->getExtraData());
+ return MDTypeRef();
}
Constant *getConstant() const {
class DICompositeType : public DIDerivedType {
friend class DIBuilder;
- /// \brief Set the array of member DITypes.
- void setArraysHelper(MDNode *Elements, MDNode *TParams);
-
public:
DICompositeType() = default;
DICompositeType(const MDCompositeTypeBase *N) : DIDerivedType(N) {}
return DIArray(get()->getElements());
}
-private:
- template <typename T>
- void setArrays(DITypedArray<T> Elements, DIArray TParams = DIArray()) {
- assert(
- (!TParams || DbgNode->getNumOperands() == 8) &&
- "If you're setting the template parameters this should include a slot "
- "for that!");
- setArraysHelper(Elements, TParams);
- }
-
-public:
unsigned getRunTimeLang() const { return get()->getRuntimeLang(); }
- DITypeRef getContainingType() const {
- return DITypeRef::get(get()->getVTableHolder());
- }
+ DITypeRef getContainingType() const { return get()->getVTableHolder(); }
-private:
- /// \brief Set the containing type.
- void setContainingType(DICompositeType ContainingType);
-
-public:
- DIArray getTemplateParams() const {
- return DIArray(get()->getTemplateParams());
- }
+ DIArray getTemplateParams() const { return get()->getTemplateParams(); }
MDString *getIdentifier() const { return get()->getRawIdentifier(); }
};
return *get();
}
- DITypedArray<DITypeRef> getTypeArray() const {
- return DITypedArray<DITypeRef>(get()->getTypeArray());
- }
+ MDTypeRefArray getTypeArray() const { return get()->getTypeArray(); }
};
/// \brief This is a wrapper for a file.
/// \brief Get the beginning of the scope of the function (not the name).
unsigned getScopeLineNumber() const { return get()->getScopeLine(); }
- DIScopeRef getContext() const { return DIScopeRef::get(get()->getScope()); }
+ DIScopeRef getContext() const { return get()->getScope(); }
DISubroutineType getType() const {
return DISubroutineType(get()->getType());
}
- DITypeRef getContainingType() const {
- return DITypeRef::get(get()->getContainingType());
- }
+ DITypeRef getContainingType() const { return get()->getContainingType(); }
/// \brief Check if this provides debugging information for the function F.
bool describes(const Function *F);
DISubprogram getFunctionDeclaration() const {
return DISubprogram(get()->getDeclaration());
}
- MDNode *getVariablesNodes() const { return getVariables(); }
DIArray getVariables() const { return DIArray(get()->getVariables()); }
unsigned isArtificial() const { return get()->isArtificial(); }
}
StringRef getName() const { return get()->getName(); }
-
- DITypeRef getType() const { return DITypeRef::get(get()->getType()); }
+ DITypeRef getType() const { return get()->getType(); }
};
/// \brief This is a wrapper for template value parameter.
}
StringRef getName() const { return get()->getName(); }
- DITypeRef getType() const { return DITypeRef::get(get()->getType()); }
+ DITypeRef getType() const { return get()->getType(); }
Metadata *getValue() const { return get()->getValue(); }
};
unsigned isDefinition() const { return get()->isDefinition(); }
DIScope getContext() const { return DIScope(get()->getScope()); }
- StringRef getFilename() const { return getFile().getFilename(); }
- StringRef getDirectory() const { return getFile().getDirectory(); }
- DITypeRef getType() const { return DITypeRef::get(get()->getType()); }
+ StringRef getFilename() const { return get()->getFilename(); }
+ StringRef getDirectory() const { return get()->getDirectory(); }
+ DITypeRef getType() const { return get()->getType(); }
GlobalVariable *getGlobal() const;
Constant *getConstant() const {
DIScope getContext() const { return DIScope(get()->getScope()); }
DIFile getFile() const { return DIFile(get()->getFile()); }
- DITypeRef getType() const { return DITypeRef::get(get()->getType()); }
+ DITypeRef getType() const { return get()->getType(); }
- /// \brief Return true if this variable is marked as "artificial".
- bool isArtificial() const {
- return (getFlags() & FlagArtificial) != 0;
- }
-
- bool isObjectPointer() const {
- return (getFlags() & FlagObjectPointer) != 0;
- }
+ bool isArtificial() const { return get()->isArtificial(); }
+ bool isObjectPointer() const { return get()->isObjectPointer(); }
/// \brief If this variable is inlined then return inline location.
MDNode *getInlinedAt() const { return DIDescriptor(get()->getInlinedAt()); }
return *get();
}
- /// \brief Return the number of elements in the complex expression.
unsigned getNumElements() const { return get()->getNumElements(); }
-
- /// \brief return the Idx'th complex address element.
uint64_t getElement(unsigned I) const { return get()->getElement(I); }
-
- /// \brief Return whether this is a piece of an aggregate variable.
- bool isBitPiece() const;
- /// \brief Return the offset of this piece in bits.
- uint64_t getBitPieceOffset() const;
- /// \brief Return the size of this piece in bits.
- uint64_t getBitPieceSize() const;
-
- class iterator;
- /// \brief A lightweight wrapper around an element of a DIExpression.
- class Operand {
- friend class iterator;
- MDExpression::element_iterator I;
- Operand() {}
- Operand(MDExpression::element_iterator I) : I(I) {}
- public:
- /// \brief Operands such as DW_OP_piece have explicit (non-stack) arguments.
- /// Argument 0 is the operand itself.
- uint64_t getArg(unsigned N) const {
- MDExpression::element_iterator In = I;
- std::advance(In, N);
- return *In;
- }
- operator uint64_t () const { return *I; }
- /// \brief Returns underlying MDExpression::element_iterator.
- const MDExpression::element_iterator &getBase() const { return I; }
- /// \brief Returns the next operand.
- iterator getNext() const;
- };
-
- /// \brief An iterator for DIExpression elements.
- class iterator : public std::iterator<std::input_iterator_tag, StringRef,
- unsigned, const Operand*, Operand> {
- friend class Operand;
- MDExpression::element_iterator I;
- Operand Tmp;
-
- public:
- iterator(MDExpression::element_iterator I) : I(I) {}
- const Operand &operator*() { return Tmp = Operand(I); }
- const Operand *operator->() { return &(Tmp = Operand(I)); }
- iterator &operator++() {
- increment();
- return *this;
- }
- iterator operator++(int) {
- iterator X(*this);
- increment();
- return X;
- }
- bool operator==(const iterator &X) const { return I == X.I; }
- bool operator!=(const iterator &X) const { return !(*this == X); }
-
- private:
- void increment() {
- switch (**this) {
- case dwarf::DW_OP_bit_piece: std::advance(I, 3); break;
- case dwarf::DW_OP_plus: std::advance(I, 2); break;
- case dwarf::DW_OP_deref: std::advance(I, 1); break;
- default:
- llvm_unreachable("unsupported operand");
- }
- }
- };
-
- iterator begin() const { return get()->elements_begin(); }
- iterator end() const { return get()->elements_end(); }
+ bool isBitPiece() const { return get()->isBitPiece(); }
+ uint64_t getBitPieceOffset() const { return get()->getBitPieceOffset(); }
+ uint64_t getBitPieceSize() const { return get()->getBitPieceSize(); }
};
/// \brief This object holds location information.
DILocation getOrigLocation() const {
return DILocation(get()->getInlinedAt());
}
- StringRef getFilename() const { return getScope().getFilename(); }
- StringRef getDirectory() const { return getScope().getDirectory(); }
- bool atSameLineAs(const DILocation &Other) const {
- return (getLineNumber() == Other.getLineNumber() &&
- getFilename() == Other.getFilename());
- }
+ StringRef getFilename() const { return get()->getFilename(); }
+ StringRef getDirectory() const { return get()->getDirectory(); }
+
/// \brief Get the DWAF discriminator.
///
/// DWARF discriminators are used to distinguish identical file locations for
}
DIScope getContext() const { return DIScope(get()->getScope()); }
- DIDescriptorRef getEntity() const {
- return DIDescriptorRef::get(get()->getEntity());
- }
+ DIDescriptorRef getEntity() const { return get()->getEntity(); }
unsigned getLineNumber() const { return get()->getLine(); }
StringRef getName() const { return get()->getName(); }
};