]> granicus.if.org Git - clang/commitdiff
Automatically execute ubiviz.
authorTed Kremenek <kremenek@apple.com>
Thu, 28 Aug 2008 03:54:51 +0000 (03:54 +0000)
committerTed Kremenek <kremenek@apple.com>
Thu, 28 Aug 2008 03:54:51 +0000 (03:54 +0000)
Cleanup ubigraph files when don't drawing the graphs.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@55459 91177308-0d34-0410-b5e6-96231b3b80d8

Driver/AnalysisConsumer.cpp
utils/ubiviz

index 81f14554fa86e1cccbc33d08cc886e31291465d0..a8390e147c8695de8128365efc4a68f8ad840efc 100644 (file)
@@ -33,6 +33,7 @@
 #include "llvm/Support/Streams.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/System/Path.h"
+#include "llvm/System/Program.h"
 #include <vector>
 
 using namespace clang;
@@ -470,13 +471,19 @@ namespace {
   
 class UbigraphViz : public ExplodedNodeImpl::Auditor {
   llvm::OwningPtr<llvm::raw_ostream> Out;
+  llvm::sys::Path Dir, Filename;
   unsigned Cntr;
 
   typedef llvm::DenseMap<void*,unsigned> VMap;
   VMap M;
   
 public:
-  UbigraphViz(llvm::raw_ostream* out) : Out(out), Cntr(0) {}  
+  UbigraphViz(llvm::raw_ostream* out, llvm::sys::Path& dir,
+              llvm::sys::Path& filename)
+    : Out(out), Dir(dir), Filename(filename), Cntr(0) {} 
+  
+  ~UbigraphViz();
+  
   virtual void AddEdge(ExplodedNodeImpl* Src, ExplodedNodeImpl* Dst);  
 };
   
@@ -485,10 +492,11 @@ public:
 static ExplodedNodeImpl::Auditor* CreateUbiViz() {
   std::string ErrMsg;
   
-  llvm::sys::Path Filename = llvm::sys::Path::GetTemporaryDirectory(&ErrMsg);
+  llvm::sys::Path Dir = llvm::sys::Path::GetTemporaryDirectory(&ErrMsg);
   if (!ErrMsg.empty())
     return 0;
 
+  llvm::sys::Path Filename = Dir;
   Filename.appendComponent("llvm_ubi");
   Filename.makeUnique(true,&ErrMsg);
 
@@ -504,7 +512,7 @@ static ExplodedNodeImpl::Auditor* CreateUbiViz() {
   if (!ErrMsg.empty())
     return 0;
   
-  return new UbigraphViz(Stream.take());
+  return new UbigraphViz(Stream.take(), Dir, Filename);
 }
 
 void UbigraphViz::AddEdge(ExplodedNodeImpl* Src, ExplodedNodeImpl* Dst) {
@@ -535,3 +543,20 @@ void UbigraphViz::AddEdge(ExplodedNodeImpl* Src, ExplodedNodeImpl* Dst) {
        << ", ('arrow','true'), ('oriented', 'true'))\n";
 }
 
+UbigraphViz::~UbigraphViz() {
+  Out.reset(0);
+  llvm::cerr << "Running 'ubiviz' program... ";
+  std::string ErrMsg;
+  llvm::sys::Path Ubiviz = llvm::sys::Program::FindProgramByName("ubiviz");
+  std::vector<const char*> args;
+  args.push_back(Ubiviz.c_str());
+  args.push_back(Filename.c_str());
+  args.push_back(0);
+  
+  if (llvm::sys::Program::ExecuteAndWait(Ubiviz, &args[0],0,0,0,0,&ErrMsg)) {
+    llvm::cerr << "Error viewing graph: " << ErrMsg << "\n";
+  }
+  
+  // Delete the directory.
+  Dir.eraseFromDisk(true); 
+}
\ No newline at end of file
index 1a8f742c3c2195928d211c1ade051fb316407c83..687e8c007a56e71e23a0e2206422f84f3a6ebb60 100755 (executable)
@@ -50,6 +50,9 @@ def main(args):
     G.clear()
     for x in StreamData(arg):
       Display(G,x)
+  
+  sys.exit(0)
+  
 
 if __name__ == '__main__':
     main(sys.argv[1:])