[llvm] r235472 - llvm-link: Factor out loop over input files, NFC
Duncan P. N. Exon Smith
dexonsmith at apple.com
Tue Apr 21 21:08:22 PDT 2015
Author: dexonsmith
Date: Tue Apr 21 23:08:22 2015
New Revision: 235472
URL: http://llvm.org/viewvc/llvm-project?rev=235472&view=rev
Log:
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!
Modified:
llvm/trunk/tools/llvm-link/llvm-link.cpp
Modified: llvm/trunk/tools/llvm-link/llvm-link.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-link/llvm-link.cpp?rev=235472&r1=235471&r2=235472&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-link/llvm-link.cpp (original)
+++ llvm/trunk/tools/llvm-link/llvm-link.cpp Tue Apr 21 23:08:22 2015
@@ -107,6 +107,30 @@ static void diagnosticHandler(const Diag
errs() << '\n';
}
+static bool linkFiles(const char *argv0, LLVMContext &Context, Linker &L,
+ const cl::list<std::string> &Files) {
+ for (const auto &File : Files) {
+ std::unique_ptr<Module> 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<Module>("llvm-link", Context);
Linker L(Composite.get(), diagnosticHandler);
- for (unsigned i = 0; i < InputFilenames.size(); ++i) {
- std::unique_ptr<Module> M = loadFile(argv[0], InputFilenames[i], Context);
- if (!M.get()) {
- errs() << argv[0] << ": error loading file '" <<InputFilenames[i]<< "'\n";
- return 1;
- }
-
- if (verifyModule(*M, &errs())) {
- errs() << argv[0] << ": " << InputFilenames[i]
- << ": error: input module is broken!\n";
- return 1;
- }
-
- if (Verbose) errs() << "Linking in '" << InputFilenames[i] << "'\n";
-
- if (L.linkInModule(M.get()))
- return 1;
- }
+ if (!linkFiles(argv[0], Context, L, InputFilenames))
+ return 1;
if (DumpAsm) errs() << "Here's the assembly:\n" << *Composite;
More information about the llvm-commits
mailing list