From 19c4756ff2429c05c2f3f7c8cbabbd258676074c Mon Sep 17 00:00:00 2001 From: "Michael J. Spencer" Date: Thu, 24 Jan 2013 22:52:25 +0000 Subject: [PATCH] Move SimpleAtoms.h to ReaderWriter. llvm-svn: 173380 --- lld/include/lld/ReaderWriter/Simple.h | 189 ++++++++++++++++++ lld/lib/ReaderWriter/MachO/ExecutableAtoms.hpp | 3 +- lld/lib/ReaderWriter/MachO/SimpleAtoms.hpp | 252 ------------------------ lld/lib/ReaderWriter/MachO/StubAtoms.hpp | 2 +- lld/lib/ReaderWriter/MachO/StubAtoms_x86.hpp | 1 - lld/lib/ReaderWriter/MachO/StubAtoms_x86_64.hpp | 1 - lld/lib/ReaderWriter/MachO/StubsPass.hpp | 2 +- 7 files changed, 192 insertions(+), 258 deletions(-) create mode 100644 lld/include/lld/ReaderWriter/Simple.h delete mode 100644 lld/lib/ReaderWriter/MachO/SimpleAtoms.hpp diff --git a/lld/include/lld/ReaderWriter/Simple.h b/lld/include/lld/ReaderWriter/Simple.h new file mode 100644 index 0000000..7ebddba --- /dev/null +++ b/lld/include/lld/ReaderWriter/Simple.h @@ -0,0 +1,189 @@ +//===- lld/Core/Simple.h - Simple implementations of Atom and File --------===// +// +// The LLVM Linker +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +/// +/// \file +/// \brief Provide simple implementations for Atoms and File. +/// +//===----------------------------------------------------------------------===// + +#ifndef LLD_CORE_SIMPLE_H +#define LLD_CORE_SIMPLE_H + +#include "lld/Core/DefinedAtom.h" +#include "lld/Core/File.h" +#include "lld/Core/Reference.h" +#include "lld/Core/UndefinedAtom.h" + +namespace lld { +class SimpleFile : public MutableFile { +public: + SimpleFile(StringRef path) : MutableFile(path) {} + + virtual void addAtom(const Atom &atom) { + if (const DefinedAtom *defAtom = dyn_cast(&atom)) { + _definedAtoms._atoms.push_back(defAtom); + } else if ( + const UndefinedAtom *undefAtom = dyn_cast(&atom)) { + _undefinedAtoms._atoms.push_back(undefAtom); + } else if ( + const SharedLibraryAtom *slAtom = dyn_cast(&atom)) { + _sharedLibraryAtoms._atoms.push_back(slAtom); + } else if (const AbsoluteAtom *abAtom = dyn_cast(&atom)) { + _absoluteAtoms._atoms.push_back(abAtom); + } else { + llvm_unreachable("atom has unknown definition kind"); + } + } + + virtual const atom_collection &defined() const { + return _definedAtoms; + } + + virtual const atom_collection &undefined() const { + return _undefinedAtoms; + } + + virtual const atom_collection &sharedLibrary() const { + return _sharedLibraryAtoms; + } + + virtual const atom_collection &absolute() const { + return _absoluteAtoms; + } + + virtual DefinedAtomRange definedAtoms() { + return make_range(_definedAtoms._atoms); + } + +private: + atom_collection_vector _definedAtoms; + atom_collection_vector _undefinedAtoms; + atom_collection_vector _sharedLibraryAtoms; + atom_collection_vector _absoluteAtoms; +}; + +class SimpleReference : public Reference { +public: + SimpleReference(Reference::Kind k, uint64_t off, const Atom *t, + Reference::Addend a) + : _target(t), _offsetInAtom(off), _addend(a), _kind(k) {} + + virtual uint64_t offsetInAtom() const { return _offsetInAtom; } + + virtual Kind kind() const { return _kind; } + + virtual void setKind(Kind k) { _kind = k; } + + virtual const Atom *target() const { return _target; } + + virtual Addend addend() const { return _addend; } + + virtual void setAddend(Addend a) { _addend = a; } + + virtual void setTarget(const Atom *newAtom) { _target = newAtom; } +private: + const Atom *_target; + uint64_t _offsetInAtom; + Addend _addend; + Kind _kind; +}; + +class SimpleDefinedAtom : public DefinedAtom { +public: + SimpleDefinedAtom(const File &f) : _file(f) { + static uint32_t lastOrdinal = 0; + _ordinal = lastOrdinal++; + } + + virtual const File &file() const { return _file; } + + virtual StringRef name() const { return StringRef(); } + + virtual uint64_t ordinal() const { return _ordinal; } + + virtual Scope scope() const { return DefinedAtom::scopeLinkageUnit; } + + virtual Interposable interposable() const { return DefinedAtom::interposeNo; } + + virtual Merge merge() const { return DefinedAtom::mergeNo; } + + virtual Alignment alignment() const { return Alignment(0, 0); } + + virtual SectionChoice sectionChoice() const { + return DefinedAtom::sectionBasedOnContent; + } + + virtual SectionPosition sectionPosition() const { + return DefinedAtom::sectionPositionAny; + } + + virtual StringRef customSectionName() const { return StringRef(); } + virtual DeadStripKind deadStrip() const { + return DefinedAtom::deadStripNormal; + } + + virtual bool isThumb() const { return false; } + + virtual bool isAlias() const { return false; } + + virtual DefinedAtom::reference_iterator begin() const { + uintptr_t index = 0; + const void *it = reinterpret_cast(index); + return reference_iterator(*this, it); + } + + virtual DefinedAtom::reference_iterator end() const { + uintptr_t index = _references.size(); + const void *it = reinterpret_cast(index); + return reference_iterator(*this, it); + } + + virtual const Reference *derefIterator(const void *it) const { + uintptr_t index = reinterpret_cast(it); + assert(index < _references.size()); + return &_references[index]; + } + + virtual void incrementIterator(const void *&it) const { + uintptr_t index = reinterpret_cast(it); + ++index; + it = reinterpret_cast(index); + } + + void addReference(Reference::Kind kind, uint64_t offset, const Atom *target, + Reference::Addend addend) { + _references.push_back(SimpleReference(kind, offset, target, addend)); + } + +private: + const File &_file; + uint32_t _ordinal; + std::vector _references; +}; + +class SimpleUndefinedAtom : public UndefinedAtom { +public: + SimpleUndefinedAtom(const File &f, StringRef name) : _file(f), _name(name) {} + + /// file - returns the File that produced/owns this Atom + virtual const class File &file() const { return _file; } + + /// name - The name of the atom. For a function atom, it is the (mangled) + /// name of the function. + virtual StringRef name() const { return _name; } + + virtual CanBeNull canBeNull() const { return UndefinedAtom::canBeNullNever; } + +private: + const File &_file; + StringRef _name; +}; +} // end namespace lld + +#endif diff --git a/lld/lib/ReaderWriter/MachO/ExecutableAtoms.hpp b/lld/lib/ReaderWriter/MachO/ExecutableAtoms.hpp index fb1e575..91fd64f 100644 --- a/lld/lib/ReaderWriter/MachO/ExecutableAtoms.hpp +++ b/lld/lib/ReaderWriter/MachO/ExecutableAtoms.hpp @@ -16,8 +16,7 @@ #include "lld/Core/File.h" #include "lld/Core/Reference.h" #include "lld/Core/TargetInfo.h" - -#include "SimpleAtoms.hpp" +#include "lld/ReaderWriter/Simple.h" namespace lld { namespace mach_o { diff --git a/lld/lib/ReaderWriter/MachO/SimpleAtoms.hpp b/lld/lib/ReaderWriter/MachO/SimpleAtoms.hpp deleted file mode 100644 index 1b7f1b5..0000000 --- a/lld/lib/ReaderWriter/MachO/SimpleAtoms.hpp +++ /dev/null @@ -1,252 +0,0 @@ -//===- lib/ReaderWriter/MachO/SimpleAtoms.hpp -----------------------------===// -// -// The LLVM Linker -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#ifndef LLD_READER_WRITER_MACHO_SIMPLE_ATOM_H_ -#define LLD_READER_WRITER_MACHO_SIMPLE_ATOM_H_ - -#include - -#include "lld/Core/DefinedAtom.h" -#include "lld/Core/UndefinedAtom.h" -#include "lld/Core/File.h" -#include "lld/Core/Reference.h" - -namespace lld { -namespace mach_o { - - -// -// Simple File -// -class SimpleFile : public File { -public: - SimpleFile(StringRef path) - : File(path) { - } - - virtual void addAtom(const Atom &atom) { - if (const DefinedAtom* defAtom = dyn_cast(&atom)) { - _definedAtoms._atoms.push_back(defAtom); - } - else if (const UndefinedAtom* undefAtom = dyn_cast(&atom)) { - _undefinedAtoms._atoms.push_back(undefAtom); - } - else if (const SharedLibraryAtom* slAtom = - dyn_cast(&atom)) { - _sharedLibraryAtoms._atoms.push_back(slAtom); - } - else if (const AbsoluteAtom* abAtom = dyn_cast(&atom)) { - _absoluteAtoms._atoms.push_back(abAtom); - } - else { - llvm_unreachable("atom has unknown definition kind"); - } - } - - virtual const atom_collection& defined() const { - return _definedAtoms; - } - virtual const atom_collection& undefined() const { - return _undefinedAtoms; - } - virtual const atom_collection& sharedLibrary() const { - return _sharedLibraryAtoms; - } - 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; -}; - - - -// -// Simple Reference -// -class SimpleReference : public Reference { -public: - SimpleReference(Reference::Kind k, uint64_t off, - const Atom *t, Reference::Addend a) - : _target(t), _offsetInAtom(off), _addend(a), _kind(k) { } - - virtual uint64_t offsetInAtom() const { - return _offsetInAtom; - } - - virtual Kind kind() const { - return _kind; - } - - virtual void setKind(Kind k) { - _kind = k; - } - - virtual const Atom* target() const { - return _target; - } - - virtual Addend addend() const { - return _addend; - } - - virtual void setAddend(Addend a) { - _addend = a; - } - - virtual void setTarget(const Atom* newAtom) { - _target = newAtom; - } -private: - const Atom* _target; - uint64_t _offsetInAtom; - Addend _addend; - Kind _kind; -}; - - -// -// Generic Atom base class -// -class SimpleDefinedAtom : public DefinedAtom { -public: - SimpleDefinedAtom(const File &f) : _file(f) { - static uint32_t lastOrdinal = 0; - _ordinal = lastOrdinal++; - } - - virtual const File& file() const { - return _file; - } - - virtual StringRef name() const { - return StringRef(); - } - - virtual uint64_t ordinal() const { - return _ordinal; - } - - virtual Scope scope() const { - return DefinedAtom::scopeLinkageUnit; - } - - virtual Interposable interposable() const { - return DefinedAtom::interposeNo; - } - - virtual Merge merge() const { - return DefinedAtom::mergeNo; - } - - virtual Alignment alignment() const { - return Alignment(0,0); - } - - virtual SectionChoice sectionChoice() const { - return DefinedAtom::sectionBasedOnContent; - } - - virtual StringRef customSectionName() const { - return StringRef(); - } - - virtual SectionPosition sectionPosition() const { - return DefinedAtom::sectionPositionAny; - } - - virtual DeadStripKind deadStrip() const { - return DefinedAtom::deadStripNormal; - } - - virtual bool isThumb() const { - return false; - } - - virtual bool isAlias() const { - return false; - } - - virtual DefinedAtom::reference_iterator begin() const { - uintptr_t index = 0; - const void* it = reinterpret_cast(index); - return reference_iterator(*this, it); - } - - virtual DefinedAtom::reference_iterator end() const { - uintptr_t index = _references.size(); - const void* it = reinterpret_cast(index); - return reference_iterator(*this, it); - } - - virtual const Reference* derefIterator(const void* it) const { - uintptr_t index = reinterpret_cast(it); - assert(index < _references.size()); - return &_references[index]; - } - - virtual void incrementIterator(const void*& it) const { - uintptr_t index = reinterpret_cast(it); - ++index; - it = reinterpret_cast(index); - } - - void addReference(Reference::Kind kind, uint64_t offset, const Atom *target, - Reference::Addend addend) { - _references.push_back(SimpleReference(kind, offset, target, addend)); - } - -private: - const File& _file; - uint32_t _ordinal; - std::vector _references; -}; - - - -// -// Generic UndefinedAtom base class -// -class SimpleUndefinedAtom : public UndefinedAtom { -public: - SimpleUndefinedAtom(const File &f, StringRef name) - : _file(f), _name(name) { - } - - /// file - returns the File that produced/owns this Atom - virtual const class File& file() const { - return _file; - } - - /// name - The name of the atom. For a function atom, it is the (mangled) - /// name of the function. - virtual StringRef name() const { - return _name; - } - - virtual CanBeNull canBeNull() const { - return UndefinedAtom::canBeNullNever; - } - -private: - const File& _file; - StringRef _name; -}; - - - -} // namespace mach_o -} // namespace lld - - -#endif // LLD_READER_WRITER_MACHO_SIMPLE_ATOM_H_ diff --git a/lld/lib/ReaderWriter/MachO/StubAtoms.hpp b/lld/lib/ReaderWriter/MachO/StubAtoms.hpp index 421053b..6294e16 100644 --- a/lld/lib/ReaderWriter/MachO/StubAtoms.hpp +++ b/lld/lib/ReaderWriter/MachO/StubAtoms.hpp @@ -16,9 +16,9 @@ #include "lld/Core/SharedLibraryAtom.h" #include "lld/Core/File.h" #include "lld/Core/Reference.h" +#include "lld/ReaderWriter/Simple.h" #include "ReferenceKinds.h" -#include "SimpleAtoms.hpp" #include "StubAtoms_x86_64.hpp" #include "StubAtoms_x86.hpp" diff --git a/lld/lib/ReaderWriter/MachO/StubAtoms_x86.hpp b/lld/lib/ReaderWriter/MachO/StubAtoms_x86.hpp index 4e50592..b4c57ad 100644 --- a/lld/lib/ReaderWriter/MachO/StubAtoms_x86.hpp +++ b/lld/lib/ReaderWriter/MachO/StubAtoms_x86.hpp @@ -18,7 +18,6 @@ #include "lld/Core/Reference.h" #include "ReferenceKinds.h" -#include "SimpleAtoms.hpp" namespace lld { namespace mach_o { diff --git a/lld/lib/ReaderWriter/MachO/StubAtoms_x86_64.hpp b/lld/lib/ReaderWriter/MachO/StubAtoms_x86_64.hpp index d3caff0..5baf915 100644 --- a/lld/lib/ReaderWriter/MachO/StubAtoms_x86_64.hpp +++ b/lld/lib/ReaderWriter/MachO/StubAtoms_x86_64.hpp @@ -18,7 +18,6 @@ #include "lld/Core/Reference.h" #include "ReferenceKinds.h" -#include "SimpleAtoms.hpp" namespace lld { namespace mach_o { diff --git a/lld/lib/ReaderWriter/MachO/StubsPass.hpp b/lld/lib/ReaderWriter/MachO/StubsPass.hpp index ffe5b13..ba46df1 100644 --- a/lld/lib/ReaderWriter/MachO/StubsPass.hpp +++ b/lld/lib/ReaderWriter/MachO/StubsPass.hpp @@ -18,9 +18,9 @@ #include "lld/Core/File.h" #include "lld/Core/Reference.h" #include "lld/Core/Pass.h" +#include "lld/ReaderWriter/Simple.h" #include "ReferenceKinds.h" -#include "SimpleAtoms.hpp" #include "StubAtoms.hpp" namespace lld { -- 2.7.4