Move member functions to its own cpp file.

llvm-svn: 195281
This commit is contained in:
Rui Ueyama 2013-11-20 23:51:41 +00:00
parent 698875aec6
commit 9114439df2
4 changed files with 71 additions and 51 deletions

View File

@ -38,38 +38,7 @@ public:
virtual ErrorOr<StringRef> getPath(const LinkingContext &ctx) const;
/// \brief Parse the input file to lld::File.
error_code parse(const LinkingContext &ctx, raw_ostream &diagnostics) {
ErrorOr<StringRef> filePath = getPath(ctx);
if (!filePath)
return error_code(filePath);
if (error_code ec = getBuffer(*filePath))
return ec;
if (ctx.logInputFiles())
diagnostics << *filePath << "\n";
if (filePath->endswith(".objtxt"))
return ctx.getYAMLReader().parseFile(_buffer, _files);
llvm::sys::fs::file_magic FileType =
llvm::sys::fs::identify_magic(_buffer->getBuffer());
std::unique_ptr<File> f;
switch (FileType) {
case llvm::sys::fs::file_magic::archive: {
// Archive File
error_code ec;
f.reset(new FileArchive(ctx, std::move(_buffer), ec, false));
_files.push_back(std::move(f));
return ec;
}
case llvm::sys::fs::file_magic::coff_object:
default:
return _ctx.getDefaultReader().parseFile(_buffer, _files);
}
}
error_code parse(const LinkingContext &ctx, raw_ostream &diagnostics);
/// \brief validates the Input Element
virtual bool validate() { return true; }
@ -77,11 +46,7 @@ public:
/// \brief Dump the Input Element
virtual bool dump(raw_ostream &) { return true; }
virtual ErrorOr<File &> getNextFile() {
if (_nextFileIndex == _files.size())
return make_error_code(InputGraphError::no_more_files);
return *_files[_nextFileIndex++];
}
virtual ErrorOr<File &> getNextFile();
protected:
const PECOFFLinkingContext &_ctx;

View File

@ -16,6 +16,7 @@ add_lld_library(lldDriver
Driver.cpp
GnuLdDriver.cpp
WinLinkDriver.cpp
WinLinkInputGraph.cpp
UniversalDriver.cpp
)

View File

@ -547,20 +547,6 @@ parseArgs(int argc, const char *argv[], raw_ostream &diagnostics,
// Main driver
//
ErrorOr<StringRef> PECOFFFileNode::getPath(const LinkingContext &) const {
if (_path.endswith_lower(".lib"))
return _ctx.searchLibraryFile(_path);
if (llvm::sys::path::extension(_path).empty())
return _ctx.allocateString(_path.str() + ".obj");
return _path;
}
ErrorOr<StringRef> PECOFFLibraryNode::getPath(const LinkingContext &) const {
if (!_path.endswith_lower(".lib"))
return _ctx.searchLibraryFile(_ctx.allocateString(_path.str() + ".lib"));
return _ctx.searchLibraryFile(_path);
}
bool WinLinkDriver::linkPECOFF(int argc, const char *argv[],
raw_ostream &diagnostics) {
PECOFFLinkingContext context;

View File

@ -0,0 +1,68 @@
//===- lib/Driver/WinLinkDriver.cpp ---------------------------------------===//
//
// The LLVM Linker
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "lld/Driver/WinLinkInputGraph.h"
namespace lld {
/// \brief Parse the input file to lld::File.
error_code PECOFFFileNode::parse(const LinkingContext &ctx,
raw_ostream &diagnostics) {
ErrorOr<StringRef> filePath = getPath(ctx);
if (!filePath)
return error_code(filePath);
if (error_code ec = getBuffer(*filePath))
return ec;
if (ctx.logInputFiles())
diagnostics << *filePath << "\n";
if (filePath->endswith(".objtxt"))
return ctx.getYAMLReader().parseFile(_buffer, _files);
llvm::sys::fs::file_magic FileType =
llvm::sys::fs::identify_magic(_buffer->getBuffer());
std::unique_ptr<File> f;
switch (FileType) {
case llvm::sys::fs::file_magic::archive: {
// Archive File
error_code ec;
f.reset(new FileArchive(ctx, std::move(_buffer), ec, false));
_files.push_back(std::move(f));
return ec;
}
case llvm::sys::fs::file_magic::coff_object:
default:
return _ctx.getDefaultReader().parseFile(_buffer, _files);
}
}
ErrorOr<File &> PECOFFFileNode::getNextFile() {
if (_nextFileIndex == _files.size())
return make_error_code(InputGraphError::no_more_files);
return *_files[_nextFileIndex++];
}
ErrorOr<StringRef> PECOFFFileNode::getPath(const LinkingContext &) const {
if (_path.endswith_lower(".lib"))
return _ctx.searchLibraryFile(_path);
if (llvm::sys::path::extension(_path).empty())
return _ctx.allocateString(_path.str() + ".obj");
return _path;
}
ErrorOr<StringRef> PECOFFLibraryNode::getPath(const LinkingContext &) const {
if (!_path.endswith_lower(".lib"))
return _ctx.searchLibraryFile(_ctx.allocateString(_path.str() + ".lib"));
return _ctx.searchLibraryFile(_path);
}
} // end anonymous namespace