Add a --save-temps option.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@51760 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/llvmc2/llvmc.cpp b/tools/llvmc2/llvmc.cpp
index ba2d70a..e093439 100644
--- a/tools/llvmc2/llvmc.cpp
+++ b/tools/llvmc2/llvmc.cpp
@@ -32,7 +32,6 @@
 // Built-in command-line options.
 // External linkage here is intentional.
 
-// TOFIX: Add a --keep-temps option.
 // TOFIX: Write a 'driver driver' (easier to do as a separate
 // executable that drives llvmc2 proper).
 cl::list<std::string> InputFilenames(cl::Positional, cl::desc("<input file>"),
@@ -50,12 +49,17 @@
 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);
@@ -65,7 +69,8 @@
       throw;
     }
 
-    tempDir.eraseFromDisk(true);
+    if (!SaveTemps)
+      tempDir.eraseFromDisk(true);
     return ret;
   }
 }