[llvm-commits] [llvm] r79808 - in /llvm/trunk/tools: llvm-extract/llvm-extract.cpp llvm-link/llvm-link.cpp

Chris Lattner sabre at nondot.org
Sat Aug 22 19:56:05 PDT 2009


Author: lattner
Date: Sat Aug 22 21:56:05 2009
New Revision: 79808

URL: http://llvm.org/viewvc/llvm-project?rev=79808&view=rev
Log:
simplify output file selection, fixing two FIXMEs about binary output

Modified:
    llvm/trunk/tools/llvm-extract/llvm-extract.cpp
    llvm/trunk/tools/llvm-link/llvm-link.cpp

Modified: llvm/trunk/tools/llvm-extract/llvm-extract.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-extract/llvm-extract.cpp?rev=79808&r1=79807&r2=79808&view=diff

==============================================================================
--- llvm/trunk/tools/llvm-extract/llvm-extract.cpp (original)
+++ llvm/trunk/tools/llvm-extract/llvm-extract.cpp Sat Aug 22 21:56:05 2009
@@ -110,29 +110,20 @@
   Passes.add(createDeadTypeEliminationPass());   // Remove dead types...
   Passes.add(createStripDeadPrototypesPass());   // Remove dead func decls
 
-  raw_ostream *Out = 0;
-
-  if (OutputFilename != "-") {  // Not stdout?
-    std::string ErrorInfo;
-    Out = new raw_fd_ostream(OutputFilename.c_str(), ErrorInfo,
-                             raw_fd_ostream::F_Binary |
-                             (Force ? raw_fd_ostream::F_Force : 0));
-    if (!ErrorInfo.empty()) {
-      errs() << ErrorInfo << '\n';
-      if (!Force)
-        errs() << "Use -f command line argument to force output\n";
-      delete Out;
-      return 1;
-    }
-  } else {                      // Specified stdout
-    // FIXME: outs() is not binary!
-    Out = &outs();
+  std::string ErrorInfo;
+  std::auto_ptr<raw_fd_ostream>
+  Out(new raw_fd_ostream(OutputFilename.c_str(), ErrorInfo,
+                         raw_fd_ostream::F_Binary |
+                         (Force ? raw_fd_ostream::F_Force : 0)));
+  if (!ErrorInfo.empty()) {
+    errs() << ErrorInfo << '\n';
+    if (!Force)
+      errs() << "Use -f command line argument to force output\n";
+    return 1;
   }
 
   Passes.add(createBitcodeWriterPass(*Out));
   Passes.run(*M.get());
 
-  if (Out != &outs())
-    delete Out;
   return 0;
 }

Modified: llvm/trunk/tools/llvm-link/llvm-link.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-link/llvm-link.cpp?rev=79808&r1=79807&r2=79808&view=diff

==============================================================================
--- llvm/trunk/tools/llvm-link/llvm-link.cpp (original)
+++ llvm/trunk/tools/llvm-link/llvm-link.cpp Sat Aug 22 21:56:05 2009
@@ -118,25 +118,22 @@
 
   if (DumpAsm) errs() << "Here's the assembly:\n" << *Composite.get();
 
-  // FIXME: outs() is not binary!
-  raw_ostream *Out = &outs();  // Default to printing to stdout...
-  if (OutputFilename != "-") {
-    std::string ErrorInfo;
-    Out = new raw_fd_ostream(OutputFilename.c_str(), ErrorInfo,
-                             raw_fd_ostream::F_Binary |
-                             (Force ? raw_fd_ostream::F_Force : 0));
-    if (!ErrorInfo.empty()) {
-      errs() << ErrorInfo << '\n';
-      if (!Force)
-        errs() << "Use -f command line argument to force output\n";
-      delete Out;
-      return 1;
-    }
+  std::string ErrorInfo;
+  std::auto_ptr<raw_ostream> 
+  Out(new raw_fd_ostream(OutputFilename.c_str(), ErrorInfo,
+                         raw_fd_ostream::F_Binary |
+                         (Force ? raw_fd_ostream::F_Force : 0)));
+  if (!ErrorInfo.empty()) {
+    errs() << ErrorInfo << '\n';
+    if (!Force)
+      errs() << "Use -f command line argument to force output\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.get())) {
     errs() << argv[0] << ": linked module is broken!\n";
@@ -146,6 +143,5 @@
   if (Verbose) errs() << "Writing bitcode...\n";
   WriteBitcodeToFile(Composite.get(), *Out);
 
-  if (Out != &outs()) delete Out;
   return 0;
 }





More information about the llvm-commits mailing list