Add support for bottom-up graphs.
authorChris Lattner <sabre@nondot.org>
Tue, 11 Jan 2005 00:24:59 +0000 (00:24 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 11 Jan 2005 00:24:59 +0000 (00:24 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@19446 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Support/DOTGraphTraits.h
include/llvm/Support/GraphWriter.h

index 7196e51f8cbcdad05f293e39b235e62162391cfc..d734efffe1822b7a0e094e492aa916f43a28729e 100644 (file)
@@ -39,6 +39,13 @@ struct DefaultDOTGraphTraits {
     return "";
   }
 
+  /// renderGraphFromBottomUp - If this function returns true, the graph is
+  /// emitted bottom-up instead of top-down.  This requires graphviz 2.0 to work
+  /// though.
+  static bool renderGraphFromBottomUp() {
+    return false;
+  }
+
   /// getNodeLabel - Given a node and a pointer to the top level graph, return
   /// the label to print in the node.
   static std::string getNodeLabel(const void *Node, const void *Graph) {
index 02f3952422c88d42ec0317cba5d645d01c7a7be0..ffbf066c4607ffaf663ad0994b1a2b1f81cf8b56 100644 (file)
@@ -78,6 +78,9 @@ public:
     else
       O << "digraph " << Name << " {\n";
 
+    if (DOTTraits::renderGraphFromBottomUp())
+      O << "\trankdir=\"BT\";\n";
+
     std::string GraphName = DOTTraits::getGraphName(G);
     if (!GraphName.empty())
       O << "\tlabel=\"" << DOT::EscapeString(GraphName) << "\";\n";
@@ -106,14 +109,17 @@ public:
       
     O << "\tNode" << reinterpret_cast<const void*>(Node) << " [shape=record,";
     if (!NodeAttributes.empty()) O << NodeAttributes << ",";
-    O << "label=\"{"
-      << DOT::EscapeString(DOTTraits::getNodeLabel(Node, G));
+    O << "label=\"{";
+
+    if (!DOTTraits::renderGraphFromBottomUp())
+      O << DOT::EscapeString(DOTTraits::getNodeLabel(Node, G));
     
     // Print out the fields of the current node...
     child_iterator EI = GTraits::child_begin(Node);
     child_iterator EE = GTraits::child_end(Node);
     if (EI != EE) {
-      O << "|{";
+      if (!DOTTraits::renderGraphFromBottomUp()) O << "|";
+      O << "{";
       
       for (unsigned i = 0; EI != EE && i != 64; ++EI, ++i) {
         if (i) O << "|";
@@ -123,7 +129,11 @@ public:
       if (EI != EE)
         O << "|<g64>truncated...";
       O << "}";
+      if (DOTTraits::renderGraphFromBottomUp()) O << "|";
     }
+    if (DOTTraits::renderGraphFromBottomUp())
+      O << DOT::EscapeString(DOTTraits::getNodeLabel(Node, G));
+      
     O << "}\"];\n";   // Finish printing the "node" line
     
     // Output all of the edges now