[llvm-commits] CVS: llvm/lib/CodeGen/MachineFunction.cpp

Jim Laskey jlaskey at apple.com
Wed Oct 12 05:09:21 PDT 2005



Changes in directory llvm/lib/CodeGen:

MachineFunction.cpp updated: 1.80 -> 1.81
---
Log message:

Added graphviz/gv support for MF.



---
Diffs of the changes:  (+22 -0)

 MachineFunction.cpp |   22 ++++++++++++++++++++++
 1 files changed, 22 insertions(+)


Index: llvm/lib/CodeGen/MachineFunction.cpp
diff -u llvm/lib/CodeGen/MachineFunction.cpp:1.80 llvm/lib/CodeGen/MachineFunction.cpp:1.81
--- llvm/lib/CodeGen/MachineFunction.cpp:1.80	Wed Aug 31 17:34:59 2005
+++ llvm/lib/CodeGen/MachineFunction.cpp	Wed Oct 12 07:09:05 2005
@@ -25,6 +25,7 @@
 #include "llvm/Instructions.h"
 #include "llvm/Support/LeakDetector.h"
 #include "llvm/Support/GraphWriter.h"
+#include "llvm/Config/config.h"
 #include <fstream>
 #include <iostream>
 #include <sstream>
@@ -206,6 +207,7 @@
 
 void MachineFunction::viewCFG() const
 {
+#ifndef NDEBUG
   std::string Filename = "/tmp/cfg." + getFunction()->getName() + ".dot";
   std::cerr << "Writing '" << Filename << "'... ";
   std::ofstream F(Filename.c_str());
@@ -219,6 +221,17 @@
   F.close();
   std::cerr << "\n";
 
+#ifdef HAVE_GRAPHVIZ
+  std::cerr << "Running 'Graphviz' program... " << std::flush;
+  if (system((LLVM_PATH_GRAPHVIZ " " + Filename).c_str())) {
+    std::cerr << "Error viewing graph: 'Graphviz' not in path?\n";
+  } else {
+    system(("rm " + Filename).c_str());
+    return;
+  }
+#endif  // HAVE_GRAPHVIZ
+
+#ifdef HAVE_GV
   std::cerr << "Running 'dot' program... " << std::flush;
   if (system(("dot -Tps -Nfontname=Courier -Gsize=7.5,10 " + Filename
               + " > /tmp/cfg.tempgraph.ps").c_str())) {
@@ -228,6 +241,15 @@
     system("gv /tmp/cfg.tempgraph.ps");
   }
   system(("rm " + Filename + " /tmp/cfg.tempgraph.ps").c_str());
+  return;
+#endif  // HAVE_GV
+#endif  // NDEBUG
+  std::cerr << "MachineFunction::viewCFG is only available in debug builds on "
+            << "systems with Graphviz or gv!\n";
+
+#ifndef NDEBUG
+  system(("rm " + Filename).c_str());
+#endif
 }
 
 void MachineFunction::viewCFGOnly() const






More information about the llvm-commits mailing list