[llvm-commits] [llvm] r51760 - in /llvm/trunk/tools/llvmc2: CompilationGraph.cpp CompilationGraph.h doc/LLVMC-Reference.rst llvmc.cpp

Mikhail Glushenkov foldr at codedgers.com
Thu May 29 23:29:18 PDT 2008


Author: foldr
Date: Fri May 30 01:29:17 2008
New Revision: 51760

URL: http://llvm.org/viewvc/llvm-project?rev=51760&view=rev
Log:
Add a --save-temps option.

Modified:
    llvm/trunk/tools/llvmc2/CompilationGraph.cpp
    llvm/trunk/tools/llvmc2/CompilationGraph.h
    llvm/trunk/tools/llvmc2/doc/LLVMC-Reference.rst
    llvm/trunk/tools/llvmc2/llvmc.cpp

Modified: llvm/trunk/tools/llvmc2/CompilationGraph.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvmc2/CompilationGraph.cpp?rev=51760&r1=51759&r2=51760&view=diff

==============================================================================
--- llvm/trunk/tools/llvmc2/CompilationGraph.cpp (original)
+++ llvm/trunk/tools/llvmc2/CompilationGraph.cpp Fri May 30 01:29:17 2008
@@ -139,8 +139,17 @@
 namespace {
   sys::Path MakeTempFile(const sys::Path& TempDir, const std::string& BaseName,
                          const std::string& Suffix) {
-    sys::Path Out = TempDir;
-    Out.appendComponent(BaseName);
+    sys::Path Out;
+
+    // Make sure we don't end up with path names like '/file.o' if the
+    // TempDir is empty.
+    if (TempDir.empty()) {
+      Out.set(BaseName);
+    }
+    else {
+      Out = TempDir;
+      Out.appendComponent(BaseName);
+    }
     Out.appendSuffix(Suffix);
     Out.makeUnique(true, NULL);
     return Out;

Modified: llvm/trunk/tools/llvmc2/CompilationGraph.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvmc2/CompilationGraph.h?rev=51760&r1=51759&r2=51760&view=diff

==============================================================================
--- llvm/trunk/tools/llvmc2/CompilationGraph.h (original)
+++ llvm/trunk/tools/llvmc2/CompilationGraph.h Fri May 30 01:29:17 2008
@@ -79,8 +79,6 @@
     { OutEdges.push_back(llvm::IntrusiveRefCntPtr<Edge>(E)); }
 
     // Inward edge counter. Used to implement topological sort.
-    // TOTHINK: Move the mutable counter back into Tool classes? Makes
-    // us more const-correct.
     void IncrInEdges() { ++InEdges; }
     void DecrInEdges() { --InEdges; }
     bool HasNoInEdges() const { return InEdges == 0; }

Modified: llvm/trunk/tools/llvmc2/doc/LLVMC-Reference.rst
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvmc2/doc/LLVMC-Reference.rst?rev=51760&r1=51759&r2=51760&view=diff

==============================================================================
--- llvm/trunk/tools/llvmc2/doc/LLVMC-Reference.rst (original)
+++ llvm/trunk/tools/llvmc2/doc/LLVMC-Reference.rst Fri May 30 01:29:17 2008
@@ -76,6 +76,12 @@
   current directory with the compilation graph description in the
   Graphviz format. Hidden option, useful for debugging.
 
+* ``--save-temps`` - Write temporary files to the current directory
+  and do not delete them on exit. Hidden option, useful for debugging.
+
+* ``--help``, ``--help-hidden``, ``--version`` - These options have
+  their standard meaning.
+
 
 Customizing LLVMC: the compilation graph
 ========================================

Modified: llvm/trunk/tools/llvmc2/llvmc.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvmc2/llvmc.cpp?rev=51760&r1=51759&r2=51760&view=diff

==============================================================================
--- llvm/trunk/tools/llvmc2/llvmc.cpp (original)
+++ llvm/trunk/tools/llvmc2/llvmc.cpp Fri May 30 01:29:17 2008
@@ -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;
   }
 }





More information about the llvm-commits mailing list