Clean up anands patch
[oota-llvm.git] / tools / as / as.cpp
index 59049748354e6984b2775d3bd758869e82297993..a956203e64910420a617c426b04c11d87a808a6e 100644 (file)
@@ -6,17 +6,17 @@
 //   as [options]      - Read LLVM assembly from stdin, write bytecode to stdout
 //   as [options] x.ll - Read LLVM assembly from the x.ll file, write bytecode
 //                       to the x.bc file.
-//
+// 
 //===------------------------------------------------------------------------===
 
 #include "llvm/Module.h"
 #include "llvm/Assembly/Parser.h"
-#include "llvm/Assembly/Writer.h"
 #include "llvm/Bytecode/Writer.h"
 #include "Support/CommandLine.h"
+#include "Support/Signals.h"
 #include <fstream>
-#include <string>
 #include <memory>
+using std::cerr;
 
 cl::String InputFilename ("", "Parse <arg> file, compile to bytecode", 0, "-");
 cl::String OutputFilename("o", "Override output filename", cl::NoFlags, "");
@@ -26,17 +26,16 @@ cl::Flag   DumpAsm       ("d", "Print assembly as parsed", cl::Hidden, false);
 int main(int argc, char **argv) {
   cl::ParseCommandLineOptions(argc, argv, " llvm .ll -> .bc assembler\n");
 
-  ostream *Out = 0;
+  std::ostream *Out = 0;
   try {
     // Parse the file now...
-    std::auto_ptr<Module> C(ParseAssemblyFile(InputFilename));
-    if (C.get() == 0) {
+    std::auto_ptr<Module> M(ParseAssemblyFile(InputFilename));
+    if (M.get() == 0) {
       cerr << "assembly didn't read correctly.\n";
       return 1;
     }
   
-    if (DumpAsm)
-      cerr << "Here's the assembly:\n" << C.get();
+    if (DumpAsm) cerr << "Here's the assembly:\n" << M.get();
 
     if (OutputFilename != "") {   // Specified an output filename?
       if (!Force && std::ifstream(OutputFilename.c_str())) {
@@ -49,7 +48,7 @@ int main(int argc, char **argv) {
     } else {
       if (InputFilename == "-") {
        OutputFilename = "-";
-       Out = &cout;
+       Out = &std::cout;
       } else {
        std::string IFN = InputFilename;
        int Len = IFN.length();
@@ -69,6 +68,9 @@ int main(int argc, char **argv) {
         }
 
        Out = new std::ofstream(OutputFilename.c_str());
+        // Make sure that the Out file gets unlink'd from the disk if we get a
+        // SIGINT
+        RemoveFileOnSignal(OutputFilename);
       }
     }
   
@@ -77,13 +79,13 @@ int main(int argc, char **argv) {
       return 1;
     }
    
-    WriteBytecodeToFile(C.get(), *Out);
+    WriteBytecodeToFile(M.get(), *Out);
   } catch (const ParseException &E) {
-    cerr << E.getMessage() << endl;
+    cerr << E.getMessage() << std::endl;
     return 1;
   }
 
-  if (Out != &cout) delete Out;
+  if (Out != &std::cout) delete Out;
   return 0;
 }