From d9443d717dbb3ec01ae8441dd70c2a077a7b5c09 Mon Sep 17 00:00:00 2001 From: "Duncan P. N. Exon Smith" Date: Wed, 22 Apr 2015 04:08:22 +0000 Subject: [PATCH] llvm-link: Factor out loop over input files, NFC Factor the loop for linking input files together into a combined module into a separate function. This is in preparation for an upcoming patch that runs the logic twice. Patch by Luqman Aden! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@235472 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/llvm-link/llvm-link.cpp | 44 +++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/tools/llvm-link/llvm-link.cpp b/tools/llvm-link/llvm-link.cpp index bcefc0b507a..9f287e4fdb6 100644 --- a/tools/llvm-link/llvm-link.cpp +++ b/tools/llvm-link/llvm-link.cpp @@ -107,6 +107,30 @@ static void diagnosticHandler(const DiagnosticInfo &DI) { errs() << '\n'; } +static bool linkFiles(const char *argv0, LLVMContext &Context, Linker &L, + const cl::list &Files) { + for (const auto &File : Files) { + std::unique_ptr M = loadFile(argv0, File, Context); + if (!M.get()) { + errs() << argv0 << ": error loading file '" << File << "'\n"; + return false; + } + + if (verifyModule(*M, &errs())) { + errs() << argv0 << ": " << File << ": error: input module is broken!\n"; + return false; + } + + if (Verbose) + errs() << "Linking in '" << File << "'\n"; + + if (L.linkInModule(M.get())) + return false; + } + + return true; +} + int main(int argc, char **argv) { // Print a stack trace if we signal out. sys::PrintStackTraceOnErrorSignal(); @@ -119,24 +143,8 @@ int main(int argc, char **argv) { auto Composite = make_unique("llvm-link", Context); Linker L(Composite.get(), diagnosticHandler); - for (unsigned i = 0; i < InputFilenames.size(); ++i) { - std::unique_ptr M = loadFile(argv[0], InputFilenames[i], Context); - if (!M.get()) { - errs() << argv[0] << ": error loading file '" <