DebugInfo: Generalize LoadedObjectInfoHelper from RuntimeDyld

Make it usable by any class derived (even indirectly) from
LoadedObjectInfo by allowing a custom base class to be specified and
perfect forwarding to the ctor.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@307166 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
David Blaikie 2017-07-05 15:23:56 +00:00
parent b26b47eeb0
commit 4a35644b43
5 changed files with 27 additions and 21 deletions

View File

@ -221,12 +221,28 @@ public:
return false;
}
// FIXME: This is untested and unused anywhere in the LLVM project, it's
// used/needed by Julia (an external project). It should have some coverage
// (at least tests, but ideally example functionality).
/// Obtain a copy of this LoadedObjectInfo.
///
/// The caller is responsible for deallocation once the copy is no longer required.
virtual std::unique_ptr<LoadedObjectInfo> clone() const = 0;
};
template <typename Derived, typename Base = LoadedObjectInfo>
struct LoadedObjectInfoHelper : Base {
protected:
LoadedObjectInfoHelper(const LoadedObjectInfoHelper &) = default;
LoadedObjectInfoHelper() = default;
public:
template <typename... Ts>
LoadedObjectInfoHelper(Ts &&... Args) : Base(std::forward<Ts>(Args)...) {}
std::unique_ptr<llvm::LoadedObjectInfo> clone() const override {
return llvm::make_unique<Derived>(static_cast<const Derived &>(*this));
}
};
} // end namespace llvm
#endif // LLVM_DEBUGINFO_DICONTEXT_H

View File

@ -88,21 +88,6 @@ public:
ObjSectionToIDMap ObjSecToIDMap;
};
template <typename Derived> struct LoadedObjectInfoHelper : LoadedObjectInfo {
protected:
LoadedObjectInfoHelper(const LoadedObjectInfoHelper &) = default;
LoadedObjectInfoHelper() = default;
public:
LoadedObjectInfoHelper(RuntimeDyldImpl &RTDyld,
LoadedObjectInfo::ObjSectionToIDMap ObjSecToIDMap)
: LoadedObjectInfo(RTDyld, std::move(ObjSecToIDMap)) {}
std::unique_ptr<llvm::LoadedObjectInfo> clone() const override {
return llvm::make_unique<Derived>(static_cast<const Derived &>(*this));
}
};
/// \brief Memory Management.
class MemoryManager {
friend class RuntimeDyld;

View File

@ -27,9 +27,12 @@ using namespace llvm::object;
namespace {
class LoadedCOFFObjectInfo final
: public RuntimeDyld::LoadedObjectInfoHelper<LoadedCOFFObjectInfo> {
: public LoadedObjectInfoHelper<LoadedCOFFObjectInfo,
RuntimeDyld::LoadedObjectInfo> {
public:
LoadedCOFFObjectInfo(RuntimeDyldImpl &RTDyld, ObjSectionToIDMap ObjSecToIDMap)
LoadedCOFFObjectInfo(
RuntimeDyldImpl &RTDyld,
RuntimeDyld::LoadedObjectInfo::ObjSectionToIDMap ObjSecToIDMap)
: LoadedObjectInfoHelper(RTDyld, std::move(ObjSecToIDMap)) {}
OwningBinary<ObjectFile>

View File

@ -123,7 +123,8 @@ void DyldELFObject<ELFT>::updateSymbolAddress(const SymbolRef &SymRef,
}
class LoadedELFObjectInfo final
: public RuntimeDyld::LoadedObjectInfoHelper<LoadedELFObjectInfo> {
: public LoadedObjectInfoHelper<LoadedELFObjectInfo,
RuntimeDyld::LoadedObjectInfo> {
public:
LoadedELFObjectInfo(RuntimeDyldImpl &RTDyld, ObjSectionToIDMap ObjSecToIDMap)
: LoadedObjectInfoHelper(RTDyld, std::move(ObjSecToIDMap)) {}

View File

@ -27,7 +27,8 @@ using namespace llvm::object;
namespace {
class LoadedMachOObjectInfo final
: public RuntimeDyld::LoadedObjectInfoHelper<LoadedMachOObjectInfo> {
: public LoadedObjectInfoHelper<LoadedMachOObjectInfo,
RuntimeDyld::LoadedObjectInfo> {
public:
LoadedMachOObjectInfo(RuntimeDyldImpl &RTDyld,
ObjSectionToIDMap ObjSecToIDMap)