<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Feb 26, 2014 at 7:30 AM, Khilan Gudka <span dir="ltr"><<a href="mailto:Khilan.Gudka@cl.cam.ac.uk" target="_blank">Khilan.Gudka@cl.cam.ac.uk</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi #llvm,<br>
<br>
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:<br>
<br>
llvm-link -o linked.bc -dir myDir<br>
<br>
This follows the intended philosophy of keeping llvm-link simple (exclusively either a directory, or a list of files).<br></blockquote><div><br></div><div>This seems counterintuitive and complex to me (complex web of restrictions). I feel the natural order of things should be that it interprets positional arguments as files to be linked (i.e. the current behavior), and any number of `-dir foo/` arguments are scanned for bitcode files which are added to the list of files to link.</div>
<div><br></div><div>Even better: there is no -dir argument. Positional arguments can be either bitcode files, or directories. If a positional argument happens to be a directory, it is scanned for bitcode files, which are added to the list of inputs. It is not an error to specify a directory that contains no bitcode files.</div>
<div><br></div><div>-- Sean Silva</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
<a href="http://llvm-reviews.chandlerc.com/D2885" target="_blank">http://llvm-reviews.chandlerc.com/D2885</a><br>
<br>
Files:<br>
tools/llvm-link/llvm-link.cpp<br>
<br>
Index: tools/llvm-link/llvm-link.cpp<br>
===================================================================<br>
--- tools/llvm-link/llvm-link.cpp<br>
+++ tools/llvm-link/llvm-link.cpp<br>
@@ -19,19 +19,22 @@<br>
#include "llvm/IR/Module.h"<br>
#include "llvm/IRReader/IRReader.h"<br>
#include "llvm/Support/CommandLine.h"<br>
+#include "llvm/Support/FileSystem.h"<br>
#include "llvm/Support/ManagedStatic.h"<br>
#include "llvm/Support/Path.h"<br>
#include "llvm/Support/PrettyStackTrace.h"<br>
#include "llvm/Support/Signals.h"<br>
#include "llvm/Support/SourceMgr.h"<br>
#include "llvm/Support/SystemUtils.h"<br>
+#include "llvm/Support/system_error.h"<br>
#include "llvm/Support/ToolOutputFile.h"<br>
#include <memory><br>
using namespace llvm;<br>
+using namespace llvm::sys::fs;<br>
<br>
static cl::list<std::string><br>
InputFilenames(cl::Positional, cl::OneOrMore,<br>
- cl::desc("<input bitcode files>"));<br>
+ cl::desc("<input bitcode files|input bitcode directory>"));<br>
<br>
static cl::opt<std::string><br>
OutputFilename("o", cl::desc("Override output filename"), cl::init("-"),<br>
@@ -50,6 +53,9 @@<br>
static cl::opt<bool><br>
DumpAsm("d", cl::desc("Print assembly as linked"), cl::Hidden);<br>
<br>
+static cl::opt<bool><br>
+Directory("dir", cl::desc("Input argument is a directory containing bitcode files"));<br>
+<br>
// LoadFile - Read the specified bitcode file in and return it. This routine<br>
// searches the link path for the specified file to try to find it...<br>
//<br>
@@ -75,6 +81,26 @@<br>
llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.<br>
cl::ParseCommandLineOptions(argc, argv, "llvm linker\n");<br>
<br>
+ if (Directory) {<br>
+ if (InputFilenames.size() > 1) {<br>
+ errs() << "Error: More than one directory specified\n";<br>
+ return -1;<br>
+ }<br>
+<br>
+ // fill InputFilenames with the name of the files in the argument directory,<br>
+ // thus allowing the code below to work with no changes<br>
+ error_code ec; // output parameter to store error codes<br>
+ std::string dir = InputFilenames[0];<br>
+ InputFilenames.clear();<br>
+ for (directory_iterator I = directory_iterator(dir, ec), E; I != E; I.increment(ec)) {<br>
+ if (ec != ec.success()) {<br>
+ errs() << "Error iterating directory: " << ec.message() << "\n";<br>
+ return -1;<br>
+ }<br>
+ InputFilenames.push_back(I->path());<br>
+ }<br>
+ }<br>
+<br>
unsigned BaseArg = 0;<br>
std::string ErrorMessage;<br>
<br>_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
<br></blockquote></div><br></div></div>