From 552074f18e922e0301671a9497003fda235476fb Mon Sep 17 00:00:00 2001 From: "Michael J. Spencer" Date: Fri, 4 Jan 2013 21:18:34 +0000 Subject: [PATCH] Style fixes. llvm-svn: 171531 --- lld/include/lld/Core/DefinedAtom.h | 144 +++++++++--------- lld/include/lld/Core/File.h | 58 +++---- lld/include/lld/Core/Pass.h | 49 +++--- lld/lib/Core/SymbolTable.cpp | 9 -- lld/tools/lld-core/TestingHelpers.hpp | 211 ++++++++++++-------------- 5 files changed, 208 insertions(+), 263 deletions(-) diff --git a/lld/include/lld/Core/DefinedAtom.h b/lld/include/lld/Core/DefinedAtom.h index ffb22c23a76b..ab5f691c34ab 100644 --- a/lld/include/lld/Core/DefinedAtom.h +++ b/lld/include/lld/Core/DefinedAtom.h @@ -7,8 +7,8 @@ // //===----------------------------------------------------------------------===// -#ifndef LLD_CORE_DEFINED_ATOM_H_ -#define LLD_CORE_DEFINED_ATOM_H_ +#ifndef LLD_CORE_DEFINED_ATOM_H +#define LLD_CORE_DEFINED_ATOM_H #include "lld/Core/Atom.h" #include "lld/Core/Reference.h" @@ -16,18 +16,18 @@ namespace llvm { template class ArrayRef; - class StringRef; } namespace lld { - class File; -/// An atom is the fundamental unit of linking. A C function or global variable -/// is an atom. An atom has content and attributes. The content of a function -/// atom is the instructions that implement the function. The content of a -/// global variable atom is its initial bytes. +/// \brief The fundamental unit of linking. +/// +/// A C function or global variable is an atom. An atom has content and +/// attributes. The content of a function atom is the instructions that +/// implement the function. The content of a global variable atom is its +/// initial bytes. /// /// Here are some example attribute sets for common atoms. If a particular /// attribute is not listed, the default values are: definition=regular, @@ -175,69 +175,72 @@ public: uint16_t modulus; }; - /// ordinal - returns a value for the order of this Atom within its file. - /// This is used by the linker to order the layout of Atoms so that - /// the resulting image is stable and reproducible. + /// \brief returns a value for the order of this Atom within its file. + /// + /// This is used by the linker to order the layout of Atoms so that the + /// resulting image is stable and reproducible. virtual uint64_t ordinal() const = 0; - /// size - the number of bytes of space this atom's content will occupy - /// in the final linked image. For a function atom, it is the number - /// of bytes of code in the function. + /// \brief the number of bytes of space this atom's content will occupy in the + /// final linked image. + /// + /// For a function atom, it is the number of bytes of code in the function. virtual uint64_t size() const = 0; - /// scope - The visibility of this atom to other atoms. C static functions - /// have scope scopeTranslationUnit. Regular C functions have scope - /// scopeGlobal. Functions compiled with visibility=hidden have scope - /// scopeLinkageUnit so they can be see by other atoms being linked but not - /// by the OS loader. + /// \brief The visibility of this atom to other atoms. + /// + /// C static functions have scope scopeTranslationUnit. Regular C functions + /// have scope scopeGlobal. Functions compiled with visibility=hidden have + /// scope scopeLinkageUnit so they can be see by other atoms being linked but + /// not by the OS loader. virtual Scope scope() const = 0; - /// interposable - Whether the linker should use direct or indirect - /// access to this atom. + /// \brief Whether the linker should use direct or indirect access to this + /// atom. virtual Interposable interposable() const = 0; - /// merge - how the linker should handle if multiple atoms have - /// the same name. + /// \brief how the linker should handle if multiple atoms have the same name. virtual Merge merge() const = 0; - /// contentType - The type of this atom, such as code or data. + /// \brief The type of this atom, such as code or data. virtual ContentType contentType() const = 0; - /// alignment - The alignment constraints on how this atom must be laid out - /// in the final linked image (e.g. 16-byte aligned). + /// \brief The alignment constraints on how this atom must be laid out in the + /// final linked image (e.g. 16-byte aligned). virtual Alignment alignment() const = 0; - /// sectionChoice - Whether this atom must be in a specially named section - /// in the final linked image, or if the linker can infer the section - /// based on the contentType(). + /// \brief Whether this atom must be in a specially named section in the final + /// linked image, or if the linker can infer the section based on the + /// contentType(). virtual SectionChoice sectionChoice() const = 0; - /// customSectionName - If sectionChoice() != sectionBasedOnContent, then - /// this return the name of the section the atom should be placed into. + /// \brief If sectionChoice() != sectionBasedOnContent, then this return the + /// name of the section the atom should be placed into. virtual StringRef customSectionName() const = 0; - /// deadStrip - constraints on whether the linker may dead strip away - /// this atom. + /// \brief constraints on whether the linker may dead strip away this atom. virtual DeadStripKind deadStrip() const = 0; - /// permissions - Returns the OS memory protections required for this atom's - /// content at runtime. A function atom is R_X, a global variable is RW_, - /// and a read-only constant is R__. + /// \brief Returns the OS memory protections required for this atom's content + /// at runtime. + /// + /// A function atom is R_X, a global variable is RW_, and a read-only constant + /// is R__. virtual ContentPermissions permissions() const = 0; - /// isThumb - only applicable to ARM code. Tells the linker if the code - /// uses thumb or arm instructions. The linker needs to know this to - /// set the low bit of pointers to thumb functions. + /// \brief only applicable to ARM code. Tells the linker if the code uses + /// thumb or arm instructions. The linker needs to know this to set the low + /// bit of pointers to thumb functions. virtual bool isThumb() const = 0; - /// isAlias - means this is a zero size atom that exists to provide an - /// alternate name for another atom. Alias atoms must have a special - /// Reference to the atom they alias which the layout engine recognizes - /// and forces the alias atom to layout right before the target atom. + /// \brief means this is a zero size atom that exists to provide an alternate + /// name for another atom. Alias atoms must have a special Reference to the + /// atom they alias which the layout engine recognizes and forces the alias + /// atom to layout right before the target atom. virtual bool isAlias() const = 0; - /// rawContent - returns a reference to the raw (unrelocated) bytes of - /// this Atom's content. + /// \brief returns a reference to the raw (unrelocated) bytes of this Atom's + /// content. virtual ArrayRef rawContent() const = 0; /// This class abstracts iterating over the sequence of References @@ -245,62 +248,59 @@ public: /// the derefIterator() and incrementIterator() methods. class reference_iterator { public: - reference_iterator(const DefinedAtom& a, const void* it) - : _atom(a), _it(it) { } + reference_iterator(const DefinedAtom &a, const void *it) + : _atom(a), _it(it) { } - const Reference* operator*() const { + const Reference *operator*() const { return _atom.derefIterator(_it); } - const Reference* operator->() const { + const Reference *operator->() const { return _atom.derefIterator(_it); } - bool operator!=(const reference_iterator& other) const { - return (this->_it != other._it); + bool operator!=(const reference_iterator &other) const { + return _it != other._it; } - reference_iterator& operator++() { + reference_iterator &operator++() { _atom.incrementIterator(_it); return *this; } private: - const DefinedAtom& _atom; - const void* _it; + const DefinedAtom &_atom; + const void *_it; }; - /// Returns an iterator to the beginning of this Atom's References + /// \brief Returns an iterator to the beginning of this Atom's References. virtual reference_iterator begin() const = 0; - /// Returns an iterator to the end of this Atom's References + /// \brief Returns an iterator to the end of this Atom's References. virtual reference_iterator end() const = 0; static inline bool classof(const Atom *a) { return a->definition() == definitionRegular; } - static inline bool classof(const DefinedAtom *) { return true; } protected: - /// DefinedAtom is an abstract base class. - /// Only subclasses can access constructor. + // DefinedAtom is an abstract base class. Only subclasses can access + // constructor. DefinedAtom() : Atom(definitionRegular) { } - /// The memory for DefinedAtom objects is always managed by the owning File - /// object. Therefore, no one but the owning File object should call - /// delete on an Atom. In fact, some File objects may bulk allocate - /// an array of Atoms, so they cannot be individually deleted by anyone. + // The memory for DefinedAtom objects is always managed by the owning File + // object. Therefore, no one but the owning File object should call delete on + // an Atom. In fact, some File objects may bulk allocate an array of Atoms, + // so they cannot be individually deleted by anyone. virtual ~DefinedAtom() {} - /// Returns a pointer to the Reference object that the abstract + /// \brief Returns a pointer to the Reference object that the abstract /// iterator "points" to. - virtual const Reference* derefIterator(const void* iter) const = 0; - - /// Adjusts the abstract iterator to "point" to the next Reference object - /// for this Atom. - virtual void incrementIterator(const void*& iter) const = 0; + virtual const Reference *derefIterator(const void *iter) const = 0; + /// \brief Adjusts the abstract iterator to "point" to the next Reference + /// object for this Atom. + virtual void incrementIterator(const void *&iter) const = 0; }; +} // end namespace lld -} // namespace lld - -#endif // LLD_CORE_DEFINED_ATOM_H_ +#endif diff --git a/lld/include/lld/Core/File.h b/lld/include/lld/Core/File.h index 8f81a9e7a9b3..4042da423673 100644 --- a/lld/include/lld/Core/File.h +++ b/lld/include/lld/Core/File.h @@ -20,20 +20,18 @@ #include namespace lld { - - /// -/// Every Atom is owned by some File. A common scenario is for a single +/// Every Atom is owned by some File. A common scenario is for a single /// object file (.o) to be parsed by some reader and produce a single -/// File object that represents the content of that object file. +/// File object that represents the content of that object file. /// /// To iterate through the Atoms in a File there are four methods that /// return collections. For instance to iterate through all the DefinedAtoms -/// in a File object use: +/// in a File object use: /// for (const DefinedAtoms *atom : file->defined()) { /// } /// -/// The Atom objects in a File are owned by the File object. The Atom objects +/// The Atom objects in a File are owned by the File object. The Atom objects /// are destroyed when the File object is destroyed. /// class File { @@ -59,20 +57,19 @@ public: } /// Returns the path of the source file used to create the object - /// file which this (File) object represents. This information is usually - /// parsed out of the DWARF debug information. If the source file cannot + /// file which this (File) object represents. This information is usually + /// parsed out of the DWARF debug information. If the source file cannot /// be ascertained, this method returns the empty string. virtual StringRef translationUnitSource() const; - - static inline bool classof(const File *) { - return true; + static inline bool classof(const File *) { + return true; } protected: template class atom_iterator; // forward reference public: - + /// For use interating over DefinedAtoms in this File. typedef atom_iterator defined_iterator; @@ -85,24 +82,19 @@ public: /// For use interating over AbsoluteAtoms in this File. typedef atom_iterator absolute_iterator; - - /// Note: this method is not const. All File objects instantiated by reading - /// an object file from disk are "const File*" objects and cannot be + /// an object file from disk are "const File*" objects and cannot be /// modified. This method can only be used with temporay File objects /// such as is seen by each Pass object when it runs. - /// This method is *not* safe to call while iterating through this File's - /// Atoms. A Pass should queue up any Atoms it want to add and then + /// This method is *not* safe to call while iterating through this File's + /// Atoms. A Pass should queue up any Atoms it want to add and then /// call this method when no longer iterating over the File's Atoms. virtual void addAtom(const Atom&) = 0; - - protected: - /// only subclasses of File can be instantiated + /// only subclasses of File can be instantiated File(StringRef p) : _path(p) {} - /// Different object file readers may instantiate and manage atoms with /// different data structures. This class is a collection abstraction. /// Each concrete File instance must implement these atom_collection @@ -117,7 +109,6 @@ protected: virtual void next(const void*& it) const = 0; }; - /// The class is the iterator type used to iterate through a File's Atoms. /// This iterator delegates the work to the associated atom_collection object. /// There are four kinds of Atoms, so this iterator is templated on @@ -125,14 +116,14 @@ protected: template class atom_iterator { public: - atom_iterator(const atom_collection& c, const void* it) + atom_iterator(const atom_collection& c, const void* it) : _collection(c), _it(it) { } const T* operator*() const { return _collection.deref(_it); } - const T* operator->() const { + return _collection.deref(_it); } @@ -148,35 +139,35 @@ protected: const atom_collection& _collection; const void* _it; }; - + public: - /// Must be implemented to return the atom_collection object for + /// Must be implemented to return the atom_collection object for /// all DefinedAtoms in this File. virtual const atom_collection& defined() const = 0; - /// Must be implemented to return the atom_collection object for + /// Must be implemented to return the atom_collection object for /// all UndefinedAtomw in this File. virtual const atom_collection& undefined() const = 0; - /// Must be implemented to return the atom_collection object for + /// Must be implemented to return the atom_collection object for /// all SharedLibraryAtoms in this File. virtual const atom_collection& sharedLibrary() const = 0; - /// Must be implemented to return the atom_collection object for + /// Must be implemented to return the atom_collection object for /// all AbsoluteAtoms in this File. virtual const atom_collection& absolute() const = 0; protected: /// This is a convenience class for File subclasses which manage their - /// atoms as a simple std::vector<>. + /// atoms as a simple std::vector<>. template class atom_collection_vector : public atom_collection { public: - virtual atom_iterator begin() const { + virtual atom_iterator begin() const { return atom_iterator(*this, reinterpret_cast (_atoms.data())); } - virtual atom_iterator end() const{ + virtual atom_iterator end() const{ return atom_iterator(*this, reinterpret_cast (_atoms.data() + _atoms.size())); } @@ -190,10 +181,9 @@ protected: } std::vector _atoms; }; - + StringRef _path; }; - } // namespace lld #endif // LLD_CORE_FILE_H_ diff --git a/lld/include/lld/Core/Pass.h b/lld/include/lld/Core/Pass.h index 6316f7e65d58..7d854d3098eb 100644 --- a/lld/include/lld/Core/Pass.h +++ b/lld/include/lld/Core/Pass.h @@ -18,8 +18,6 @@ namespace lld { class DefinedAtom; - -/// /// Once the core linking is done (which resolves references, coalesces atoms /// and produces a complete Atom graph), the linker runs a series of passes /// on the Atom graph. The graph is modeled as a File, which means the pass @@ -30,26 +28,21 @@ class DefinedAtom; /// actual work in it perform() method. It can iterator over Atoms in the /// graph using the *begin()/*end() atom iterator of the File. It can add /// new Atoms to the graph using the File's addAtom() method. -/// -/// class Pass { public: virtual ~Pass() { } - /// Do the actual work of the Pass. - virtual void perform(File& mergedFile) = 0; + /// Do the actual work of the Pass. + virtual void perform(File &mergedFile) = 0; protected: // Only subclassess can be instantiated. Pass() { } }; - -/// /// Pass for adding stubs (PLT entries) for calls to functions -/// outside the linkage unit. This class is subclassed by each +/// outside the linkage unit. This class is subclassed by each /// file format Writer which implements the pure virtual methods. -/// class StubsPass : public Pass { public: StubsPass() : Pass() {} @@ -57,7 +50,7 @@ public: /// Scans all Atoms looking for call-site uses of SharedLibraryAtoms /// and transfroms the call-site to call a stub instead using the /// helper methods below. - virtual void perform(File& mergedFile); + virtual void perform(File &mergedFile); /// If true, the pass should use stubs for references /// to shared library symbols. If false, the pass @@ -65,29 +58,25 @@ public: /// runtime loader will use to patch the program at runtime. virtual bool noTextRelocs() = 0; - /// Returns whether the Reference kind is for a call site. The pass + /// Returns whether the Reference kind is for a call site. The pass /// uses this to find calls that need to be indirected through a stub. virtual bool isCallSite(Reference::Kind) = 0; - + /// Returns a file format specific atom for a stub/PLT entry which contains - /// instructions which jump to the specified atom. May be called multiple - /// times for the same target atom, in which case this method should return - /// the same stub atom. - virtual const DefinedAtom* getStub(const Atom &target) = 0; + /// instructions which jump to the specified atom. May be called multiple + /// times for the same target atom, in which case this method should return + /// the same stub atom. + virtual const DefinedAtom *getStub(const Atom &target) = 0; /// After the default implementation of perform() is done calling getStub(), - /// it will call this method to add all the stub (and support) atoms to the + /// it will call this method to add all the stub (and support) atoms to the /// master file object. virtual void addStubAtoms(File &masterFile) = 0; }; - - -/// /// Pass for adding GOT entries for pointers to functions/data -/// outside the linkage unit. This class is subclassed by each +/// outside the linkage unit. This class is subclassed by each /// file format Writer which implements the pure virtual methods. -/// class GOTPass : public Pass { public: GOTPass() : Pass() {} @@ -95,7 +84,7 @@ public: /// Scans all Atoms looking for pointer to SharedLibraryAtoms /// and transfroms them to a pointer to a GOT entry using the /// helper methods below. - virtual void perform(File& mergedFile); + virtual void perform(File &mergedFile); /// If true, the pass will use GOT entries for references /// to shared library symbols. If false, the pass @@ -104,13 +93,13 @@ public: virtual bool noTextRelocs() = 0; /// Returns whether the Reference kind is a pre-instantiated GOT access. - /// The default implementation of perform() uses this to figure out + /// The default implementation of perform() uses this to figure out /// what GOT entries to instantiate. - virtual bool isGOTAccess(Reference::Kind, bool& canBypassGOT) = 0; + virtual bool isGOTAccess(Reference::Kind, bool &canBypassGOT) = 0; - /// The file format Writer needs to alter the reference kind from a + /// The file format Writer needs to alter the reference kind from a /// pre-instantiated GOT access to an actual access. If targetIsNowGOT is - /// true, the pass has instantiated a GOT atom and altered the reference's + /// true, the pass has instantiated a GOT atom and altered the reference's /// target to point to that atom. If targetIsNowGOT is false, the pass /// determined a GOT entry is not needed because the reference site can /// directly access the target. @@ -118,10 +107,8 @@ public: /// Returns a file format specific atom for a GOT entry targeting /// the specified atom. - virtual const DefinedAtom* makeGOTEntry(const Atom& target) = 0; + virtual const DefinedAtom *makeGOTEntry(const Atom &target) = 0; }; - - } // namespace lld #endif // LLD_CORE_PASS_H_ diff --git a/lld/lib/Core/SymbolTable.cpp b/lld/lib/Core/SymbolTable.cpp index 926f656a9350..b3fe8e8a50e5 100644 --- a/lld/lib/Core/SymbolTable.cpp +++ b/lld/lib/Core/SymbolTable.cpp @@ -29,7 +29,6 @@ #include namespace lld { - SymbolTable::SymbolTable(ResolverOptions &opts) : _options(opts) { } @@ -90,7 +89,6 @@ static NameCollisionResolution collide(Atom::Definition first, return cases[first][second]; } - enum MergeResolution { MCR_First, MCR_Second, @@ -123,7 +121,6 @@ static MergeResolution mergeSelect(DefinedAtom::Merge first, return mergeCases[first][second]; } - void SymbolTable::addByName(const Atom & newAtom) { StringRef name = newAtom.name(); const Atom *existing = this->findByName(name); @@ -249,7 +246,6 @@ void SymbolTable::addByName(const Atom & newAtom) { } } - unsigned SymbolTable::AtomMappingInfo::getHashValue(const DefinedAtom * const atom) { unsigned hash = atom->size(); if ( atom->contentType() != DefinedAtom::typeZeroFill ) { @@ -264,7 +260,6 @@ unsigned SymbolTable::AtomMappingInfo::getHashValue(const DefinedAtom * const at return hash; } - bool SymbolTable::AtomMappingInfo::isEqual(const DefinedAtom * const l, const DefinedAtom * const r) { if ( l == r ) @@ -287,7 +282,6 @@ bool SymbolTable::AtomMappingInfo::isEqual(const DefinedAtom * const l, return lc.equals(rc); } - void SymbolTable::addByContent(const DefinedAtom & newAtom) { AtomContentSet::iterator pos = _contentTable.find(&newAtom); if ( pos == _contentTable.end() ) { @@ -299,8 +293,6 @@ void SymbolTable::addByContent(const DefinedAtom & newAtom) { _replacedAtoms[&newAtom] = existing; } - - const Atom *SymbolTable::findByName(StringRef sym) { NameToAtom::iterator pos = _nameTable.find(sym); if (pos == _nameTable.end()) @@ -350,5 +342,4 @@ void SymbolTable::tentativeDefinitions(std::vector &names) { } } } - } // namespace lld diff --git a/lld/tools/lld-core/TestingHelpers.hpp b/lld/tools/lld-core/TestingHelpers.hpp index f6abb4f0df31..5f065d803fb4 100644 --- a/lld/tools/lld-core/TestingHelpers.hpp +++ b/lld/tools/lld-core/TestingHelpers.hpp @@ -30,24 +30,22 @@ using namespace lld; -// -// Simple atom created by the stubs pass. -// +/// \brief Simple atom created by the stubs pass. class TestingStubAtom : public DefinedAtom { public: TestingStubAtom(const File &F, const Atom&) : _file(F) { static uint32_t lastOrdinal = 0; - _ordinal = lastOrdinal++; + _ordinal = lastOrdinal++; } - virtual const File& file() const { + virtual const File &file() const { return _file; } virtual StringRef name() const { return StringRef(); } - + virtual uint64_t ordinal() const { return _ordinal; } @@ -59,92 +57,86 @@ public: virtual Scope scope() const { return DefinedAtom::scopeLinkageUnit; } - + virtual Interposable interposable() const { return DefinedAtom::interposeNo; } - + virtual Merge merge() const { return DefinedAtom::mergeNo; } - + virtual ContentType contentType() const { return DefinedAtom::typeStub; } virtual Alignment alignment() const { - return Alignment(0,0); + return Alignment(0, 0); } - + virtual SectionChoice sectionChoice() const { return DefinedAtom::sectionBasedOnContent; } - + virtual StringRef customSectionName() const { return StringRef(); } virtual DeadStripKind deadStrip() const { return DefinedAtom::deadStripNormal; } - + virtual ContentPermissions permissions() const { return DefinedAtom::permR_X; } - + virtual bool isThumb() const { return false; } - + virtual bool isAlias() const { return false; } - + virtual ArrayRef rawContent() const { return ArrayRef(); } - + virtual reference_iterator begin() const { return reference_iterator(*this, nullptr); } - + virtual reference_iterator end() const { return reference_iterator(*this, nullptr); } - - virtual const Reference* derefIterator(const void* iter) const { + + virtual const Reference *derefIterator(const void *iter) const { return nullptr; } - - virtual void incrementIterator(const void*& iter) const { - + + virtual void incrementIterator(const void *&iter) const { } - + private: - const File& _file; - uint32_t _ordinal; + const File &_file; + uint32_t _ordinal; }; - - - -// -// Simple atom created by the GOT pass. -// +/// \brief Simple atom created by the GOT pass. class TestingGOTAtom : public DefinedAtom { public: TestingGOTAtom(const File &F, const Atom&) : _file(F) { static uint32_t lastOrdinal = 0; - _ordinal = lastOrdinal++; + _ordinal = lastOrdinal++; } - virtual const File& file() const { + virtual const File &file() const { return _file; } virtual StringRef name() const { return StringRef(); } - + virtual uint64_t ordinal() const { return _ordinal; } @@ -156,131 +148,123 @@ public: virtual Scope scope() const { return DefinedAtom::scopeLinkageUnit; } - + virtual Interposable interposable() const { return DefinedAtom::interposeNo; } - + virtual Merge merge() const { return DefinedAtom::mergeNo; } - + virtual ContentType contentType() const { return DefinedAtom::typeGOT; } virtual Alignment alignment() const { - return Alignment(3,0); + return Alignment(3, 0); } - + virtual SectionChoice sectionChoice() const { return DefinedAtom::sectionBasedOnContent; } - + virtual StringRef customSectionName() const { return StringRef(); } + virtual DeadStripKind deadStrip() const { return DefinedAtom::deadStripNormal; } - + virtual ContentPermissions permissions() const { return DefinedAtom::permRW_; } - + virtual bool isThumb() const { return false; } - + virtual bool isAlias() const { return false; } - + virtual ArrayRef rawContent() const { return ArrayRef(); } - + virtual reference_iterator begin() const { return reference_iterator(*this, nullptr); } - + virtual reference_iterator end() const { return reference_iterator(*this, nullptr); } - - virtual const Reference* derefIterator(const void* iter) const { + + virtual const Reference *derefIterator(const void *iter) const { return nullptr; } - - virtual void incrementIterator(const void*& iter) const { - + + virtual void incrementIterator(const void *&iter) const { } - + private: - const File& _file; - uint32_t _ordinal; + const File &_file; + uint32_t _ordinal; }; - - class TestingPassFile : public File { public: TestingPassFile() : File("Testing pass") { } - + virtual void addAtom(const Atom &atom) { - if (const DefinedAtom* defAtom = dyn_cast(&atom)) { + if (const DefinedAtom *defAtom = dyn_cast(&atom)) _definedAtoms._atoms.push_back(defAtom); - } - else { - assert(0 && "atom has unknown definition kind"); - } + else + llvm_unreachable("atom has unknown definition kind"); } - - virtual const atom_collection& defined() const { + + virtual const atom_collection &defined() const { return _definedAtoms; } - virtual const atom_collection& undefined() const { + virtual const atom_collection &undefined() const { return _undefinedAtoms; } - virtual const atom_collection& sharedLibrary() const { + virtual const atom_collection &sharedLibrary() const { return _sharedLibraryAtoms; } - virtual const atom_collection& absolute() const { + virtual const atom_collection &absolute() const { return _absoluteAtoms; } - + private: - atom_collection_vector _definedAtoms; - atom_collection_vector _undefinedAtoms; - atom_collection_vector _sharedLibraryAtoms; - atom_collection_vector _absoluteAtoms; + atom_collection_vector _definedAtoms; + atom_collection_vector _undefinedAtoms; + atom_collection_vector _sharedLibraryAtoms; + atom_collection_vector _absoluteAtoms; }; - - struct TestingKindMapping { - const char* string; - Reference::Kind value; - bool isBranch; - bool isGotLoad; - bool isGotUse; + const char *string; + Reference::Kind value; + bool isBranch; + bool isGotLoad; + bool isGotUse; }; // // Table of fixup kinds in YAML documents used for testing // const TestingKindMapping sKinds[] = { - { "call32", 2, true, false, false}, - { "pcrel32", 3, false, false, false }, - { "gotLoad32", 7, false, true, true }, - { "gotUse32", 9, false, false, true }, - { "lea32wasGot", 8, false, false, false }, - { nullptr, 0, false, false, false } + {"call32", 2, true, false, false}, + {"pcrel32", 3, false, false, false}, + {"gotLoad32", 7, false, true, true}, + {"gotUse32", 9, false, false, true}, + {"lea32wasGot", 8, false, false, false}, + {nullptr, 0, false, false, false} }; - - class TestingStubsPass : public StubsPass { public: virtual bool noTextRelocs() { @@ -288,32 +272,29 @@ public: } virtual bool isCallSite(Reference::Kind kind) { - for (const TestingKindMapping* p = sKinds; p->string != nullptr; ++p) { - if ( kind == p->value ) + for (const TestingKindMapping *p = sKinds; p->string != nullptr; ++p) { + if (kind == p->value) return p->isBranch; } return false; } - virtual const DefinedAtom* getStub(const Atom& target) { + virtual const DefinedAtom *getStub(const Atom &target) { const DefinedAtom *result = new TestingStubAtom(_file, target); _file.addAtom(*result); return result; } - virtual void addStubAtoms(File &mergedFile) { for (const DefinedAtom *stub : _file.defined() ) { mergedFile.addAtom(*stub); } } - + private: - TestingPassFile _file; + TestingPassFile _file; }; - - class TestingGOTPass : public GOTPass { public: virtual bool noTextRelocs() { @@ -321,31 +302,30 @@ public: } virtual bool isGOTAccess(Reference::Kind kind, bool &canBypassGOT) { - for (const TestingKindMapping* p = sKinds; p->string != nullptr; ++p) { - if ( kind == p->value ) { + for (const TestingKindMapping *p = sKinds; p->string != nullptr; ++p) { + if (kind == p->value) { canBypassGOT = p->isGotLoad; - return (p->isGotUse || p->isGotLoad); + return p->isGotUse || p->isGotLoad; } } return false; } virtual void updateReferenceToGOT(const Reference *ref, bool targetIsNowGOT) { - if ( targetIsNowGOT ) - (const_cast(ref))->setKind(3); // pcrel32 + if (targetIsNowGOT) + const_cast(ref)->setKind(3); // pcrel32 else - (const_cast(ref))->setKind(8); // lea32wasGot + const_cast(ref)->setKind(8); // lea32wasGot } - virtual const DefinedAtom* makeGOTEntry(const Atom &target) { + virtual const DefinedAtom *makeGOTEntry(const Atom &target) { return new TestingGOTAtom(_file, target); } - + private: - TestingPassFile _file; + TestingPassFile _file; }; - class TestingWriterOptionsYAML : public lld::WriterOptionsYAML { public: TestingWriterOptionsYAML(bool stubs, bool got) @@ -353,22 +333,22 @@ public: } virtual StubsPass *stubPass() const { - if ( _doStubs ) + if (_doStubs) return const_cast(&_stubsPass); else return nullptr; } - + virtual GOTPass *gotPass() const { - if ( _doGOT ) + if (_doGOT) return const_cast(&_gotPass); else return nullptr; } - + virtual StringRef kindToString(Reference::Kind value) const { - for (const TestingKindMapping* p = sKinds; p->string != nullptr; ++p) { - if ( value == p->value) + for (const TestingKindMapping *p = sKinds; p->string != nullptr; ++p) { + if (value == p->value) return p->string; } return StringRef("???"); @@ -380,11 +360,10 @@ private: TestingGOTPass _gotPass; }; - class TestingReaderOptionsYAML : public lld::ReaderOptionsYAML { virtual Reference::Kind kindFromString(StringRef kindName) const { - for (const TestingKindMapping* p = sKinds; p->string != nullptr; ++p) { - if ( kindName.equals(p->string) ) + for (const TestingKindMapping *p = sKinds; p->string != nullptr; ++p) { + if (kindName.equals(p->string)) return p->value; } int k; @@ -394,6 +373,4 @@ class TestingReaderOptionsYAML : public lld::ReaderOptionsYAML { } }; - - #endif // LLD_TOOLS_TESTING_HELPERS_H_ -- GitLab