Rename Kept -> Suffix
[oota-llvm.git] / tools / link / link.cpp
index 6cb30a2bd4e69e695bb8a1bbf0f63571749d465a..075e7075e8414e526821552ba14adcedbaae6bf8 100644 (file)
@@ -9,7 +9,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "llvm/Transforms/Linker.h"
+#include "llvm/Transforms/Utils/Linker.h"
 #include "llvm/Bytecode/Reader.h"
 #include "llvm/Bytecode/Writer.h"
 #include "llvm/Module.h"
 #include <sys/types.h>     // For FileExists
 #include <sys/stat.h>
 
+using std::cerr;
 
-cl::StringList InputFilenames("", "Load <arg> files, linking them together", 
-                             cl::OneOrMore);
-cl::String OutputFilename("o", "Override output filename", cl::NoFlags, "-");
-cl::Flag   Force         ("f", "Overwrite output files", cl::NoFlags, false);
-cl::Flag   Verbose       ("v", "Print information about actions taken");
-cl::Flag   DumpAsm       ("d", "Print assembly as linked", cl::Hidden, false);
-cl::StringList LibPaths  ("L", "Specify a library search path", cl::ZeroOrMore);
-cl::StringList Libraries ("l", "Specify libraries to link to", cl::ZeroOrMore);
+static cl::list<std::string>
+InputFilenames(cl::Positional, cl::OneOrMore,
+               cl::desc("<input bytecode files>"));
 
+static cl::opt<std::string>
+OutputFilename("o", cl::desc("Override output filename"), cl::init("-"),
+               cl::value_desc("filename"));
+
+static cl::opt<bool> Force("f", cl::desc("Overwrite output files"));
+
+static cl::opt<bool>
+Verbose("v", cl::desc("Print information about actions taken"));
+
+static cl::opt<bool>
+DumpAsm("d", cl::desc("Print assembly as linked"), cl::Hidden);
+
+static cl::list<std::string>
+LibPaths("L", cl::desc("Specify a library search path"), cl::ZeroOrMore,
+         cl::value_desc("directory"), cl::Prefix);
 
 // FileExists - Return true if the specified string is an openable file...
 static inline bool FileExists(const std::string &FN) {
@@ -75,9 +86,7 @@ static inline std::auto_ptr<Module> LoadFile(const std::string &FN) {
 
 
 int main(int argc, char **argv) {
-  cl::ParseCommandLineOptions(argc, argv, " llvm linker\n",
-                             cl::EnableSingleLetterArgValue |
-                             cl::DisableSingleLetterArgGrouping);
+  cl::ParseCommandLineOptions(argc, argv, " llvm linker\n");
   assert(InputFilenames.size() > 0 && "OneOrMore is not working");
 
   unsigned BaseArg = 0;
@@ -90,9 +99,6 @@ int main(int argc, char **argv) {
     OutputFilename = InputFilenames[1];
   }
 
-  if (!Libraries.empty())
-    cerr << "LLVM Linker Warning:  Linking to libraries is unimplemented!\n";
-
   std::auto_ptr<Module> Composite(LoadFile(InputFilenames[BaseArg]));
   if (Composite.get() == 0) return 1;
 
@@ -103,28 +109,26 @@ int main(int argc, char **argv) {
     if (Verbose) cerr << "Linking in '" << InputFilenames[i] << "'\n";
 
     if (LinkModules(Composite.get(), M.get(), &ErrorMessage)) {
-      cerr << "Error linking in '" << InputFilenames[i] << "': "
+      cerr << argv[0] << ": error linking in '" << InputFilenames[i] << "': "
           << ErrorMessage << "\n";
       return 1;
     }
   }
 
-  if (DumpAsm) {
-    cerr << "Here's the assembly:\n";
-    Composite.get()->dump();
-  }
+  if (DumpAsm) cerr << "Here's the assembly:\n" << Composite.get();
 
-  ostream *Out = &cout;  // Default to printing to stdout...
+  std::ostream *Out = &std::cout;  // Default to printing to stdout...
   if (OutputFilename != "-") {
     if (!Force && std::ifstream(OutputFilename.c_str())) {
       // If force is not specified, make sure not to overwrite a file!
-      cerr << "Error opening '" << OutputFilename << "': File exists!\n"
+      cerr << argv[0] << ": error opening '" << OutputFilename
+           << "': file exists!\n"
            << "Use -f command line argument to force output\n";
       return 1;
     }
     Out = new std::ofstream(OutputFilename.c_str());
     if (!Out->good()) {
-      cerr << "Error opening '" << OutputFilename << "'!\n";
+      cerr << argv[0] << ": error opening '" << OutputFilename << "'!\n";
       return 1;
     }