Files
clang-p2996/lld/lib/Core/InputFiles.cpp
Nick Kledzik abb6981f68 Major refactoring: Remove Platform concept. In its place there are
now Reader and Writer subclasses for each file format.  Each Reader and
Writer subclass defines an "options" class which controls how that Reader
or Writer operates.

llvm-svn: 157774
2012-05-31 22:34:00 +00:00

91 lines
2.5 KiB
C++

//===- Core/InputFiles.cpp - Manages list of Files ------------------------===//
//
// The LLVM Linker
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "lld/Core/InputFiles.h"
#include "lld/Core/SharedLibraryFile.h"
#include "lld/Core/ArchiveLibraryFile.h"
#include "lld/Core/LLVM.h"
namespace lld {
InputFiles::InputFiles() {
}
InputFiles::~InputFiles() {
}
void InputFiles::forEachInitialAtom(InputFiles::Handler &handler) const {
for ( const File *file : _files ) {
this->handleFile(file, handler);
}
}
void InputFiles::prependFile(const File &file) {
_files.insert(_files.begin(), &file);
}
void InputFiles::appendFile(const File &file) {
_files.push_back(&file);
}
void InputFiles::appendFiles(std::vector<std::unique_ptr<File>> &files) {
for (std::unique_ptr<File> &f : files) {
_files.push_back(f.release());
}
}
bool InputFiles::searchLibraries(StringRef name, bool searchSharedLibs,
bool searchArchives, bool dataSymbolOnly,
InputFiles::Handler &handler) const {
for ( const File *file : _files ) {
if ( searchSharedLibs ) {
if (const SharedLibraryFile *shlib = dyn_cast<SharedLibraryFile>(file)) {
if ( const SharedLibraryAtom* shAtom = shlib->exports(name,
dataSymbolOnly) ) {
handler.doSharedLibraryAtom(*shAtom);
return true;
}
}
}
if ( searchArchives ) {
if (const ArchiveLibraryFile *lib = dyn_cast<ArchiveLibraryFile>(file)) {
if ( const File *member = lib->find(name, dataSymbolOnly) ) {
this->handleFile(member, handler);
return true;
}
}
}
}
return false;
}
void InputFiles::handleFile(const File *file,
InputFiles::Handler &handler) const {
handler.doFile(*file);
for( const DefinedAtom *atom : file->defined() ) {
handler.doDefinedAtom(*atom);
}
for( const UndefinedAtom *undefAtom : file->undefined() ) {
handler.doUndefinedAtom(*undefAtom);
}
for( const SharedLibraryAtom *shlibAtom : file->sharedLibrary() ) {
handler.doSharedLibraryAtom(*shlibAtom);
}
for( const AbsoluteAtom *absAtom : file->absolute() ) {
handler.doAbsoluteAtom(*absAtom);
}
}
} // namespace lld