[llvm-commits] [lld] r173380 - in /lld/trunk: include/lld/ReaderWriter/Simple.h lib/ReaderWriter/MachO/ExecutableAtoms.hpp lib/ReaderWriter/MachO/SimpleAtoms.hpp lib/ReaderWriter/MachO/StubAtoms.hpp lib/ReaderWriter/MachO/StubAtoms_x86.hpp lib/ReaderWriter/MachO/StubAtoms_x86_64.hpp lib/ReaderWriter/MachO/StubsPass.hpp
Michael J. Spencer
bigcheesegs at gmail.com
Thu Jan 24 14:52:25 PST 2013
Author: mspencer
Date: Thu Jan 24 16:52:25 2013
New Revision: 173380
URL: http://llvm.org/viewvc/llvm-project?rev=173380&view=rev
Log:
Move SimpleAtoms.h to ReaderWriter.
Added:
lld/trunk/include/lld/ReaderWriter/Simple.h
Removed:
lld/trunk/lib/ReaderWriter/MachO/SimpleAtoms.hpp
Modified:
lld/trunk/lib/ReaderWriter/MachO/ExecutableAtoms.hpp
lld/trunk/lib/ReaderWriter/MachO/StubAtoms.hpp
lld/trunk/lib/ReaderWriter/MachO/StubAtoms_x86.hpp
lld/trunk/lib/ReaderWriter/MachO/StubAtoms_x86_64.hpp
lld/trunk/lib/ReaderWriter/MachO/StubsPass.hpp
Added: lld/trunk/include/lld/ReaderWriter/Simple.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/ReaderWriter/Simple.h?rev=173380&view=auto
==============================================================================
--- lld/trunk/include/lld/ReaderWriter/Simple.h (added)
+++ lld/trunk/include/lld/ReaderWriter/Simple.h Thu Jan 24 16:52:25 2013
@@ -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<DefinedAtom>(&atom)) {
+ _definedAtoms._atoms.push_back(defAtom);
+ } else if (
+ const UndefinedAtom *undefAtom = dyn_cast<UndefinedAtom>(&atom)) {
+ _undefinedAtoms._atoms.push_back(undefAtom);
+ } else if (
+ const SharedLibraryAtom *slAtom = dyn_cast<SharedLibraryAtom>(&atom)) {
+ _sharedLibraryAtoms._atoms.push_back(slAtom);
+ } else if (const AbsoluteAtom *abAtom = dyn_cast<AbsoluteAtom>(&atom)) {
+ _absoluteAtoms._atoms.push_back(abAtom);
+ } else {
+ llvm_unreachable("atom has unknown definition kind");
+ }
+ }
+
+ virtual const atom_collection<DefinedAtom> &defined() const {
+ return _definedAtoms;
+ }
+
+ virtual const atom_collection<UndefinedAtom> &undefined() const {
+ return _undefinedAtoms;
+ }
+
+ virtual const atom_collection<SharedLibraryAtom> &sharedLibrary() const {
+ return _sharedLibraryAtoms;
+ }
+
+ virtual const atom_collection<AbsoluteAtom> &absolute() const {
+ return _absoluteAtoms;
+ }
+
+ virtual DefinedAtomRange definedAtoms() {
+ return make_range(_definedAtoms._atoms);
+ }
+
+private:
+ atom_collection_vector<DefinedAtom> _definedAtoms;
+ atom_collection_vector<UndefinedAtom> _undefinedAtoms;
+ atom_collection_vector<SharedLibraryAtom> _sharedLibraryAtoms;
+ atom_collection_vector<AbsoluteAtom> _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<const void *>(index);
+ return reference_iterator(*this, it);
+ }
+
+ virtual DefinedAtom::reference_iterator end() const {
+ uintptr_t index = _references.size();
+ const void *it = reinterpret_cast<const void *>(index);
+ return reference_iterator(*this, it);
+ }
+
+ virtual const Reference *derefIterator(const void *it) const {
+ uintptr_t index = reinterpret_cast<uintptr_t>(it);
+ assert(index < _references.size());
+ return &_references[index];
+ }
+
+ virtual void incrementIterator(const void *&it) const {
+ uintptr_t index = reinterpret_cast<uintptr_t>(it);
+ ++index;
+ it = reinterpret_cast<const void *>(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<SimpleReference> _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
Modified: lld/trunk/lib/ReaderWriter/MachO/ExecutableAtoms.hpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/ExecutableAtoms.hpp?rev=173380&r1=173379&r2=173380&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/ExecutableAtoms.hpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/ExecutableAtoms.hpp Thu Jan 24 16:52:25 2013
@@ -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 {
Removed: lld/trunk/lib/ReaderWriter/MachO/SimpleAtoms.hpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/SimpleAtoms.hpp?rev=173379&view=auto
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/SimpleAtoms.hpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/SimpleAtoms.hpp (removed)
@@ -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 <vector>
-
-#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<DefinedAtom>(&atom)) {
- _definedAtoms._atoms.push_back(defAtom);
- }
- else if (const UndefinedAtom* undefAtom = dyn_cast<UndefinedAtom>(&atom)) {
- _undefinedAtoms._atoms.push_back(undefAtom);
- }
- else if (const SharedLibraryAtom* slAtom =
- dyn_cast<SharedLibraryAtom>(&atom)) {
- _sharedLibraryAtoms._atoms.push_back(slAtom);
- }
- else if (const AbsoluteAtom* abAtom = dyn_cast<AbsoluteAtom>(&atom)) {
- _absoluteAtoms._atoms.push_back(abAtom);
- }
- else {
- llvm_unreachable("atom has unknown definition kind");
- }
- }
-
- virtual const atom_collection<DefinedAtom>& defined() const {
- return _definedAtoms;
- }
- virtual const atom_collection<UndefinedAtom>& undefined() const {
- return _undefinedAtoms;
- }
- virtual const atom_collection<SharedLibraryAtom>& sharedLibrary() const {
- return _sharedLibraryAtoms;
- }
- virtual const atom_collection<AbsoluteAtom>& absolute() const {
- return _absoluteAtoms;
- }
-
-private:
- atom_collection_vector<DefinedAtom> _definedAtoms;
- atom_collection_vector<UndefinedAtom> _undefinedAtoms;
- atom_collection_vector<SharedLibraryAtom> _sharedLibraryAtoms;
- atom_collection_vector<AbsoluteAtom> _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<const void*>(index);
- return reference_iterator(*this, it);
- }
-
- virtual DefinedAtom::reference_iterator end() const {
- uintptr_t index = _references.size();
- const void* it = reinterpret_cast<const void*>(index);
- return reference_iterator(*this, it);
- }
-
- virtual const Reference* derefIterator(const void* it) const {
- uintptr_t index = reinterpret_cast<uintptr_t>(it);
- assert(index < _references.size());
- return &_references[index];
- }
-
- virtual void incrementIterator(const void*& it) const {
- uintptr_t index = reinterpret_cast<uintptr_t>(it);
- ++index;
- it = reinterpret_cast<const void*>(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<SimpleReference> _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_
Modified: lld/trunk/lib/ReaderWriter/MachO/StubAtoms.hpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/StubAtoms.hpp?rev=173380&r1=173379&r2=173380&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/StubAtoms.hpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/StubAtoms.hpp Thu Jan 24 16:52:25 2013
@@ -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"
Modified: lld/trunk/lib/ReaderWriter/MachO/StubAtoms_x86.hpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/StubAtoms_x86.hpp?rev=173380&r1=173379&r2=173380&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/StubAtoms_x86.hpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/StubAtoms_x86.hpp Thu Jan 24 16:52:25 2013
@@ -18,7 +18,6 @@
#include "lld/Core/Reference.h"
#include "ReferenceKinds.h"
-#include "SimpleAtoms.hpp"
namespace lld {
namespace mach_o {
Modified: lld/trunk/lib/ReaderWriter/MachO/StubAtoms_x86_64.hpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/StubAtoms_x86_64.hpp?rev=173380&r1=173379&r2=173380&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/StubAtoms_x86_64.hpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/StubAtoms_x86_64.hpp Thu Jan 24 16:52:25 2013
@@ -18,7 +18,6 @@
#include "lld/Core/Reference.h"
#include "ReferenceKinds.h"
-#include "SimpleAtoms.hpp"
namespace lld {
namespace mach_o {
Modified: lld/trunk/lib/ReaderWriter/MachO/StubsPass.hpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/StubsPass.hpp?rev=173380&r1=173379&r2=173380&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/StubsPass.hpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/StubsPass.hpp Thu Jan 24 16:52:25 2013
@@ -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 {
More information about the llvm-commits
mailing list