From: Ted Kremenek Date: Thu, 28 Aug 2008 03:54:51 +0000 (+0000) Subject: Automatically execute ubiviz. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=710ad9343f32b33b336369b20edad1a21a0b3299;p=clang Automatically execute ubiviz. 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 --- diff --git a/Driver/AnalysisConsumer.cpp b/Driver/AnalysisConsumer.cpp index 81f14554fa..a8390e147c 100644 --- a/Driver/AnalysisConsumer.cpp +++ b/Driver/AnalysisConsumer.cpp @@ -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 using namespace clang; @@ -470,13 +471,19 @@ namespace { class UbigraphViz : public ExplodedNodeImpl::Auditor { llvm::OwningPtr Out; + llvm::sys::Path Dir, Filename; unsigned Cntr; typedef llvm::DenseMap 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 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 diff --git a/utils/ubiviz b/utils/ubiviz index 1a8f742c3c..687e8c007a 100755 --- a/utils/ubiviz +++ b/utils/ubiviz @@ -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:])