[llvm-commits] CVS: llvm/include/llvm/Support/GraphWriter.h

Reid Spencer reid at x10sys.com
Tue Jun 27 09:50:12 PDT 2006



Changes in directory llvm/include/llvm/Support:

GraphWriter.h updated: 1.26 -> 1.27
---
Log message:

For PR801: http://llvm.org/PR801 :
Refactor the Graph writing code to use a common implementation which is
now in lib/Support/GraphWriter.cpp. This completes the PR.

Patch by Anton Korobeynikov. Thanks, Anton!


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

 GraphWriter.h |   58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 58 insertions(+)


Index: llvm/include/llvm/Support/GraphWriter.h
diff -u llvm/include/llvm/Support/GraphWriter.h:1.26 llvm/include/llvm/Support/GraphWriter.h:1.27
--- llvm/include/llvm/Support/GraphWriter.h:1.26	Fri Sep 30 19:19:21 2005
+++ llvm/include/llvm/Support/GraphWriter.h	Tue Jun 27 11:49:46 2006
@@ -25,8 +25,10 @@
 
 #include "llvm/Support/DOTGraphTraits.h"
 #include "llvm/ADT/GraphTraits.h"
+#include "llvm/System/Path.h"
 #include <vector>
 #include <iostream>
+#include <fstream>
 
 namespace llvm {
 
@@ -59,6 +61,8 @@
   }
 }
 
+void DisplayGraph(const sys::Path& Filename);
+  
 template<typename GraphType>
 class GraphWriter {
   std::ostream &O;
@@ -236,6 +240,60 @@
   return O;
 }
 
+template<typename GraphType>
+sys::Path WriteGraph(const GraphType &G,
+                     const std::string& Name, 
+                     const std::string& Title = "") {
+  sys::Path Filename = sys::Path::GetTemporaryDirectory();;  
+  Filename.appendComponent(Name + ".dot");
+  Filename.makeUnique();
+  std::cerr << "Writing '" << Filename << "'... ";
+  
+  std::ofstream O(Filename.c_str());
+
+  if (O.good()) {
+    // Start the graph emission process...
+    GraphWriter<GraphType> W(O, G);
+
+    // Output the header for the graph...
+    W.writeHeader(Title);
+
+    // Emit all of the nodes in the graph...
+    W.writeNodes();
+
+    // Output any customizations on the graph
+    DOTGraphTraits<GraphType>::addCustomGraphFeatures(G, W);
+
+    // Output the end of the graph
+    W.writeFooter();
+    std::cerr << " done. \n";
+
+    O.close();
+    
+  } else {
+    std::cerr << "error opening file for writing!\n";
+    Filename.clear();
+  }
+  
+  return Filename;
+}
+  
+/// ViewGraph - Emit a dot graph, run 'dot', run gv on the postscript file,
+/// then cleanup.  For use from the debugger.
+///
+template<typename GraphType>
+void ViewGraph(const GraphType& G, 
+               const std::string& Name, 
+               const std::string& Title = "") {
+  sys::Path Filename =  WriteGraph(G, Name, Title);
+
+  if (Filename.isEmpty()) {
+    return;
+  }
+  
+  DisplayGraph(Filename);
+}
+
 } // End llvm namespace
 
 #endif






More information about the llvm-commits mailing list