[PATCH] Add support for a directory argument to llvm-link
Khilan Gudka
Khilan.Gudka at cl.cam.ac.uk
Wed Feb 26 04:30:17 PST 2014
Hi #llvm,
Sometimes when linking a very large number of bit code files together, it is not possible if the number exceeds that allowed by the shell. This patch adds a -dir flag to llvm-link that allows a single directory to be passed. For example:
llvm-link -o linked.bc -dir myDir
This follows the intended philosophy of keeping llvm-link simple (exclusively either a directory, or a list of files).
http://llvm-reviews.chandlerc.com/D2885
Files:
tools/llvm-link/llvm-link.cpp
Index: tools/llvm-link/llvm-link.cpp
===================================================================
--- tools/llvm-link/llvm-link.cpp
+++ tools/llvm-link/llvm-link.cpp
@@ -19,19 +19,22 @@
#include "llvm/IR/Module.h"
#include "llvm/IRReader/IRReader.h"
#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/FileSystem.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/Signals.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/SystemUtils.h"
+#include "llvm/Support/system_error.h"
#include "llvm/Support/ToolOutputFile.h"
#include <memory>
using namespace llvm;
+using namespace llvm::sys::fs;
static cl::list<std::string>
InputFilenames(cl::Positional, cl::OneOrMore,
- cl::desc("<input bitcode files>"));
+ cl::desc("<input bitcode files|input bitcode directory>"));
static cl::opt<std::string>
OutputFilename("o", cl::desc("Override output filename"), cl::init("-"),
@@ -50,6 +53,9 @@
static cl::opt<bool>
DumpAsm("d", cl::desc("Print assembly as linked"), cl::Hidden);
+static cl::opt<bool>
+Directory("dir", cl::desc("Input argument is a directory containing bitcode files"));
+
// LoadFile - Read the specified bitcode file in and return it. This routine
// searches the link path for the specified file to try to find it...
//
@@ -75,6 +81,26 @@
llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
cl::ParseCommandLineOptions(argc, argv, "llvm linker\n");
+ if (Directory) {
+ if (InputFilenames.size() > 1) {
+ errs() << "Error: More than one directory specified\n";
+ return -1;
+ }
+
+ // fill InputFilenames with the name of the files in the argument directory,
+ // thus allowing the code below to work with no changes
+ error_code ec; // output parameter to store error codes
+ std::string dir = InputFilenames[0];
+ InputFilenames.clear();
+ for (directory_iterator I = directory_iterator(dir, ec), E; I != E; I.increment(ec)) {
+ if (ec != ec.success()) {
+ errs() << "Error iterating directory: " << ec.message() << "\n";
+ return -1;
+ }
+ InputFilenames.push_back(I->path());
+ }
+ }
+
unsigned BaseArg = 0;
std::string ErrorMessage;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2885.1.patch
Type: text/x-patch
Size: 2309 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140226/2805a988/attachment.bin>
More information about the llvm-commits
mailing list