There is no EndPtr anymore - reinterpret the original comment in terms
[oota-llvm.git] / tools / llvm-link / llvm-link.cpp
index c60e56ae9b6e78765631b5bc5609cef3deb087c3..f2ba29cf97d452a449198d581689379b6287d345 100644 (file)
@@ -20,7 +20,7 @@
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/PrettyStackTrace.h"
-#include "llvm/Support/raw_ostream.h"
+#include "llvm/Support/ToolOutputFile.h"
 #include "llvm/Support/SystemUtils.h"
 #include "llvm/Support/IRReader.h"
 #include "llvm/System/Signals.h"
@@ -62,20 +62,14 @@ static inline std::auto_ptr<Module> LoadFile(const char *argv0,
   }
 
   SMDiagnostic Err;
-  if (Filename.exists()) {
-    if (Verbose) errs() << "Loading '" << Filename.c_str() << "'\n";
-    Module* Result = 0;
-    
-    const std::string &FNStr = Filename.str();
-    Result = ParseIRFile(FNStr, Err, Context);
-    if (Result) return std::auto_ptr<Module>(Result);   // Load successful!
-
-    if (Verbose)
-      Err.Print(argv0, errs());
-  } else {
-    errs() << "Bitcode file: '" << Filename.c_str() << "' does not exist.\n";
-  }
+  if (Verbose) errs() << "Loading '" << Filename.c_str() << "'\n";
+  Module* Result = 0;
+  
+  const std::string &FNStr = Filename.str();
+  Result = ParseIRFile(FNStr, Err, Context);
+  if (Result) return std::auto_ptr<Module>(Result);   // Load successful!
 
+  Err.Print(argv0, errs());
   return std::auto_ptr<Module>();
 }
 
@@ -122,19 +116,13 @@ int main(int argc, char **argv) {
   if (DumpAsm) errs() << "Here's the assembly:\n" << *Composite;
 
   std::string ErrorInfo;
-  std::auto_ptr<raw_ostream> 
-  Out(new raw_fd_ostream(OutputFilename.c_str(), ErrorInfo,
-                         raw_fd_ostream::F_Binary));
+  tool_output_file Out(OutputFilename.c_str(), ErrorInfo,
+                       raw_fd_ostream::F_Binary);
   if (!ErrorInfo.empty()) {
     errs() << ErrorInfo << '\n';
     return 1;
   }
 
-    // Make sure that the Out file gets unlinked from the disk if we get a
-    // SIGINT
-  if (OutputFilename != "-")
-    sys::RemoveFileOnSignal(sys::Path(OutputFilename));
-
   if (verifyModule(*Composite)) {
     errs() << argv[0] << ": linked module is broken!\n";
     return 1;
@@ -142,9 +130,12 @@ int main(int argc, char **argv) {
 
   if (Verbose) errs() << "Writing bitcode...\n";
   if (OutputAssembly) {
-    *Out << *Composite;
-  } else if (Force || !CheckBitcodeOutputToConsole(*Out, true))
-    WriteBitcodeToFile(Composite.get(), *Out);
+    Out.os() << *Composite;
+  } else if (Force || !CheckBitcodeOutputToConsole(Out.os(), true))
+    WriteBitcodeToFile(Composite.get(), Out.os());
+
+  // Declare success.
+  Out.keep();
 
   return 0;
 }