Updating documentation based on my change to remove the template disambiguation.
[oota-llvm.git] / tools / llvm-link / llvm-link.cpp
index ed8c06e79843965a082f8d216b6d77899b1c238d..17866a06713f532664810a6e111464ca6124c34c 100644 (file)
@@ -55,20 +55,18 @@ static cl::opt<bool>
 SuppressWarnings("suppress-warnings", cl::desc("Suppress all linking warnings"),
                  cl::init(false));
 
-// 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...
+// Read the specified bitcode file in and return it. This routine searches the
+// link path for the specified file to try to find it...
 //
-static inline Module *LoadFile(const char *argv0, const std::string &FN,
-                               LLVMContext& Context) {
+static std::unique_ptr<Module>
+loadFile(const char *argv0, const std::string &FN, LLVMContext &Context) {
   SMDiagnostic Err;
   if (Verbose) errs() << "Loading '" << FN << "'\n";
-  Module* Result = nullptr;
+  std::unique_ptr<Module> Result = parseIRFile(FN, Err, Context);
+  if (!Result)
+    Err.print(argv0, errs());
 
-  Result = ParseIRFile(FN, Err, Context);
-  if (Result) return Result;   // Load successful!
-
-  Err.print(argv0, errs());
-  return nullptr;
+  return Result;
 }
 
 int main(int argc, char **argv) {
@@ -83,8 +81,8 @@ int main(int argc, char **argv) {
   unsigned BaseArg = 0;
   std::string ErrorMessage;
 
-  std::unique_ptr<Module> Composite(
-      LoadFile(argv[0], InputFilenames[BaseArg], Context));
+  std::unique_ptr<Module> Composite =
+      loadFile(argv[0], InputFilenames[BaseArg], Context);
   if (!Composite.get()) {
     errs() << argv[0] << ": error loading file '"
            << InputFilenames[BaseArg] << "'\n";
@@ -93,7 +91,7 @@ int main(int argc, char **argv) {
 
   Linker L(Composite.get(), SuppressWarnings);
   for (unsigned i = BaseArg+1; i < InputFilenames.size(); ++i) {
-    std::unique_ptr<Module> M(LoadFile(argv[0], InputFilenames[i], Context));
+    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;
@@ -110,10 +108,10 @@ int main(int argc, char **argv) {
 
   if (DumpAsm) errs() << "Here's the assembly:\n" << *Composite;
 
-  std::string ErrorInfo;
-  tool_output_file Out(OutputFilename.c_str(), ErrorInfo, sys::fs::F_None);
-  if (!ErrorInfo.empty()) {
-    errs() << ErrorInfo << '\n';
+  std::error_code EC;
+  tool_output_file Out(OutputFilename, EC, sys::fs::F_None);
+  if (EC) {
+    errs() << EC.message() << '\n';
     return 1;
   }