1193323Sed//===-- llvm/Support/DotGraphTraits.h - Customize .dot output ---*- C++ -*-===// 2193323Sed// 3193323Sed// The LLVM Compiler Infrastructure 4193323Sed// 5193323Sed// This file is distributed under the University of Illinois Open Source 6193323Sed// License. See LICENSE.TXT for details. 7193323Sed// 8193323Sed//===----------------------------------------------------------------------===// 9193323Sed// 10193323Sed// This file defines a template class that can be used to customize dot output 11193323Sed// graphs generated by the GraphWriter.h file. The default implementation of 12193323Sed// this file will produce a simple, but not very polished graph. By 13193323Sed// specializing this template, lots of customization opportunities are possible. 14193323Sed// 15193323Sed//===----------------------------------------------------------------------===// 16193323Sed 17193323Sed#ifndef LLVM_SUPPORT_DOTGRAPHTRAITS_H 18193323Sed#define LLVM_SUPPORT_DOTGRAPHTRAITS_H 19193323Sed 20193323Sed#include <string> 21193323Sed 22193323Sednamespace llvm { 23193323Sed 24193323Sed/// DefaultDOTGraphTraits - This class provides the default implementations of 25193323Sed/// all of the DOTGraphTraits methods. If a specialization does not need to 26193323Sed/// override all methods here it should inherit so that it can get the default 27193323Sed/// implementations. 28193323Sed/// 29193323Sedstruct DefaultDOTGraphTraits { 30199989Srdivackyprivate: 31199989Srdivacky bool IsSimple; 32199989Srdivacky 33199989Srdivackyprotected: 34199989Srdivacky bool isSimple() { 35199989Srdivacky return IsSimple; 36199989Srdivacky } 37199989Srdivacky 38199989Srdivackypublic: 39208599Srdivacky explicit DefaultDOTGraphTraits(bool simple=false) : IsSimple (simple) {} 40199989Srdivacky 41193323Sed /// getGraphName - Return the label for the graph as a whole. Printed at the 42193323Sed /// top of the graph. 43193323Sed /// 44193323Sed template<typename GraphType> 45234353Sdim static std::string getGraphName(const GraphType &) { return ""; } 46193323Sed 47193323Sed /// getGraphProperties - Return any custom properties that should be included 48193323Sed /// in the top level graph structure for dot. 49193323Sed /// 50193323Sed template<typename GraphType> 51234353Sdim static std::string getGraphProperties(const GraphType &) { 52193323Sed return ""; 53193323Sed } 54193323Sed 55193323Sed /// renderGraphFromBottomUp - If this function returns true, the graph is 56193323Sed /// emitted bottom-up instead of top-down. This requires graphviz 2.0 to work 57193323Sed /// though. 58193323Sed static bool renderGraphFromBottomUp() { 59193323Sed return false; 60193323Sed } 61193323Sed 62208599Srdivacky /// isNodeHidden - If the function returns true, the given node is not 63208599Srdivacky /// displayed in the graph. 64234353Sdim static bool isNodeHidden(const void *) { 65208599Srdivacky return false; 66208599Srdivacky } 67208599Srdivacky 68193323Sed /// getNodeLabel - Given a node and a pointer to the top level graph, return 69193323Sed /// the label to print in the node. 70193323Sed template<typename GraphType> 71234353Sdim std::string getNodeLabel(const void *, const GraphType &) { 72193323Sed return ""; 73193323Sed } 74193323Sed 75193323Sed /// hasNodeAddressLabel - If this method returns true, the address of the node 76193323Sed /// is added to the label of the node. 77193323Sed template<typename GraphType> 78234353Sdim static bool hasNodeAddressLabel(const void *, const GraphType &) { 79193323Sed return false; 80193323Sed } 81193323Sed 82249423Sdim template<typename GraphType> 83249423Sdim static std::string getNodeDescription(const void *, const GraphType &) { 84249423Sdim return ""; 85249423Sdim } 86249423Sdim 87193323Sed /// If you want to specify custom node attributes, this is the place to do so 88193323Sed /// 89193323Sed template<typename GraphType> 90234353Sdim static std::string getNodeAttributes(const void *, 91234353Sdim const GraphType &) { 92193323Sed return ""; 93193323Sed } 94193323Sed 95193323Sed /// If you want to override the dot attributes printed for a particular edge, 96193323Sed /// override this method. 97221345Sdim template<typename EdgeIter, typename GraphType> 98234353Sdim static std::string getEdgeAttributes(const void *, EdgeIter, 99234353Sdim const GraphType &) { 100193323Sed return ""; 101193323Sed } 102193323Sed 103193323Sed /// getEdgeSourceLabel - If you want to label the edge source itself, 104193323Sed /// implement this method. 105193323Sed template<typename EdgeIter> 106234353Sdim static std::string getEdgeSourceLabel(const void *, EdgeIter) { 107193323Sed return ""; 108193323Sed } 109193323Sed 110193323Sed /// edgeTargetsEdgeSource - This method returns true if this outgoing edge 111193323Sed /// should actually target another edge source, not a node. If this method is 112193323Sed /// implemented, getEdgeTarget should be implemented. 113193323Sed template<typename EdgeIter> 114234353Sdim static bool edgeTargetsEdgeSource(const void *, EdgeIter) { 115193323Sed return false; 116193323Sed } 117193323Sed 118193323Sed /// getEdgeTarget - If edgeTargetsEdgeSource returns true, this method is 119193323Sed /// called to determine which outgoing edge of Node is the target of this 120193323Sed /// edge. 121193323Sed template<typename EdgeIter> 122234353Sdim static EdgeIter getEdgeTarget(const void *, EdgeIter I) { 123193323Sed return I; 124193323Sed } 125193323Sed 126193323Sed /// hasEdgeDestLabels - If this function returns true, the graph is able 127193323Sed /// to provide labels for edge destinations. 128193323Sed static bool hasEdgeDestLabels() { 129193323Sed return false; 130193323Sed } 131193323Sed 132193323Sed /// numEdgeDestLabels - If hasEdgeDestLabels, this function returns the 133193323Sed /// number of incoming edge labels the given node has. 134234353Sdim static unsigned numEdgeDestLabels(const void *) { 135193323Sed return 0; 136193323Sed } 137193323Sed 138193323Sed /// getEdgeDestLabel - If hasEdgeDestLabels, this function returns the 139193323Sed /// incoming edge label with the given index in the given node. 140234353Sdim static std::string getEdgeDestLabel(const void *, unsigned) { 141193323Sed return ""; 142193323Sed } 143193323Sed 144193323Sed /// addCustomGraphFeatures - If a graph is made up of more than just 145193323Sed /// straight-forward nodes and edges, this is the place to put all of the 146193323Sed /// custom stuff necessary. The GraphWriter object, instantiated with your 147193323Sed /// GraphType is passed in as an argument. You may call arbitrary methods on 148193323Sed /// it to add things to the output graph. 149193323Sed /// 150193323Sed template<typename GraphType, typename GraphWriter> 151234353Sdim static void addCustomGraphFeatures(const GraphType &, GraphWriter &) {} 152193323Sed}; 153193323Sed 154193323Sed 155193323Sed/// DOTGraphTraits - Template class that can be specialized to customize how 156193323Sed/// graphs are converted to 'dot' graphs. When specializing, you may inherit 157193323Sed/// from DefaultDOTGraphTraits if you don't need to override everything. 158193323Sed/// 159193323Sedtemplate <typename Ty> 160199989Srdivackystruct DOTGraphTraits : public DefaultDOTGraphTraits { 161199989Srdivacky DOTGraphTraits (bool simple=false) : DefaultDOTGraphTraits (simple) {} 162199989Srdivacky}; 163193323Sed 164193323Sed} // End llvm namespace 165193323Sed 166193323Sed#endif 167