DOTGraphTraits.h revision 193323
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 { 30193323Sed /// getGraphName - Return the label for the graph as a whole. Printed at the 31193323Sed /// top of the graph. 32193323Sed /// 33193323Sed template<typename GraphType> 34193323Sed static std::string getGraphName(const GraphType& Graph) { return ""; } 35193323Sed 36193323Sed /// getGraphProperties - Return any custom properties that should be included 37193323Sed /// in the top level graph structure for dot. 38193323Sed /// 39193323Sed template<typename GraphType> 40193323Sed static std::string getGraphProperties(const GraphType& Graph) { 41193323Sed return ""; 42193323Sed } 43193323Sed 44193323Sed /// renderGraphFromBottomUp - If this function returns true, the graph is 45193323Sed /// emitted bottom-up instead of top-down. This requires graphviz 2.0 to work 46193323Sed /// though. 47193323Sed static bool renderGraphFromBottomUp() { 48193323Sed return false; 49193323Sed } 50193323Sed 51193323Sed /// getNodeLabel - Given a node and a pointer to the top level graph, return 52193323Sed /// the label to print in the node. 53193323Sed template<typename GraphType> 54193323Sed static std::string getNodeLabel(const void *Node, const GraphType& Graph) { 55193323Sed return ""; 56193323Sed } 57193323Sed 58193323Sed /// hasNodeAddressLabel - If this method returns true, the address of the node 59193323Sed /// is added to the label of the node. 60193323Sed template<typename GraphType> 61193323Sed static bool hasNodeAddressLabel(const void *Node, const GraphType& Graph) { 62193323Sed return false; 63193323Sed } 64193323Sed 65193323Sed /// If you want to specify custom node attributes, this is the place to do so 66193323Sed /// 67193323Sed template<typename GraphType> 68193323Sed static std::string getNodeAttributes(const void *Node, 69193323Sed const GraphType& Graph) { 70193323Sed return ""; 71193323Sed } 72193323Sed 73193323Sed /// If you want to override the dot attributes printed for a particular edge, 74193323Sed /// override this method. 75193323Sed template<typename EdgeIter> 76193323Sed static std::string getEdgeAttributes(const void *Node, EdgeIter EI) { 77193323Sed return ""; 78193323Sed } 79193323Sed 80193323Sed /// getEdgeSourceLabel - If you want to label the edge source itself, 81193323Sed /// implement this method. 82193323Sed template<typename EdgeIter> 83193323Sed static std::string getEdgeSourceLabel(const void *Node, EdgeIter I) { 84193323Sed return ""; 85193323Sed } 86193323Sed 87193323Sed /// edgeTargetsEdgeSource - This method returns true if this outgoing edge 88193323Sed /// should actually target another edge source, not a node. If this method is 89193323Sed /// implemented, getEdgeTarget should be implemented. 90193323Sed template<typename EdgeIter> 91193323Sed static bool edgeTargetsEdgeSource(const void *Node, EdgeIter I) { 92193323Sed return false; 93193323Sed } 94193323Sed 95193323Sed /// getEdgeTarget - If edgeTargetsEdgeSource returns true, this method is 96193323Sed /// called to determine which outgoing edge of Node is the target of this 97193323Sed /// edge. 98193323Sed template<typename EdgeIter> 99193323Sed static EdgeIter getEdgeTarget(const void *Node, EdgeIter I) { 100193323Sed return I; 101193323Sed } 102193323Sed 103193323Sed /// hasEdgeDestLabels - If this function returns true, the graph is able 104193323Sed /// to provide labels for edge destinations. 105193323Sed static bool hasEdgeDestLabels() { 106193323Sed return false; 107193323Sed } 108193323Sed 109193323Sed /// numEdgeDestLabels - If hasEdgeDestLabels, this function returns the 110193323Sed /// number of incoming edge labels the given node has. 111193323Sed static unsigned numEdgeDestLabels(const void *Node) { 112193323Sed return 0; 113193323Sed } 114193323Sed 115193323Sed /// getEdgeDestLabel - If hasEdgeDestLabels, this function returns the 116193323Sed /// incoming edge label with the given index in the given node. 117193323Sed static std::string getEdgeDestLabel(const void *Node, unsigned i) { 118193323Sed return ""; 119193323Sed } 120193323Sed 121193323Sed /// addCustomGraphFeatures - If a graph is made up of more than just 122193323Sed /// straight-forward nodes and edges, this is the place to put all of the 123193323Sed /// custom stuff necessary. The GraphWriter object, instantiated with your 124193323Sed /// GraphType is passed in as an argument. You may call arbitrary methods on 125193323Sed /// it to add things to the output graph. 126193323Sed /// 127193323Sed template<typename GraphType, typename GraphWriter> 128193323Sed static void addCustomGraphFeatures(const GraphType& Graph, GraphWriter &GW) {} 129193323Sed}; 130193323Sed 131193323Sed 132193323Sed/// DOTGraphTraits - Template class that can be specialized to customize how 133193323Sed/// graphs are converted to 'dot' graphs. When specializing, you may inherit 134193323Sed/// from DefaultDOTGraphTraits if you don't need to override everything. 135193323Sed/// 136193323Sedtemplate <typename Ty> 137193323Sedstruct DOTGraphTraits : public DefaultDOTGraphTraits {}; 138193323Sed 139193323Sed} // End llvm namespace 140193323Sed 141193323Sed#endif 142