[lld] r192170 - Move duplicate code in InputGraphs to the parent class.
Rui Ueyama
ruiu at google.com
Mon Oct 7 22:52:01 PDT 2013
Author: ruiu
Date: Tue Oct 8 00:52:01 2013
New Revision: 192170
URL: http://llvm.org/viewvc/llvm-project?rev=192170&view=rev
Log:
Move duplicate code in InputGraphs to the parent class.
Modified:
lld/trunk/include/lld/Driver/DarwinInputGraph.h
lld/trunk/include/lld/Driver/GnuLdInputGraph.h
lld/trunk/include/lld/Driver/InputGraph.h
lld/trunk/include/lld/Driver/WinLinkInputGraph.h
lld/trunk/lib/Driver/InputGraph.cpp
Modified: lld/trunk/include/lld/Driver/DarwinInputGraph.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Driver/DarwinInputGraph.h?rev=192170&r1=192169&r2=192170&view=diff
==============================================================================
--- lld/trunk/include/lld/Driver/DarwinInputGraph.h (original)
+++ lld/trunk/include/lld/Driver/DarwinInputGraph.h Tue Oct 8 00:52:01 2013
@@ -42,34 +42,9 @@ public:
/// \brief Parse the input file to lld::File.
llvm::error_code parse(const LinkingContext &ctx, raw_ostream &diagnostics) {
- ErrorOr<StringRef> filePath = getPath(ctx);
- if (!filePath &&
- error_code(filePath) == llvm::errc::no_such_file_or_directory)
- return make_error_code(llvm::errc::no_such_file_or_directory);
-
- // Create a memory buffer
- OwningPtr<llvm::MemoryBuffer> opmb;
- llvm::error_code ec;
-
- if ((ec = llvm::MemoryBuffer::getFileOrSTDIN(*filePath, opmb)))
+ if (error_code ec = readFile(ctx, diagnostics))
return ec;
-
- std::unique_ptr<MemoryBuffer> mb(opmb.take());
- _buffer = std::move(mb);
-
- if (ctx.logInputFiles())
- diagnostics << _buffer->getBufferIdentifier() << "\n";
-
- // YAML file is identified by a .objtxt extension
- // FIXME : Identify YAML files by using a magic
- if (filePath->endswith(".objtxt")) {
- ec = _ctx.getYAMLReader().parseFile(_buffer, _files);
- if (!ec)
- return ec;
- }
-
(void) (_isWholeArchive);
-
return llvm::error_code::success();
}
Modified: lld/trunk/include/lld/Driver/GnuLdInputGraph.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Driver/GnuLdInputGraph.h?rev=192170&r1=192169&r2=192170&view=diff
==============================================================================
--- lld/trunk/include/lld/Driver/GnuLdInputGraph.h (original)
+++ lld/trunk/include/lld/Driver/GnuLdInputGraph.h Tue Oct 8 00:52:01 2013
@@ -72,33 +72,10 @@ public:
/// \brief Parse the input file to lld::File.
llvm::error_code parse(const LinkingContext &ctx, raw_ostream &diagnostics) {
- ErrorOr<StringRef> filePath = getPath(ctx);
- if (!filePath &&
- error_code(filePath) == llvm::errc::no_such_file_or_directory)
- return make_error_code(llvm::errc::no_such_file_or_directory);
-
- // Create a memory buffer
- OwningPtr<llvm::MemoryBuffer> opmb;
- llvm::error_code ec;
-
- if ((ec = llvm::MemoryBuffer::getFileOrSTDIN(*filePath, opmb)))
+ // Read the file to _buffer.
+ if (error_code ec = readFile(ctx, diagnostics))
return ec;
- std::unique_ptr<MemoryBuffer> mb(opmb.take());
- _buffer = std::move(mb);
-
- // If tracing is enabled, print the files being processed.
- if (ctx.logInputFiles())
- diagnostics << _buffer->getBufferIdentifier() << "\n";
-
- // YAML file is identified by a .objtxt extension
- // FIXME : Identify YAML files by using a magic
- if (filePath->endswith(".objtxt")) {
- ec = _elfLinkingContext.getYAMLReader().parseFile(_buffer, _files);
- if (!ec)
- return ec;
- }
-
// Identify File type
llvm::sys::fs::file_magic FileType =
llvm::sys::fs::identify_magic(_buffer->getBuffer());
@@ -107,12 +84,12 @@ public:
case llvm::sys::fs::file_magic::elf_relocatable:
case llvm::sys::fs::file_magic::elf_shared_object:
// Call the default reader to read object files and shared objects
- ec = _elfLinkingContext.getDefaultReader().parseFile(_buffer, _files);
- break;
+ return _elfLinkingContext.getDefaultReader().parseFile(_buffer, _files);
case llvm::sys::fs::file_magic::archive: {
// Process archive files. If Whole Archive option is set,
// parse all members of the archive.
+ error_code ec;
std::unique_ptr<FileArchive> fileArchive(
new FileArchive(ctx, std::move(_buffer), ec, _isWholeArchive));
if (_isWholeArchive) {
@@ -121,15 +98,14 @@ public:
} else {
_files.push_back(std::move(fileArchive));
}
- break;
+ return ec;
}
default:
// Process Linker script
_elfLinkingContext.getLinkerScriptReader().parseFile(_buffer, _files);
- break;
+ return error_code::success();
}
- return ec;
}
/// \brief This is used by Group Nodes, when there is a need to reset the
Modified: lld/trunk/include/lld/Driver/InputGraph.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Driver/InputGraph.h?rev=192170&r1=192169&r2=192170&view=diff
==============================================================================
--- lld/trunk/include/lld/Driver/InputGraph.h (original)
+++ lld/trunk/include/lld/Driver/InputGraph.h Tue Oct 8 00:52:01 2013
@@ -302,6 +302,9 @@ public:
virtual void assignFileOrdinals(uint64_t &startOrdinal);
protected:
+ /// \brief Read the file into _buffer.
+ error_code readFile(const LinkingContext &ctx, raw_ostream &diagnostics);
+
StringRef _path;
InputGraph::FileVectorT _files;
std::unique_ptr<llvm::MemoryBuffer> _buffer;
Modified: lld/trunk/include/lld/Driver/WinLinkInputGraph.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Driver/WinLinkInputGraph.h?rev=192170&r1=192169&r2=192170&view=diff
==============================================================================
--- lld/trunk/include/lld/Driver/WinLinkInputGraph.h (original)
+++ lld/trunk/include/lld/Driver/WinLinkInputGraph.h Tue Oct 8 00:52:01 2013
@@ -38,51 +38,28 @@ public:
virtual llvm::ErrorOr<StringRef> getPath(const LinkingContext &ctx) const;
/// \brief Parse the input file to lld::File.
- llvm::error_code parse(const LinkingContext &ctx, raw_ostream &diagnostics) {
- ErrorOr<StringRef> filePath = getPath(ctx);
- if (!filePath &&
- error_code(filePath) == llvm::errc::no_such_file_or_directory)
- return make_error_code(llvm::errc::no_such_file_or_directory);
-
- // Create a memory buffer
- OwningPtr<llvm::MemoryBuffer> opmb;
- llvm::error_code ec;
-
- if ((ec = llvm::MemoryBuffer::getFileOrSTDIN(*filePath, opmb)))
+ error_code parse(const LinkingContext &ctx, raw_ostream &diagnostics) {
+ // Read the file to _buffer.
+ if (error_code ec = readFile(ctx, diagnostics))
return ec;
- std::unique_ptr<MemoryBuffer> mb(opmb.take());
- _buffer = std::move(mb);
-
- if (ctx.logInputFiles())
- diagnostics << _buffer->getBufferIdentifier() << "\n";
-
- // YAML file is identified by a .objtxt extension
- // FIXME : Identify YAML files by using a magic
- if (filePath->endswith(".objtxt")) {
- ec = _ctx.getYAMLReader().parseFile(_buffer, _files);
- if (!ec)
- return ec;
- }
-
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:
+ 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));
- break;
+ return ec;
+ }
case llvm::sys::fs::file_magic::coff_object:
default:
- ec = _ctx.getDefaultReader().parseFile(_buffer, _files);
- break;
+ return _ctx.getDefaultReader().parseFile(_buffer, _files);
}
- return ec;
}
/// \brief validates the Input Element
Modified: lld/trunk/lib/Driver/InputGraph.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/InputGraph.cpp?rev=192170&r1=192169&r2=192170&view=diff
==============================================================================
--- lld/trunk/lib/Driver/InputGraph.cpp (original)
+++ lld/trunk/lib/Driver/InputGraph.cpp Tue Oct 8 00:52:01 2013
@@ -105,6 +105,35 @@ void FileNode::assignFileOrdinals(uint64
file->setOrdinalAndIncrement(startOrdinal);
}
+/// \brief Read the file into _buffer.
+error_code
+FileNode::readFile(const LinkingContext &ctx, raw_ostream &diagnostics) {
+ ErrorOr<StringRef> filePath = getPath(ctx);
+ if (!filePath &&
+ error_code(filePath) == llvm::errc::no_such_file_or_directory)
+ return make_error_code(llvm::errc::no_such_file_or_directory);
+
+ // Create a memory buffer
+ OwningPtr<llvm::MemoryBuffer> opmb;
+
+ if (error_code ec = llvm::MemoryBuffer::getFileOrSTDIN(*filePath, opmb))
+ return ec;
+
+ std::unique_ptr<MemoryBuffer> mb(opmb.take());
+ _buffer = std::move(mb);
+
+ if (ctx.logInputFiles())
+ diagnostics << _buffer->getBufferIdentifier() << "\n";
+
+ // YAML file is identified by a .objtxt extension
+ // FIXME : Identify YAML files by using a magic
+ if (filePath->endswith(".objtxt"))
+ if (error_code ec = ctx.getYAMLReader().parseFile(_buffer, _files))
+ return ec;
+ return error_code::success();
+}
+
+
/// \brief Assign File ordinals for files contained
/// in the InputElement
void ControlNode::assignFileOrdinals(uint64_t &startOrdinal) {
More information about the llvm-commits
mailing list