* Factor printing code again, add emitSimpleNode method
authorChris Lattner <sabre@nondot.org>
Wed, 16 Oct 2002 02:03:18 +0000 (02:03 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 16 Oct 2002 02:03:18 +0000 (02:03 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@4198 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 7783b4680876fb57055ef77f802d57506125cdf2..60cae2e50020c4cc77d91abfde63a40cd6849042 100644 (file)
@@ -124,8 +124,7 @@ public:
 
   void writeEdge(NodeType *Node, unsigned edgeidx, child_iterator EI) {
     if (NodeType *TargetNode = *EI) {
-      O << "\tNode" << (void*)Node << ":g" << edgeidx << " -> Node"
-        << (void*)TargetNode;
+      int DestPort = -1;
       if (DOTTraits::edgeTargetsEdgeSource(Node, EI)) {
         child_iterator TargetIt = DOTTraits::getEdgeTarget(Node, EI);
 
@@ -133,15 +132,37 @@ public:
         unsigned Offset = std::distance(GTraits::child_begin(TargetNode),
                                         TargetIt);
         if (Offset > 64) Offset = 64;  // Targetting the truncated part?
-        O << ":g" << Offset;        
+        DestPort = (int)Offset;
       }
-      
-      std::string EdgeAttributes = DOTTraits::getEdgeAttributes(Node, EI);
-      if (!EdgeAttributes.empty())
-        O << "[" << EdgeAttributes << "]";
-      O << ";\n";
+
+      emitEdge((void *)Node, edgeidx, (void*)TargetNode, DestPort,
+               DOTTraits::getEdgeAttributes(Node, EI));
     }
   }
+
+  /// emitSimpleNode - Outputs a simple (non-record) node
+  void emitSimpleNode(void *ID, const std::string &Attr,
+                      const std::string &Label) {
+    O << "\tNode" << ID << "[ ";
+    if (!Attr.empty())
+      O << Attr << ",";
+    O << " label =\"" << DOT::EscapeString(Label) << "\"];\n";
+  }
+
+  /// emitEdge - Output an edge from a simple node into the graph...
+  void emitEdge(void *SrcNodeID, int SrcNodePort,
+                void *DestNodeID, int DestNodePort, const std::string &Attrs) {
+    O << "\tNode" << SrcNodeID;
+    if (SrcNodePort >= 0)
+      O << ":g" << SrcNodePort;
+    O << " -> Node" << (void*)DestNodeID;
+    if (DestNodePort >= 0)
+      O << ":g" << DestNodePort;    
+
+    if (!Attrs.empty())
+      O << "[" << Attrs << "]";
+    O << ";\n";
+  }
 };
 
 template<typename GraphType>
index 7783b4680876fb57055ef77f802d57506125cdf2..60cae2e50020c4cc77d91abfde63a40cd6849042 100644 (file)
@@ -124,8 +124,7 @@ public:
 
   void writeEdge(NodeType *Node, unsigned edgeidx, child_iterator EI) {
     if (NodeType *TargetNode = *EI) {
-      O << "\tNode" << (void*)Node << ":g" << edgeidx << " -> Node"
-        << (void*)TargetNode;
+      int DestPort = -1;
       if (DOTTraits::edgeTargetsEdgeSource(Node, EI)) {
         child_iterator TargetIt = DOTTraits::getEdgeTarget(Node, EI);
 
@@ -133,15 +132,37 @@ public:
         unsigned Offset = std::distance(GTraits::child_begin(TargetNode),
                                         TargetIt);
         if (Offset > 64) Offset = 64;  // Targetting the truncated part?
-        O << ":g" << Offset;        
+        DestPort = (int)Offset;
       }
-      
-      std::string EdgeAttributes = DOTTraits::getEdgeAttributes(Node, EI);
-      if (!EdgeAttributes.empty())
-        O << "[" << EdgeAttributes << "]";
-      O << ";\n";
+
+      emitEdge((void *)Node, edgeidx, (void*)TargetNode, DestPort,
+               DOTTraits::getEdgeAttributes(Node, EI));
     }
   }
+
+  /// emitSimpleNode - Outputs a simple (non-record) node
+  void emitSimpleNode(void *ID, const std::string &Attr,
+                      const std::string &Label) {
+    O << "\tNode" << ID << "[ ";
+    if (!Attr.empty())
+      O << Attr << ",";
+    O << " label =\"" << DOT::EscapeString(Label) << "\"];\n";
+  }
+
+  /// emitEdge - Output an edge from a simple node into the graph...
+  void emitEdge(void *SrcNodeID, int SrcNodePort,
+                void *DestNodeID, int DestNodePort, const std::string &Attrs) {
+    O << "\tNode" << SrcNodeID;
+    if (SrcNodePort >= 0)
+      O << ":g" << SrcNodePort;
+    O << " -> Node" << (void*)DestNodeID;
+    if (DestNodePort >= 0)
+      O << ":g" << DestNodePort;    
+
+    if (!Attrs.empty())
+      O << "[" << Attrs << "]";
+    O << ";\n";
+  }
 };
 
 template<typename GraphType>