Remove duplication code.

llvm-svn: 226321
This commit is contained in:
Rui Ueyama 2015-01-16 21:11:00 +00:00
parent a089c7cb4b
commit bd350a5cd2
3 changed files with 3 additions and 81 deletions

View File

@ -12,6 +12,7 @@
#include "lld/Core/File.h"
#include "lld/Core/SharedLibraryFile.h"
#include "lld/Core/Simple.h"
#include "lld/Core/SymbolTable.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DenseSet.h"
@ -73,37 +74,10 @@ private:
void markLive(const Atom *atom);
void addAtoms(const std::vector<const DefinedAtom *>&);
class MergedFile : public MutableFile {
class MergedFile : public SimpleFile {
public:
MergedFile() : MutableFile("<linker-internal>") {}
const atom_collection<DefinedAtom> &defined() const override {
return _definedAtoms;
}
const atom_collection<UndefinedAtom>& undefined() const override {
return _undefinedAtoms;
}
const atom_collection<SharedLibraryAtom>& sharedLibrary() const override {
return _sharedLibraryAtoms;
}
const atom_collection<AbsoluteAtom>& absolute() const override {
return _absoluteAtoms;
}
MergedFile() : SimpleFile("<linker-internal>") {}
void addAtoms(std::vector<const Atom*>& atoms);
void addAtom(const Atom& atom) override;
DefinedAtomRange definedAtoms() override;
void removeDefinedAtomsIf(
std::function<bool(const DefinedAtom *)> pred) override;
private:
atom_collection_vector<DefinedAtom> _definedAtoms;
atom_collection_vector<UndefinedAtom> _undefinedAtoms;
atom_collection_vector<SharedLibraryAtom> _sharedLibraryAtoms;
atom_collection_vector<AbsoluteAtom> _absoluteAtoms;
};
LinkingContext &_context;

View File

@ -458,32 +458,6 @@ bool Resolver::resolve() {
return true;
}
void Resolver::MergedFile::addAtom(const Atom &atom) {
if (auto *def = dyn_cast<DefinedAtom>(&atom)) {
_definedAtoms._atoms.push_back(def);
} else if (auto *undef = dyn_cast<UndefinedAtom>(&atom)) {
_undefinedAtoms._atoms.push_back(undef);
} else if (auto *shared = dyn_cast<SharedLibraryAtom>(&atom)) {
_sharedLibraryAtoms._atoms.push_back(shared);
} else if (auto *abs = dyn_cast<AbsoluteAtom>(&atom)) {
_absoluteAtoms._atoms.push_back(abs);
} else {
llvm_unreachable("atom has unknown definition kind");
}
}
MutableFile::DefinedAtomRange Resolver::MergedFile::definedAtoms() {
return range<std::vector<const DefinedAtom *>::iterator>(
_definedAtoms._atoms.begin(), _definedAtoms._atoms.end());
}
void Resolver::MergedFile::removeDefinedAtomsIf(
std::function<bool(const DefinedAtom *)> pred) {
auto &atoms = _definedAtoms._atoms;
auto newEnd = std::remove_if(atoms.begin(), atoms.end(), pred);
atoms.erase(newEnd, atoms.end());
}
void Resolver::MergedFile::addAtoms(std::vector<const Atom *> &all) {
ScopedTask task(getDefaultDomain(), "addAtoms");
DEBUG_WITH_TYPE("resolver", llvm::dbgs() << "Resolver final atom list:\n");

View File

@ -155,34 +155,8 @@ public:
else
llvm_unreachable("atom has unknown definition kind");
}
DefinedAtomRange definedAtoms() override {
return range<std::vector<const DefinedAtom *>::iterator>(
_definedAtoms._atoms.begin(), _definedAtoms._atoms.end());
}
const atom_collection<DefinedAtom> &defined() const override {
return _definedAtoms;
}
const atom_collection<UndefinedAtom> &undefined() const override {
return _undefinedAtoms;
}
const atom_collection<SharedLibraryAtom> &sharedLibrary() const override {
return _sharedLibraryAtoms;
}
const atom_collection<AbsoluteAtom> &absolute() const override {
return _absoluteAtoms;
}
private:
atom_collection_vector<DefinedAtom> _definedAtoms;
atom_collection_vector<UndefinedAtom> _undefinedAtoms;
atom_collection_vector<SharedLibraryAtom> _sharedLibraryAtoms;
atom_collection_vector<AbsoluteAtom> _absoluteAtoms;
};
} // anonymous namespace
CoreLinkingContext::CoreLinkingContext() {}