1 //===-- llvm/Support/DOTGraphTraits.h - Customize .dot output ---*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file defines a template class that can be used to customize dot output
10 // graphs generated by the GraphWriter.h file. The default implementation of
11 // this file will produce a simple, but not very polished graph. By
12 // specializing this template, lots of customization opportunities are possible.
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_SUPPORT_DOTGRAPHTRAITS_H
17 #define LLVM_SUPPORT_DOTGRAPHTRAITS_H
23 /// DefaultDOTGraphTraits - This class provides the default implementations of
24 /// all of the DOTGraphTraits methods. If a specialization does not need to
25 /// override all methods here it should inherit so that it can get the default
28 struct DefaultDOTGraphTraits
{
38 explicit DefaultDOTGraphTraits(bool simple
=false) : IsSimple (simple
) {}
40 /// getGraphName - Return the label for the graph as a whole. Printed at the
43 template<typename GraphType
>
44 static std::string
getGraphName(const GraphType
&) { return ""; }
46 /// getGraphProperties - Return any custom properties that should be included
47 /// in the top level graph structure for dot.
49 template<typename GraphType
>
50 static std::string
getGraphProperties(const GraphType
&) {
54 /// renderGraphFromBottomUp - If this function returns true, the graph is
55 /// emitted bottom-up instead of top-down. This requires graphviz 2.0 to work
57 static bool renderGraphFromBottomUp() {
61 /// isNodeHidden - If the function returns true, the given node is not
62 /// displayed in the graph.
63 static bool isNodeHidden(const void *) {
67 /// getNodeLabel - Given a node and a pointer to the top level graph, return
68 /// the label to print in the node.
69 template<typename GraphType
>
70 std::string
getNodeLabel(const void *, const GraphType
&) {
74 // getNodeIdentifierLabel - Returns a string representing the
75 // address or other unique identifier of the node. (Only used if
77 template <typename GraphType
>
78 static std::string
getNodeIdentifierLabel(const void *, const GraphType
&) {
82 template<typename GraphType
>
83 static std::string
getNodeDescription(const void *, const GraphType
&) {
87 /// If you want to specify custom node attributes, this is the place to do so
89 template<typename GraphType
>
90 static std::string
getNodeAttributes(const void *,
95 /// If you want to override the dot attributes printed for a particular edge,
96 /// override this method.
97 template<typename EdgeIter
, typename GraphType
>
98 static std::string
getEdgeAttributes(const void *, EdgeIter
,
103 /// getEdgeSourceLabel - If you want to label the edge source itself,
104 /// implement this method.
105 template<typename EdgeIter
>
106 static std::string
getEdgeSourceLabel(const void *, EdgeIter
) {
110 /// edgeTargetsEdgeSource - This method returns true if this outgoing edge
111 /// should actually target another edge source, not a node. If this method is
112 /// implemented, getEdgeTarget should be implemented.
113 template<typename EdgeIter
>
114 static bool edgeTargetsEdgeSource(const void *, EdgeIter
) {
118 /// getEdgeTarget - If edgeTargetsEdgeSource returns true, this method is
119 /// called to determine which outgoing edge of Node is the target of this
121 template<typename EdgeIter
>
122 static EdgeIter
getEdgeTarget(const void *, EdgeIter I
) {
126 /// hasEdgeDestLabels - If this function returns true, the graph is able
127 /// to provide labels for edge destinations.
128 static bool hasEdgeDestLabels() {
132 /// numEdgeDestLabels - If hasEdgeDestLabels, this function returns the
133 /// number of incoming edge labels the given node has.
134 static unsigned numEdgeDestLabels(const void *) {
138 /// getEdgeDestLabel - If hasEdgeDestLabels, this function returns the
139 /// incoming edge label with the given index in the given node.
140 static std::string
getEdgeDestLabel(const void *, unsigned) {
144 /// addCustomGraphFeatures - If a graph is made up of more than just
145 /// straight-forward nodes and edges, this is the place to put all of the
146 /// custom stuff necessary. The GraphWriter object, instantiated with your
147 /// GraphType is passed in as an argument. You may call arbitrary methods on
148 /// it to add things to the output graph.
150 template<typename GraphType
, typename GraphWriter
>
151 static void addCustomGraphFeatures(const GraphType
&, GraphWriter
&) {}
155 /// DOTGraphTraits - Template class that can be specialized to customize how
156 /// graphs are converted to 'dot' graphs. When specializing, you may inherit
157 /// from DefaultDOTGraphTraits if you don't need to override everything.
159 template <typename Ty
>
160 struct DOTGraphTraits
: public DefaultDOTGraphTraits
{
161 DOTGraphTraits (bool simple
=false) : DefaultDOTGraphTraits (simple
) {}
164 } // End llvm namespace