1 //===-- llvm/Support/DotGraphTraits.h - Customize .dot output ---*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // 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 {
39 DefaultDOTGraphTraits (bool simple=false) : IsSimple (simple) {}
41 /// getGraphName - Return the label for the graph as a whole. Printed at the
44 template<typename GraphType>
45 static std::string getGraphName(const GraphType& Graph) { return ""; }
47 /// getGraphProperties - Return any custom properties that should be included
48 /// in the top level graph structure for dot.
50 template<typename GraphType>
51 static std::string getGraphProperties(const GraphType& Graph) {
55 /// renderGraphFromBottomUp - If this function returns true, the graph is
56 /// emitted bottom-up instead of top-down. This requires graphviz 2.0 to work
58 static bool renderGraphFromBottomUp() {
62 /// getNodeLabel - Given a node and a pointer to the top level graph, return
63 /// the label to print in the node.
64 template<typename GraphType>
65 static std::string getNodeLabel(const void *Node,
66 const GraphType& Graph, bool ShortNames) {
70 /// hasNodeAddressLabel - If this method returns true, the address of the node
71 /// is added to the label of the node.
72 template<typename GraphType>
73 static bool hasNodeAddressLabel(const void *Node, const GraphType& Graph) {
77 /// If you want to specify custom node attributes, this is the place to do so
79 template<typename GraphType>
80 static std::string getNodeAttributes(const void *Node,
81 const GraphType& Graph) {
85 /// If you want to override the dot attributes printed for a particular edge,
86 /// override this method.
87 template<typename EdgeIter>
88 static std::string getEdgeAttributes(const void *Node, EdgeIter EI) {
92 /// getEdgeSourceLabel - If you want to label the edge source itself,
93 /// implement this method.
94 template<typename EdgeIter>
95 static std::string getEdgeSourceLabel(const void *Node, EdgeIter I) {
99 /// edgeTargetsEdgeSource - This method returns true if this outgoing edge
100 /// should actually target another edge source, not a node. If this method is
101 /// implemented, getEdgeTarget should be implemented.
102 template<typename EdgeIter>
103 static bool edgeTargetsEdgeSource(const void *Node, EdgeIter I) {
107 /// getEdgeTarget - If edgeTargetsEdgeSource returns true, this method is
108 /// called to determine which outgoing edge of Node is the target of this
110 template<typename EdgeIter>
111 static EdgeIter getEdgeTarget(const void *Node, EdgeIter I) {
115 /// hasEdgeDestLabels - If this function returns true, the graph is able
116 /// to provide labels for edge destinations.
117 static bool hasEdgeDestLabels() {
121 /// numEdgeDestLabels - If hasEdgeDestLabels, this function returns the
122 /// number of incoming edge labels the given node has.
123 static unsigned numEdgeDestLabels(const void *Node) {
127 /// getEdgeDestLabel - If hasEdgeDestLabels, this function returns the
128 /// incoming edge label with the given index in the given node.
129 static std::string getEdgeDestLabel(const void *Node, unsigned i) {
133 /// addCustomGraphFeatures - If a graph is made up of more than just
134 /// straight-forward nodes and edges, this is the place to put all of the
135 /// custom stuff necessary. The GraphWriter object, instantiated with your
136 /// GraphType is passed in as an argument. You may call arbitrary methods on
137 /// it to add things to the output graph.
139 template<typename GraphType, typename GraphWriter>
140 static void addCustomGraphFeatures(const GraphType& Graph, GraphWriter &GW) {}
144 /// DOTGraphTraits - Template class that can be specialized to customize how
145 /// graphs are converted to 'dot' graphs. When specializing, you may inherit
146 /// from DefaultDOTGraphTraits if you don't need to override everything.
148 template <typename Ty>
149 struct DOTGraphTraits : public DefaultDOTGraphTraits {
150 DOTGraphTraits (bool simple=false) : DefaultDOTGraphTraits (simple) {}
153 } // End llvm namespace