1 //===-- llvm/Support/DotGraphTraits.h - Customize .dot output ---*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines a template class that can be used to customize dot output
11 // graphs generated by the GraphWriter.h file. The default implementation of
12 // this file will produce a simple, but not very polished graph. By
13 // specializing this template, lots of customization opportunities are possible.
15 //===----------------------------------------------------------------------===//
17 #ifndef LLVM_SUPPORT_DOTGRAPHTRAITS_H
18 #define LLVM_SUPPORT_DOTGRAPHTRAITS_H
24 /// DefaultDOTGraphTraits - This class provides the default implementations of
25 /// all of the DOTGraphTraits methods. If a specialization does not need to
26 /// override all methods here it should inherit so that it can get the default
29 struct DefaultDOTGraphTraits {
30 /// getGraphName - Return the label for the graph as a whole. Printed at the
33 static std::string getGraphName(const void *Graph) { return ""; }
35 /// getGraphProperties - Return any custom properties that should be included
36 /// in the top level graph structure for dot.
38 static std::string getGraphProperties(const void *Graph) {
42 /// renderGraphFromBottomUp - If this function returns true, the graph is
43 /// emitted bottom-up instead of top-down. This requires graphviz 2.0 to work
45 static bool renderGraphFromBottomUp() {
49 /// getNodeLabel - Given a node and a pointer to the top level graph, return
50 /// the label to print in the node.
51 static std::string getNodeLabel(const void *Node, const void *Graph) {
55 /// If you want to specify custom node attributes, this is the place to do so
57 static std::string getNodeAttributes(const void *Node) { return ""; }
59 /// If you want to override the dot attributes printed for a particular edge,
60 /// override this method.
61 template<typename EdgeIter>
62 static std::string getEdgeAttributes(const void *Node, EdgeIter EI) {
66 /// getEdgeSourceLabel - If you want to label the edge source itself,
67 /// implement this method.
68 template<typename EdgeIter>
69 static std::string getEdgeSourceLabel(const void *Node, EdgeIter I) {
73 /// edgeTargetsEdgeSource - This method returns true if this outgoing edge
74 /// should actually target another edge source, not a node. If this method is
75 /// implemented, getEdgeTarget should be implemented.
76 template<typename EdgeIter>
77 static bool edgeTargetsEdgeSource(const void *Node, EdgeIter I) {
81 /// getEdgeTarget - If edgeTargetsEdgeSource returns true, this method is
82 /// called to determine which outgoing edge of Node is the target of this
84 template<typename EdgeIter>
85 static EdgeIter getEdgeTarget(const void *Node, EdgeIter I) {
89 /// addCustomGraphFeatures - If a graph is made up of more than just
90 /// straight-forward nodes and edges, this is the place to put all of the
91 /// custom stuff necessary. The GraphWriter object, instantiated with your
92 /// GraphType is passed in as an argument. You may call arbitrary methods on
93 /// it to add things to the output graph.
95 template<typename GraphWriter>
96 static void addCustomGraphFeatures(const void *Graph, GraphWriter &GW) {}
100 /// DOTGraphTraits - Template class that can be specialized to customize how
101 /// graphs are converted to 'dot' graphs. When specializing, you may inherit
102 /// from DefaultDOTGraphTraits if you don't need to override everything.
104 template <typename Ty>
105 struct DOTGraphTraits : public DefaultDOTGraphTraits {};
107 } // End llvm namespace