From 98758cbe853a32eec7d30cc1fb1366714b31e48b Mon Sep 17 00:00:00 2001 From: Shankar Easwaran Date: Sun, 24 Nov 2013 22:29:19 +0000 Subject: [PATCH] [Gnu] Move code from .h to .cpp. No change in functionality. llvm-svn: 195582 --- lld/include/lld/Driver/GnuLdInputGraph.h | 46 +----------------- lld/lib/Driver/CMakeLists.txt | 1 + lld/lib/Driver/GnuLdInputGraph.cpp | 61 ++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 45 deletions(-) create mode 100644 lld/lib/Driver/GnuLdInputGraph.cpp diff --git a/lld/include/lld/Driver/GnuLdInputGraph.h b/lld/include/lld/Driver/GnuLdInputGraph.h index 903682ef7b3c..798828f848e6 100644 --- a/lld/include/lld/Driver/GnuLdInputGraph.h +++ b/lld/include/lld/Driver/GnuLdInputGraph.h @@ -71,51 +71,7 @@ public: } /// \brief Parse the input file to lld::File. - error_code parse(const LinkingContext &ctx, raw_ostream &diagnostics) { - ErrorOr 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); - - // Identify File type - llvm::sys::fs::file_magic FileType = - llvm::sys::fs::identify_magic(_buffer->getBuffer()); - - switch (FileType) { - 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 - 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( - new FileArchive(ctx, std::move(_buffer), ec, _isWholeArchive)); - if (_isWholeArchive) { - fileArchive->parseAllMembers(_files); - _archiveFile = std::move(fileArchive); - } else { - _files.push_back(std::move(fileArchive)); - } - return ec; - } - - default: - // Process Linker script - return _elfLinkingContext.getLinkerScriptReader().parseFile(_buffer, - _files); - } - } + error_code parse(const LinkingContext &, raw_ostream &); /// \brief This is used by Group Nodes, when there is a need to reset the /// the file to be processed next. When handling a group node that contains diff --git a/lld/lib/Driver/CMakeLists.txt b/lld/lib/Driver/CMakeLists.txt index 6670bf097e2e..30962c75a5ef 100644 --- a/lld/lib/Driver/CMakeLists.txt +++ b/lld/lib/Driver/CMakeLists.txt @@ -15,6 +15,7 @@ add_lld_library(lldDriver DarwinLdDriver.cpp Driver.cpp GnuLdDriver.cpp + GnuLdInputGraph.cpp WinLinkDriver.cpp WinLinkInputGraph.cpp UniversalDriver.cpp diff --git a/lld/lib/Driver/GnuLdInputGraph.cpp b/lld/lib/Driver/GnuLdInputGraph.cpp new file mode 100644 index 000000000000..775be0140c7f --- /dev/null +++ b/lld/lib/Driver/GnuLdInputGraph.cpp @@ -0,0 +1,61 @@ +//===- lib/Driver/GnuLdInputGraph.cpp -------------------------------------===// +// +// The LLVM Linker +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "lld/Driver/GnuLdInputGraph.h" +#include "lld/ReaderWriter/LinkerScript.h" + +using namespace lld; + +/// \brief Parse the input file to lld::File. +error_code ELFFileNode::parse(const LinkingContext &ctx, + raw_ostream &diagnostics) { + ErrorOr 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); + + // Identify File type + llvm::sys::fs::file_magic FileType = + llvm::sys::fs::identify_magic(_buffer->getBuffer()); + + switch (FileType) { + 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 + 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( + new FileArchive(ctx, std::move(_buffer), ec, _isWholeArchive)); + if (_isWholeArchive) { + fileArchive->parseAllMembers(_files); + _archiveFile = std::move(fileArchive); + } else { + _files.push_back(std::move(fileArchive)); + } + return ec; + } + default: + // Process Linker script + return _elfLinkingContext.getLinkerScriptReader().parseFile(_buffer, + _files); + break; + } +}