Add a SubclassData field to SDNode, similar to what's done
[oota-llvm.git] / tools / llvmc2 / llvmc.cpp
index c06ea59ed9a40869171847e18198765859ebb67f..e073845d09e07978666672e3880cca0241012946 100644 (file)
@@ -1,4 +1,4 @@
-//===--- llvmc.cpp - The LLVM Compiler Driver ------------------*- C++ -*-===//
+//===--- llvmc.cpp - The LLVM Compiler Driver -------------------*- C++ -*-===//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -39,6 +39,8 @@ cl::opt<std::string> OutputFilename("o", cl::desc("Output file name"),
 cl::list<std::string> Languages("x",
           cl::desc("Specify the language of the following input files"),
           cl::ZeroOrMore);
+cl::opt<bool> DryRun("dry-run",
+                     cl::desc("Only pretend to run commands"));
 cl::opt<bool> VerboseMode("v",
                           cl::desc("Enable verbose mode"));
 cl::opt<bool> WriteGraph("write-graph",
@@ -47,12 +49,17 @@ cl::opt<bool> WriteGraph("write-graph",
 cl::opt<bool> ViewGraph("view-graph",
                          cl::desc("Show compilation graph in GhostView"),
                          cl::Hidden);
+cl::opt<bool> SaveTemps("save-temps",
+                         cl::desc("Keep temporary files"),
+                         cl::Hidden);
 
 namespace {
   /// BuildTargets - A small wrapper for CompilationGraph::Build.
   int BuildTargets(CompilationGraph& graph) {
     int ret;
-    sys::Path tempDir(sys::Path::GetTemporaryDirectory());
+    const sys::Path& tempDir = SaveTemps
+      ? sys::Path("")
+      : sys::Path(sys::Path::GetTemporaryDirectory());
 
     try {
       ret = graph.Build(tempDir);
@@ -62,7 +69,8 @@ namespace {
       throw;
     }
 
-    tempDir.eraseFromDisk(true);
+    if (!SaveTemps)
+      tempDir.eraseFromDisk(true);
     return ret;
   }
 }
@@ -87,8 +95,7 @@ int main(int argc, char** argv) {
     }
 
     if (InputFilenames.empty()) {
-      std::cerr << "No input files.\n";
-      return 1;
+      throw std::runtime_error("no input files");
     }
 
     return BuildTargets(graph);
@@ -97,10 +104,10 @@ int main(int argc, char** argv) {
     return ec.code();
   }
   catch(const std::exception& ex) {
-    std::cerr << ex.what() << '\n';
+    std::cerr << argv[0] << ": " << ex.what() << '\n';
   }
   catch(...) {
-    std::cerr << "Unknown error!\n";
+    std::cerr << argv[0] << ": unknown error!\n";
   }
   return 1;
 }