[llvm-commits] [llvm] r75056 - in /llvm/trunk: include/llvm/Support/GraphWriter.h lib/Support/GraphWriter.cpp
David Greene
greened at obbligato.org
Wed Jul 8 14:53:53 PDT 2009
Author: greened
Date: Wed Jul 8 16:53:41 2009
New Revision: 75056
URL: http://llvm.org/viewvc/llvm-project?rev=75056&view=rev
Log:
Allow users of GraphWriter to display graphs asynchronously. This
provides a way to quickly dump a bunch of graph information to dot files
and display them. It's a timesaver when working on large systems.
Modified:
llvm/trunk/include/llvm/Support/GraphWriter.h
llvm/trunk/lib/Support/GraphWriter.cpp
Modified: llvm/trunk/include/llvm/Support/GraphWriter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/GraphWriter.h?rev=75056&r1=75055&r2=75056&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/GraphWriter.h (original)
+++ llvm/trunk/include/llvm/Support/GraphWriter.h Wed Jul 8 16:53:41 2009
@@ -29,6 +29,7 @@
#include "llvm/System/Path.h"
#include <fstream>
#include <vector>
+#include <cassert>
namespace llvm {
@@ -66,7 +67,7 @@
}
}
-void DisplayGraph(const sys::Path& Filename);
+void DisplayGraph(const sys::Path& Filename, bool wait=true);
template<typename GraphType>
class GraphWriter {
Modified: llvm/trunk/lib/Support/GraphWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/GraphWriter.cpp?rev=75056&r1=75055&r2=75056&view=diff
==============================================================================
--- llvm/trunk/lib/Support/GraphWriter.cpp (original)
+++ llvm/trunk/lib/Support/GraphWriter.cpp Wed Jul 8 16:53:41 2009
@@ -18,7 +18,7 @@
#include "llvm/Config/config.h"
using namespace llvm;
-void llvm::DisplayGraph(const sys::Path &Filename) {
+void llvm::DisplayGraph(const sys::Path &Filename, bool wait) {
std::string ErrMsg;
#if HAVE_GRAPHVIZ
sys::Path Graphviz(LLVM_PATH_GRAPHVIZ);
@@ -30,16 +30,24 @@
cerr << "Running 'Graphviz' program... " << std::flush;
if (sys::Program::ExecuteAndWait(Graphviz, &args[0],0,0,0,0,&ErrMsg)) {
- cerr << "Error viewing graph: " << ErrMsg << "\n";
+ cerr << "Error viewing graph " << Filename << ": " << ErrMsg << "\n";
}
-#elif (HAVE_GV && HAVE_DOT)
+ else {
+ Filename.eraseFromDisk();
+ }
+
+#elif (HAVE_GV && (HAVE_DOT || HAVE_FDP))
sys::Path PSFilename = Filename;
PSFilename.appendSuffix("ps");
-
- sys::Path dot(LLVM_PATH_DOT);
+
+#if HAVE_FDP
+ sys::Path prog(LLVM_PATH_FDP);
+#else
+ sys::Path prog(LLVM_PATH_DOT);
+#endif
std::vector<const char*> args;
- args.push_back(dot.c_str());
+ args.push_back(prog.c_str());
args.push_back("-Tps");
args.push_back("-Nfontname=Courier");
args.push_back("-Gsize=7.5,10");
@@ -48,9 +56,10 @@
args.push_back(PSFilename.c_str());
args.push_back(0);
- cerr << "Running 'dot' program... " << std::flush;
- if (sys::Program::ExecuteAndWait(dot, &args[0],0,0,0,0,&ErrMsg)) {
- cerr << "Error viewing graph: '" << ErrMsg << "\n";
+ cerr << "Running '" << prog << "' program... " << std::flush;
+
+ if (sys::Program::ExecuteAndWait(prog, &args[0],0,0,0,0,&ErrMsg)) {
+ cerr << "Error viewing graph " << Filename << ": '" << ErrMsg << "\n";
} else {
cerr << " done. \n";
@@ -62,11 +71,18 @@
args.push_back(0);
ErrMsg.clear();
- if (sys::Program::ExecuteAndWait(gv, &args[0],0,0,0,0,&ErrMsg)) {
- cerr << "Error viewing graph: " << ErrMsg << "\n";
+ if (wait) {
+ if (sys::Program::ExecuteAndWait(gv, &args[0],0,0,0,0,&ErrMsg)) {
+ cerr << "Error viewing graph: " << ErrMsg << "\n";
+ }
+ Filename.eraseFromDisk();
+ PSFilename.eraseFromDisk();
+ }
+ else {
+ sys::Program::ExecuteNoWait(gv, &args[0],0,0,0,&ErrMsg);
+ cerr << "Remember to erase graph files: " << Filename << " " << PSFilename << "\n";
}
}
- PSFilename.eraseFromDisk();
#elif HAVE_DOTTY
sys::Path dotty(LLVM_PATH_DOTTY);
@@ -77,13 +93,12 @@
cerr << "Running 'dotty' program... " << std::flush;
if (sys::Program::ExecuteAndWait(dotty, &args[0],0,0,0,0,&ErrMsg)) {
- cerr << "Error viewing graph: " << ErrMsg << "\n";
+ cerr << "Error viewing graph " << Filename << ": " << ErrMsg << "\n";
} else {
#ifdef __MINGW32__ // Dotty spawns another app and doesn't wait until it returns
return;
#endif
+ Filename.eraseFromDisk();
}
#endif
-
- Filename.eraseFromDisk();
}
More information about the llvm-commits
mailing list