Merge atom_collection_vector with atom_collection.
atom_collection_vector is the only derived class of atom_collection. This patch merges the two. llvm-svn: 234443
This commit is contained in:
parent
2f05640409
commit
1a6ec93616
|
@ -97,16 +97,32 @@ public:
|
||||||
/// different data structures. This class is a collection abstraction.
|
/// different data structures. This class is a collection abstraction.
|
||||||
/// Each concrete File instance must implement these atom_collection
|
/// Each concrete File instance must implement these atom_collection
|
||||||
/// methods to enable clients to interate the File's atoms.
|
/// methods to enable clients to interate the File's atoms.
|
||||||
template <typename T>
|
template <typename T> class atom_collection {
|
||||||
class atom_collection {
|
|
||||||
public:
|
public:
|
||||||
virtual ~atom_collection() { }
|
atom_iterator<T> begin() const {
|
||||||
virtual atom_iterator<T> begin() const = 0;
|
const void *it = _atoms.data();
|
||||||
virtual atom_iterator<T> end() const = 0;
|
return atom_iterator<T>(*this, it);
|
||||||
virtual const T *deref(const void *it) const = 0;
|
}
|
||||||
virtual void next(const void *&it) const = 0;
|
|
||||||
virtual uint64_t size() const = 0;
|
atom_iterator<T> end() const {
|
||||||
|
const void *it = _atoms.data() + _atoms.size();
|
||||||
|
return atom_iterator<T>(*this, it);
|
||||||
|
}
|
||||||
|
|
||||||
|
const T *deref(const void *it) const {
|
||||||
|
return *reinterpret_cast<const T *const *>(it);
|
||||||
|
}
|
||||||
|
|
||||||
|
void next(const void *&it) const {
|
||||||
|
const T *const *p = reinterpret_cast<const T *const *>(it);
|
||||||
|
++p;
|
||||||
|
it = reinterpret_cast<const void *>(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t size() const { return _atoms.size(); }
|
||||||
bool empty() const { return size() == 0; }
|
bool empty() const { return size() == 0; }
|
||||||
|
|
||||||
|
std::vector<const T *> _atoms;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \brief The class is the iterator type used to iterate through a File's
|
/// \brief The class is the iterator type used to iterate through a File's
|
||||||
|
@ -193,40 +209,10 @@ protected:
|
||||||
/// memory buffer passed to this file's constructor.
|
/// memory buffer passed to this file's constructor.
|
||||||
virtual std::error_code doParse() { return std::error_code(); }
|
virtual std::error_code doParse() { return std::error_code(); }
|
||||||
|
|
||||||
/// \brief This is a convenience class for File subclasses which manage their
|
static atom_collection<DefinedAtom> _noDefinedAtoms;
|
||||||
/// atoms as a simple std::vector<>.
|
static atom_collection<UndefinedAtom> _noUndefinedAtoms;
|
||||||
template <typename T>
|
static atom_collection<SharedLibraryAtom> _noSharedLibraryAtoms;
|
||||||
class atom_collection_vector : public atom_collection<T> {
|
static atom_collection<AbsoluteAtom> _noAbsoluteAtoms;
|
||||||
public:
|
|
||||||
atom_iterator<T> begin() const override {
|
|
||||||
const void *it = _atoms.data();
|
|
||||||
return atom_iterator<T>(*this, it);
|
|
||||||
}
|
|
||||||
|
|
||||||
atom_iterator<T> end() const override {
|
|
||||||
const void *it = _atoms.data() + _atoms.size();
|
|
||||||
return atom_iterator<T>(*this, it);
|
|
||||||
}
|
|
||||||
|
|
||||||
const T *deref(const void *it) const override {
|
|
||||||
return *reinterpret_cast<const T *const *>(it);
|
|
||||||
}
|
|
||||||
|
|
||||||
void next(const void *&it) const override {
|
|
||||||
const T *const *p = reinterpret_cast<const T *const *>(it);
|
|
||||||
++p;
|
|
||||||
it = reinterpret_cast<const void*>(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint64_t size() const override { return _atoms.size(); }
|
|
||||||
|
|
||||||
std::vector<const T *> _atoms;
|
|
||||||
};
|
|
||||||
|
|
||||||
static atom_collection_vector<DefinedAtom> _noDefinedAtoms;
|
|
||||||
static atom_collection_vector<UndefinedAtom> _noUndefinedAtoms;
|
|
||||||
static atom_collection_vector<SharedLibraryAtom> _noSharedLibraryAtoms;
|
|
||||||
static atom_collection_vector<AbsoluteAtom> _noAbsoluteAtoms;
|
|
||||||
mutable llvm::BumpPtrAllocator _allocator;
|
mutable llvm::BumpPtrAllocator _allocator;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -54,10 +54,10 @@ protected:
|
||||||
/// only subclasses of SharedLibraryFile can be instantiated
|
/// only subclasses of SharedLibraryFile can be instantiated
|
||||||
explicit SharedLibraryFile(StringRef path) : File(path, kindSharedLibrary) {}
|
explicit SharedLibraryFile(StringRef path) : File(path, kindSharedLibrary) {}
|
||||||
|
|
||||||
atom_collection_vector<DefinedAtom> _definedAtoms;
|
atom_collection<DefinedAtom> _definedAtoms;
|
||||||
atom_collection_vector<UndefinedAtom> _undefinedAtoms;
|
atom_collection<UndefinedAtom> _undefinedAtoms;
|
||||||
atom_collection_vector<SharedLibraryAtom> _sharedLibraryAtoms;
|
atom_collection<SharedLibraryAtom> _sharedLibraryAtoms;
|
||||||
atom_collection_vector<AbsoluteAtom> _absoluteAtoms;
|
atom_collection<AbsoluteAtom> _absoluteAtoms;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace lld
|
} // namespace lld
|
||||||
|
|
|
@ -75,10 +75,10 @@ public:
|
||||||
DefinedAtomRange definedAtoms() { return make_range(_defined._atoms); }
|
DefinedAtomRange definedAtoms() { return make_range(_defined._atoms); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
atom_collection_vector<DefinedAtom> _defined;
|
atom_collection<DefinedAtom> _defined;
|
||||||
atom_collection_vector<UndefinedAtom> _undefined;
|
atom_collection<UndefinedAtom> _undefined;
|
||||||
atom_collection_vector<SharedLibraryAtom> _shared;
|
atom_collection<SharedLibraryAtom> _shared;
|
||||||
atom_collection_vector<AbsoluteAtom> _absolute;
|
atom_collection<AbsoluteAtom> _absolute;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \brief Archive library file that may be used as a virtual container
|
/// \brief Archive library file that may be used as a virtual container
|
||||||
|
@ -117,10 +117,10 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
atom_collection_vector<DefinedAtom> _definedAtoms;
|
atom_collection<DefinedAtom> _definedAtoms;
|
||||||
atom_collection_vector<UndefinedAtom> _undefinedAtoms;
|
atom_collection<UndefinedAtom> _undefinedAtoms;
|
||||||
atom_collection_vector<SharedLibraryAtom> _sharedLibraryAtoms;
|
atom_collection<SharedLibraryAtom> _sharedLibraryAtoms;
|
||||||
atom_collection_vector<AbsoluteAtom> _absoluteAtoms;
|
atom_collection<AbsoluteAtom> _absoluteAtoms;
|
||||||
};
|
};
|
||||||
|
|
||||||
class SimpleReference : public Reference {
|
class SimpleReference : public Reference {
|
||||||
|
|
|
@ -15,10 +15,10 @@ namespace lld {
|
||||||
|
|
||||||
File::~File() {}
|
File::~File() {}
|
||||||
|
|
||||||
File::atom_collection_vector<DefinedAtom> File::_noDefinedAtoms;
|
File::atom_collection<DefinedAtom> File::_noDefinedAtoms;
|
||||||
File::atom_collection_vector<UndefinedAtom> File::_noUndefinedAtoms;
|
File::atom_collection<UndefinedAtom> File::_noUndefinedAtoms;
|
||||||
File::atom_collection_vector<SharedLibraryAtom> File::_noSharedLibraryAtoms;
|
File::atom_collection<SharedLibraryAtom> File::_noSharedLibraryAtoms;
|
||||||
File::atom_collection_vector<AbsoluteAtom> File::_noAbsoluteAtoms;
|
File::atom_collection<AbsoluteAtom> File::_noAbsoluteAtoms;
|
||||||
|
|
||||||
std::error_code File::parse() {
|
std::error_code File::parse() {
|
||||||
std::lock_guard<std::mutex> lock(_parseMutex);
|
std::lock_guard<std::mutex> lock(_parseMutex);
|
||||||
|
|
|
@ -123,7 +123,7 @@ public:
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
mutable atom_collection_vector<DefinedAtom> _definedAtoms;
|
mutable atom_collection<DefinedAtom> _definedAtoms;
|
||||||
StringRef _machHeaderSymbolName;
|
StringRef _machHeaderSymbolName;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -398,7 +398,7 @@ private:
|
||||||
|
|
||||||
// instantiate array of BASeT from IvarsT data in file
|
// instantiate array of BASeT from IvarsT data in file
|
||||||
template <typename BaseT, typename AtomT, typename IvarsT>
|
template <typename BaseT, typename AtomT, typename IvarsT>
|
||||||
std::error_code processAtoms(atom_collection_vector<BaseT> &result,
|
std::error_code processAtoms(atom_collection<BaseT> &result,
|
||||||
const uint8_t *base, const NativeChunk *chunk) {
|
const uint8_t *base, const NativeChunk *chunk) {
|
||||||
std::vector<const BaseT *> vec(chunk->elementCount);
|
std::vector<const BaseT *> vec(chunk->elementCount);
|
||||||
const size_t ivarElementSize = chunk->fileSize / chunk->elementCount;
|
const size_t ivarElementSize = chunk->fileSize / chunk->elementCount;
|
||||||
|
@ -690,10 +690,10 @@ private:
|
||||||
|
|
||||||
std::unique_ptr<MemoryBuffer> _mb;
|
std::unique_ptr<MemoryBuffer> _mb;
|
||||||
const NativeFileHeader* _header;
|
const NativeFileHeader* _header;
|
||||||
atom_collection_vector<DefinedAtom> _definedAtoms;
|
atom_collection<DefinedAtom> _definedAtoms;
|
||||||
atom_collection_vector<UndefinedAtom> _undefinedAtoms;
|
atom_collection<UndefinedAtom> _undefinedAtoms;
|
||||||
atom_collection_vector<SharedLibraryAtom> _sharedLibraryAtoms;
|
atom_collection<SharedLibraryAtom> _sharedLibraryAtoms;
|
||||||
atom_collection_vector<AbsoluteAtom> _absoluteAtoms;
|
atom_collection<AbsoluteAtom> _absoluteAtoms;
|
||||||
const uint8_t* _absAttributes;
|
const uint8_t* _absAttributes;
|
||||||
uint32_t _absAbsoluteMaxOffset;
|
uint32_t _absAbsoluteMaxOffset;
|
||||||
const uint8_t* _attributes;
|
const uint8_t* _attributes;
|
||||||
|
|
|
@ -299,7 +299,7 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
PECOFFLinkingContext *_ctx;
|
PECOFFLinkingContext *_ctx;
|
||||||
atom_collection_vector<UndefinedAtom> _undefinedAtoms;
|
atom_collection<UndefinedAtom> _undefinedAtoms;
|
||||||
std::mutex _mutex;
|
std::mutex _mutex;
|
||||||
llvm::BumpPtrAllocator _alloc;
|
llvm::BumpPtrAllocator _alloc;
|
||||||
bool _firstTime;
|
bool _firstTime;
|
||||||
|
|
|
@ -159,10 +159,10 @@ private:
|
||||||
|
|
||||||
std::unique_ptr<const llvm::object::COFFObjectFile> _obj;
|
std::unique_ptr<const llvm::object::COFFObjectFile> _obj;
|
||||||
std::unique_ptr<MemoryBuffer> _mb;
|
std::unique_ptr<MemoryBuffer> _mb;
|
||||||
atom_collection_vector<DefinedAtom> _definedAtoms;
|
atom_collection<DefinedAtom> _definedAtoms;
|
||||||
atom_collection_vector<UndefinedAtom> _undefinedAtoms;
|
atom_collection<UndefinedAtom> _undefinedAtoms;
|
||||||
atom_collection_vector<SharedLibraryAtom> _sharedLibraryAtoms;
|
atom_collection<SharedLibraryAtom> _sharedLibraryAtoms;
|
||||||
atom_collection_vector<AbsoluteAtom> _absoluteAtoms;
|
atom_collection<AbsoluteAtom> _absoluteAtoms;
|
||||||
|
|
||||||
// The target type of the object.
|
// The target type of the object.
|
||||||
Reference::KindArch _referenceArch;
|
Reference::KindArch _referenceArch;
|
||||||
|
|
|
@ -315,8 +315,8 @@ private:
|
||||||
_definedAtoms._atoms.push_back(atom);
|
_definedAtoms._atoms.push_back(atom);
|
||||||
}
|
}
|
||||||
|
|
||||||
atom_collection_vector<DefinedAtom> _definedAtoms;
|
atom_collection<DefinedAtom> _definedAtoms;
|
||||||
atom_collection_vector<SharedLibraryAtom> _sharedLibraryAtoms;
|
atom_collection<SharedLibraryAtom> _sharedLibraryAtoms;
|
||||||
mutable llvm::BumpPtrAllocator _alloc;
|
mutable llvm::BumpPtrAllocator _alloc;
|
||||||
|
|
||||||
// Does the same thing as StringRef::ltrim() but removes at most one
|
// Does the same thing as StringRef::ltrim() but removes at most one
|
||||||
|
|
|
@ -215,8 +215,7 @@ private:
|
||||||
NameToAtom _groupMap;
|
NameToAtom _groupMap;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T> using AtomList = lld::File::atom_collection<T>;
|
||||||
using AtomList = lld::File::atom_collection_vector<T>;
|
|
||||||
|
|
||||||
/// Mapping of kind: field in yaml files.
|
/// Mapping of kind: field in yaml files.
|
||||||
enum FileKinds {
|
enum FileKinds {
|
||||||
|
|
Loading…
Reference in New Issue