mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-28 19:31:58 +00:00
Metadata: Add typed array-like wrapper for MDTuple
Add `MDTupleTypedArrayWrapper`, a wrapper around `MDTuple` that adapts it to look like an array and cast its operands to the given type. This is designed to be a replacement for `DITypedArray<>`, which is in the `DIDescriptor` hierarchy. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@234183 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
c6370a13cf
commit
8eb45116ef
@ -607,7 +607,7 @@ public:
|
|||||||
return cast_or_null<MDTuple>(getRawElements());
|
return cast_or_null<MDTuple>(getRawElements());
|
||||||
}
|
}
|
||||||
Metadata *getVTableHolder() const { return getRawVTableHolder(); }
|
Metadata *getVTableHolder() const { return getRawVTableHolder(); }
|
||||||
MDTuple *getTemplateParams() const {
|
MDTemplateParameterArray getTemplateParams() const {
|
||||||
return cast_or_null<MDTuple>(getRawTemplateParams());
|
return cast_or_null<MDTuple>(getRawTemplateParams());
|
||||||
}
|
}
|
||||||
StringRef getIdentifier() const { return getStringOperand(7); }
|
StringRef getIdentifier() const { return getStringOperand(7); }
|
||||||
@ -636,7 +636,7 @@ public:
|
|||||||
void replaceVTableHolder(Metadata *VTableHolder) {
|
void replaceVTableHolder(Metadata *VTableHolder) {
|
||||||
replaceOperandWith(5, VTableHolder);
|
replaceOperandWith(5, VTableHolder);
|
||||||
}
|
}
|
||||||
void replaceTemplateParams(MDTuple *TemplateParams) {
|
void replaceTemplateParams(MDTemplateParameterArray TemplateParams) {
|
||||||
replaceOperandWith(6, TemplateParams);
|
replaceOperandWith(6, TemplateParams);
|
||||||
}
|
}
|
||||||
/// @}
|
/// @}
|
||||||
@ -844,19 +844,19 @@ public:
|
|||||||
StringRef getProducer() const { return getStringOperand(1); }
|
StringRef getProducer() const { return getStringOperand(1); }
|
||||||
StringRef getFlags() const { return getStringOperand(2); }
|
StringRef getFlags() const { return getStringOperand(2); }
|
||||||
StringRef getSplitDebugFilename() const { return getStringOperand(3); }
|
StringRef getSplitDebugFilename() const { return getStringOperand(3); }
|
||||||
MDTuple *getEnumTypes() const {
|
MDCompositeTypeArray getEnumTypes() const {
|
||||||
return cast_or_null<MDTuple>(getRawEnumTypes());
|
return cast_or_null<MDTuple>(getRawEnumTypes());
|
||||||
}
|
}
|
||||||
MDTuple *getRetainedTypes() const {
|
MDTypeArray getRetainedTypes() const {
|
||||||
return cast_or_null<MDTuple>(getRawRetainedTypes());
|
return cast_or_null<MDTuple>(getRawRetainedTypes());
|
||||||
}
|
}
|
||||||
MDTuple *getSubprograms() const {
|
MDSubprogramArray getSubprograms() const {
|
||||||
return cast_or_null<MDTuple>(getRawSubprograms());
|
return cast_or_null<MDTuple>(getRawSubprograms());
|
||||||
}
|
}
|
||||||
MDTuple *getGlobalVariables() const {
|
MDGlobalVariableArray getGlobalVariables() const {
|
||||||
return cast_or_null<MDTuple>(getRawGlobalVariables());
|
return cast_or_null<MDTuple>(getRawGlobalVariables());
|
||||||
}
|
}
|
||||||
MDTuple *getImportedEntities() const {
|
MDImportedEntityArray getImportedEntities() const {
|
||||||
return cast_or_null<MDTuple>(getRawImportedEntities());
|
return cast_or_null<MDTuple>(getRawImportedEntities());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1103,13 +1103,13 @@ public:
|
|||||||
ConstantAsMetadata *getFunction() const {
|
ConstantAsMetadata *getFunction() const {
|
||||||
return cast_or_null<ConstantAsMetadata>(getRawFunction());
|
return cast_or_null<ConstantAsMetadata>(getRawFunction());
|
||||||
}
|
}
|
||||||
MDTuple *getTemplateParams() const {
|
MDTemplateParameterArray getTemplateParams() const {
|
||||||
return cast_or_null<MDTuple>(getRawTemplateParams());
|
return cast_or_null<MDTuple>(getRawTemplateParams());
|
||||||
}
|
}
|
||||||
MDSubprogram *getDeclaration() const {
|
MDSubprogram *getDeclaration() const {
|
||||||
return cast_or_null<MDSubprogram>(getRawDeclaration());
|
return cast_or_null<MDSubprogram>(getRawDeclaration());
|
||||||
}
|
}
|
||||||
MDTuple *getVariables() const {
|
MDLocalVariableArray getVariables() const {
|
||||||
return cast_or_null<MDTuple>(getRawVariables());
|
return cast_or_null<MDTuple>(getRawVariables());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1033,6 +1033,56 @@ void TempMDNodeDeleter::operator()(MDNode *Node) const {
|
|||||||
MDNode::deleteTemporary(Node);
|
MDNode::deleteTemporary(Node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// \brief Typed iterator through MDNode operands.
|
||||||
|
///
|
||||||
|
/// An iterator that transforms an \a MDNode::iterator into an iterator over a
|
||||||
|
/// particular Metadata subclass.
|
||||||
|
template <class T>
|
||||||
|
class TypedMDOperandIterator
|
||||||
|
: std::iterator<std::input_iterator_tag, T *, std::ptrdiff_t, void, T *> {
|
||||||
|
MDNode::op_iterator I;
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit TypedMDOperandIterator(MDNode::op_iterator I) : I(I) {}
|
||||||
|
T *operator*() const { return cast_or_null<T>(*I); }
|
||||||
|
TypedMDOperandIterator &operator++() {
|
||||||
|
++I;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
TypedMDOperandIterator operator++(int) {
|
||||||
|
TypedMDOperandIterator Temp(*this);
|
||||||
|
++I;
|
||||||
|
return Temp;
|
||||||
|
}
|
||||||
|
bool operator==(const TypedMDOperandIterator &X) const { return I == X.I; }
|
||||||
|
bool operator!=(const TypedMDOperandIterator &X) const { return I != X.I; }
|
||||||
|
};
|
||||||
|
|
||||||
|
/// \brief Typed, array-like tuple of metadata.
|
||||||
|
///
|
||||||
|
/// This is a wrapper for \a MDTuple that makes it act like an array holding a
|
||||||
|
/// particular type of metadata.
|
||||||
|
template <class T> class MDTupleTypedArrayWrapper {
|
||||||
|
const MDTuple *N = nullptr;
|
||||||
|
|
||||||
|
public:
|
||||||
|
MDTupleTypedArrayWrapper(const MDTuple *N) : N(N) {}
|
||||||
|
operator MDTuple *() const { return const_cast<MDTuple *>(N); }
|
||||||
|
MDTuple *operator->() const { return const_cast<MDTuple *>(N); }
|
||||||
|
MDTuple &operator*() const { return *const_cast<MDTuple *>(N); }
|
||||||
|
|
||||||
|
unsigned size() const { return N->getNumOperands(); }
|
||||||
|
T *operator[](unsigned I) const { return cast_or_null<T>(N->getOperand(I)); }
|
||||||
|
|
||||||
|
typedef TypedMDOperandIterator<T> iterator;
|
||||||
|
iterator begin() const { return iterator(N->op_begin()); }
|
||||||
|
iterator end() const { return iterator(N->op_end()); }
|
||||||
|
};
|
||||||
|
|
||||||
|
#define HANDLE_METADATA(CLASS) \
|
||||||
|
typedef MDTupleTypedArrayWrapper<CLASS> CLASS##Array;
|
||||||
|
#include "llvm/IR/Metadata.def"
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
/// \brief A tuple of MDNodes.
|
/// \brief A tuple of MDNodes.
|
||||||
///
|
///
|
||||||
|
@ -3401,8 +3401,8 @@ void Verifier::verifyTypeRefs() {
|
|||||||
|
|
||||||
// Visit all the compile units again to check the type references.
|
// Visit all the compile units again to check the type references.
|
||||||
for (auto *CU : CUs->operands())
|
for (auto *CU : CUs->operands())
|
||||||
if (auto *Ts = cast<MDCompileUnit>(CU)->getRetainedTypes())
|
if (auto Ts = cast<MDCompileUnit>(CU)->getRetainedTypes())
|
||||||
for (auto &Op : Ts->operands())
|
for (MDType *Op : Ts)
|
||||||
if (auto *T = dyn_cast<MDCompositeType>(Op))
|
if (auto *T = dyn_cast<MDCompositeType>(Op))
|
||||||
TypeRefs.erase(T->getRawIdentifier());
|
TypeRefs.erase(T->getRawIdentifier());
|
||||||
if (TypeRefs.empty())
|
if (TypeRefs.empty())
|
||||||
|
Loading…
Reference in New Issue
Block a user