summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lld/include/lld/Core/File.h70
-rw-r--r--lld/include/lld/Core/SharedLibraryFile.h8
-rw-r--r--lld/include/lld/Core/Simple.h16
-rw-r--r--lld/lib/Core/File.cpp8
-rw-r--r--lld/lib/ReaderWriter/MachO/ExecutableAtoms.hpp2
-rw-r--r--lld/lib/ReaderWriter/Native/ReaderNative.cpp10
-rw-r--r--lld/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h2
-rw-r--r--lld/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp8
-rw-r--r--lld/lib/ReaderWriter/PECOFF/ReaderImportHeader.cpp4
-rw-r--r--lld/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp3
10 files changed, 58 insertions, 73 deletions
diff --git a/lld/include/lld/Core/File.h b/lld/include/lld/Core/File.h
index e43141b9a5b..48da03276ab 100644
--- a/lld/include/lld/Core/File.h
+++ b/lld/include/lld/Core/File.h
@@ -97,16 +97,32 @@ public:
/// different data structures. This class is a collection abstraction.
/// Each concrete File instance must implement these atom_collection
/// methods to enable clients to interate the File's atoms.
- template <typename T>
- class atom_collection {
+ template <typename T> class atom_collection {
public:
- virtual ~atom_collection() { }
- virtual atom_iterator<T> begin() const = 0;
- virtual atom_iterator<T> end() const = 0;
- 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> begin() const {
+ const void *it = _atoms.data();
+ return atom_iterator<T>(*this, it);
+ }
+
+ 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; }
+
+ std::vector<const T *> _atoms;
};
/// \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.
virtual std::error_code doParse() { return std::error_code(); }
- /// \brief This is a convenience class for File subclasses which manage their
- /// atoms as a simple std::vector<>.
- template <typename T>
- class atom_collection_vector : public atom_collection<T> {
- 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;
+ static atom_collection<DefinedAtom> _noDefinedAtoms;
+ static atom_collection<UndefinedAtom> _noUndefinedAtoms;
+ static atom_collection<SharedLibraryAtom> _noSharedLibraryAtoms;
+ static atom_collection<AbsoluteAtom> _noAbsoluteAtoms;
mutable llvm::BumpPtrAllocator _allocator;
private:
diff --git a/lld/include/lld/Core/SharedLibraryFile.h b/lld/include/lld/Core/SharedLibraryFile.h
index 2f84624287d..9c3f3ce3568 100644
--- a/lld/include/lld/Core/SharedLibraryFile.h
+++ b/lld/include/lld/Core/SharedLibraryFile.h
@@ -54,10 +54,10 @@ protected:
/// only subclasses of SharedLibraryFile can be instantiated
explicit SharedLibraryFile(StringRef path) : File(path, kindSharedLibrary) {}
- atom_collection_vector<DefinedAtom> _definedAtoms;
- atom_collection_vector<UndefinedAtom> _undefinedAtoms;
- atom_collection_vector<SharedLibraryAtom> _sharedLibraryAtoms;
- atom_collection_vector<AbsoluteAtom> _absoluteAtoms;
+ atom_collection<DefinedAtom> _definedAtoms;
+ atom_collection<UndefinedAtom> _undefinedAtoms;
+ atom_collection<SharedLibraryAtom> _sharedLibraryAtoms;
+ atom_collection<AbsoluteAtom> _absoluteAtoms;
};
} // namespace lld
diff --git a/lld/include/lld/Core/Simple.h b/lld/include/lld/Core/Simple.h
index 58fc5ea2c90..a4999e15f82 100644
--- a/lld/include/lld/Core/Simple.h
+++ b/lld/include/lld/Core/Simple.h
@@ -75,10 +75,10 @@ public:
DefinedAtomRange definedAtoms() { return make_range(_defined._atoms); }
private:
- atom_collection_vector<DefinedAtom> _defined;
- atom_collection_vector<UndefinedAtom> _undefined;
- atom_collection_vector<SharedLibraryAtom> _shared;
- atom_collection_vector<AbsoluteAtom> _absolute;
+ atom_collection<DefinedAtom> _defined;
+ atom_collection<UndefinedAtom> _undefined;
+ atom_collection<SharedLibraryAtom> _shared;
+ atom_collection<AbsoluteAtom> _absolute;
};
/// \brief Archive library file that may be used as a virtual container
@@ -117,10 +117,10 @@ public:
}
private:
- atom_collection_vector<DefinedAtom> _definedAtoms;
- atom_collection_vector<UndefinedAtom> _undefinedAtoms;
- atom_collection_vector<SharedLibraryAtom> _sharedLibraryAtoms;
- atom_collection_vector<AbsoluteAtom> _absoluteAtoms;
+ atom_collection<DefinedAtom> _definedAtoms;
+ atom_collection<UndefinedAtom> _undefinedAtoms;
+ atom_collection<SharedLibraryAtom> _sharedLibraryAtoms;
+ atom_collection<AbsoluteAtom> _absoluteAtoms;
};
class SimpleReference : public Reference {
diff --git a/lld/lib/Core/File.cpp b/lld/lib/Core/File.cpp
index f07d2cc2674..6ada51601c8 100644
--- a/lld/lib/Core/File.cpp
+++ b/lld/lib/Core/File.cpp
@@ -15,10 +15,10 @@ namespace lld {
File::~File() {}
-File::atom_collection_vector<DefinedAtom> File::_noDefinedAtoms;
-File::atom_collection_vector<UndefinedAtom> File::_noUndefinedAtoms;
-File::atom_collection_vector<SharedLibraryAtom> File::_noSharedLibraryAtoms;
-File::atom_collection_vector<AbsoluteAtom> File::_noAbsoluteAtoms;
+File::atom_collection<DefinedAtom> File::_noDefinedAtoms;
+File::atom_collection<UndefinedAtom> File::_noUndefinedAtoms;
+File::atom_collection<SharedLibraryAtom> File::_noSharedLibraryAtoms;
+File::atom_collection<AbsoluteAtom> File::_noAbsoluteAtoms;
std::error_code File::parse() {
std::lock_guard<std::mutex> lock(_parseMutex);
diff --git a/lld/lib/ReaderWriter/MachO/ExecutableAtoms.hpp b/lld/lib/ReaderWriter/MachO/ExecutableAtoms.hpp
index 26f3b61e43c..6caa10766be 100644
--- a/lld/lib/ReaderWriter/MachO/ExecutableAtoms.hpp
+++ b/lld/lib/ReaderWriter/MachO/ExecutableAtoms.hpp
@@ -123,7 +123,7 @@ public:
private:
- mutable atom_collection_vector<DefinedAtom> _definedAtoms;
+ mutable atom_collection<DefinedAtom> _definedAtoms;
StringRef _machHeaderSymbolName;
};
diff --git a/lld/lib/ReaderWriter/Native/ReaderNative.cpp b/lld/lib/ReaderWriter/Native/ReaderNative.cpp
index 8b3ee16e3b5..0ded101f8b0 100644
--- a/lld/lib/ReaderWriter/Native/ReaderNative.cpp
+++ b/lld/lib/ReaderWriter/Native/ReaderNative.cpp
@@ -398,7 +398,7 @@ private:
// instantiate array of BASeT from IvarsT data in file
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) {
std::vector<const BaseT *> vec(chunk->elementCount);
const size_t ivarElementSize = chunk->fileSize / chunk->elementCount;
@@ -690,10 +690,10 @@ private:
std::unique_ptr<MemoryBuffer> _mb;
const NativeFileHeader* _header;
- atom_collection_vector<DefinedAtom> _definedAtoms;
- atom_collection_vector<UndefinedAtom> _undefinedAtoms;
- atom_collection_vector<SharedLibraryAtom> _sharedLibraryAtoms;
- atom_collection_vector<AbsoluteAtom> _absoluteAtoms;
+ atom_collection<DefinedAtom> _definedAtoms;
+ atom_collection<UndefinedAtom> _undefinedAtoms;
+ atom_collection<SharedLibraryAtom> _sharedLibraryAtoms;
+ atom_collection<AbsoluteAtom> _absoluteAtoms;
const uint8_t* _absAttributes;
uint32_t _absAbsoluteMaxOffset;
const uint8_t* _attributes;
diff --git a/lld/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h b/lld/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h
index 9bf7a9c7111..4bcae11ef8d 100644
--- a/lld/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h
+++ b/lld/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h
@@ -299,7 +299,7 @@ private:
}
PECOFFLinkingContext *_ctx;
- atom_collection_vector<UndefinedAtom> _undefinedAtoms;
+ atom_collection<UndefinedAtom> _undefinedAtoms;
std::mutex _mutex;
llvm::BumpPtrAllocator _alloc;
bool _firstTime;
diff --git a/lld/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp b/lld/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp
index 7d6a73f4440..9a7a5809c90 100644
--- a/lld/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp
+++ b/lld/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp
@@ -159,10 +159,10 @@ private:
std::unique_ptr<const llvm::object::COFFObjectFile> _obj;
std::unique_ptr<MemoryBuffer> _mb;
- atom_collection_vector<DefinedAtom> _definedAtoms;
- atom_collection_vector<UndefinedAtom> _undefinedAtoms;
- atom_collection_vector<SharedLibraryAtom> _sharedLibraryAtoms;
- atom_collection_vector<AbsoluteAtom> _absoluteAtoms;
+ atom_collection<DefinedAtom> _definedAtoms;
+ atom_collection<UndefinedAtom> _undefinedAtoms;
+ atom_collection<SharedLibraryAtom> _sharedLibraryAtoms;
+ atom_collection<AbsoluteAtom> _absoluteAtoms;
// The target type of the object.
Reference::KindArch _referenceArch;
diff --git a/lld/lib/ReaderWriter/PECOFF/ReaderImportHeader.cpp b/lld/lib/ReaderWriter/PECOFF/ReaderImportHeader.cpp
index 0ddffb0f419..26bdfaa1460 100644
--- a/lld/lib/ReaderWriter/PECOFF/ReaderImportHeader.cpp
+++ b/lld/lib/ReaderWriter/PECOFF/ReaderImportHeader.cpp
@@ -315,8 +315,8 @@ private:
_definedAtoms._atoms.push_back(atom);
}
- atom_collection_vector<DefinedAtom> _definedAtoms;
- atom_collection_vector<SharedLibraryAtom> _sharedLibraryAtoms;
+ atom_collection<DefinedAtom> _definedAtoms;
+ atom_collection<SharedLibraryAtom> _sharedLibraryAtoms;
mutable llvm::BumpPtrAllocator _alloc;
// Does the same thing as StringRef::ltrim() but removes at most one
diff --git a/lld/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp b/lld/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp
index 00cf60f7fd3..3bf8a943637 100644
--- a/lld/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp
+++ b/lld/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp
@@ -215,8 +215,7 @@ private:
NameToAtom _groupMap;
};
-template <typename T>
-using AtomList = lld::File::atom_collection_vector<T>;
+template <typename T> using AtomList = lld::File::atom_collection<T>;
/// Mapping of kind: field in yaml files.
enum FileKinds {
OpenPOWER on IntegriCloud