1 //===-- llvm/Support/DotGraphTraits.h - Customize .dot output ---*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 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. 14 // 15 //===----------------------------------------------------------------------===// 16 17 #ifndef LLVM_SUPPORT_DOTGRAPHTRAITS_H 18 #define LLVM_SUPPORT_DOTGRAPHTRAITS_H 19 20 #include <string> 21 22 namespace llvm { 23 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 27 /// implementations. 28 /// 29 struct DefaultDOTGraphTraits { 30 private: 31 bool IsSimple; 32 33 protected: isSimpleDefaultDOTGraphTraits34 bool isSimple() { 35 return IsSimple; 36 } 37 38 public: IsSimpleDefaultDOTGraphTraits39 explicit DefaultDOTGraphTraits(bool simple=false) : IsSimple (simple) {} 40 41 /// getGraphName - Return the label for the graph as a whole. Printed at the 42 /// top of the graph. 43 /// 44 template<typename GraphType> getGraphNameDefaultDOTGraphTraits45 static std::string getGraphName(const GraphType &) { return ""; } 46 47 /// getGraphProperties - Return any custom properties that should be included 48 /// in the top level graph structure for dot. 49 /// 50 template<typename GraphType> getGraphPropertiesDefaultDOTGraphTraits51 static std::string getGraphProperties(const GraphType &) { 52 return ""; 53 } 54 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 57 /// though. renderGraphFromBottomUpDefaultDOTGraphTraits58 static bool renderGraphFromBottomUp() { 59 return false; 60 } 61 62 /// isNodeHidden - If the function returns true, the given node is not 63 /// displayed in the graph. isNodeHiddenDefaultDOTGraphTraits64 static bool isNodeHidden(const void *) { 65 return false; 66 } 67 68 /// getNodeLabel - Given a node and a pointer to the top level graph, return 69 /// the label to print in the node. 70 template<typename GraphType> getNodeLabelDefaultDOTGraphTraits71 std::string getNodeLabel(const void *, const GraphType &) { 72 return ""; 73 } 74 75 /// hasNodeAddressLabel - If this method returns true, the address of the node 76 /// is added to the label of the node. 77 template<typename GraphType> hasNodeAddressLabelDefaultDOTGraphTraits78 static bool hasNodeAddressLabel(const void *, const GraphType &) { 79 return false; 80 } 81 82 template<typename GraphType> getNodeDescriptionDefaultDOTGraphTraits83 static std::string getNodeDescription(const void *, const GraphType &) { 84 return ""; 85 } 86 87 /// If you want to specify custom node attributes, this is the place to do so 88 /// 89 template<typename GraphType> getNodeAttributesDefaultDOTGraphTraits90 static std::string getNodeAttributes(const void *, 91 const GraphType &) { 92 return ""; 93 } 94 95 /// If you want to override the dot attributes printed for a particular edge, 96 /// override this method. 97 template<typename EdgeIter, typename GraphType> getEdgeAttributesDefaultDOTGraphTraits98 static std::string getEdgeAttributes(const void *, EdgeIter, 99 const GraphType &) { 100 return ""; 101 } 102 103 /// getEdgeSourceLabel - If you want to label the edge source itself, 104 /// implement this method. 105 template<typename EdgeIter> getEdgeSourceLabelDefaultDOTGraphTraits106 static std::string getEdgeSourceLabel(const void *, EdgeIter) { 107 return ""; 108 } 109 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> edgeTargetsEdgeSourceDefaultDOTGraphTraits114 static bool edgeTargetsEdgeSource(const void *, EdgeIter) { 115 return false; 116 } 117 118 /// getEdgeTarget - If edgeTargetsEdgeSource returns true, this method is 119 /// called to determine which outgoing edge of Node is the target of this 120 /// edge. 121 template<typename EdgeIter> getEdgeTargetDefaultDOTGraphTraits122 static EdgeIter getEdgeTarget(const void *, EdgeIter I) { 123 return I; 124 } 125 126 /// hasEdgeDestLabels - If this function returns true, the graph is able 127 /// to provide labels for edge destinations. hasEdgeDestLabelsDefaultDOTGraphTraits128 static bool hasEdgeDestLabels() { 129 return false; 130 } 131 132 /// numEdgeDestLabels - If hasEdgeDestLabels, this function returns the 133 /// number of incoming edge labels the given node has. numEdgeDestLabelsDefaultDOTGraphTraits134 static unsigned numEdgeDestLabels(const void *) { 135 return 0; 136 } 137 138 /// getEdgeDestLabel - If hasEdgeDestLabels, this function returns the 139 /// incoming edge label with the given index in the given node. getEdgeDestLabelDefaultDOTGraphTraits140 static std::string getEdgeDestLabel(const void *, unsigned) { 141 return ""; 142 } 143 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. 149 /// 150 template<typename GraphType, typename GraphWriter> addCustomGraphFeaturesDefaultDOTGraphTraits151 static void addCustomGraphFeatures(const GraphType &, GraphWriter &) {} 152 }; 153 154 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. 158 /// 159 template <typename Ty> 160 struct DOTGraphTraits : public DefaultDOTGraphTraits { DefaultDOTGraphTraitsDOTGraphTraits161 DOTGraphTraits (bool simple=false) : DefaultDOTGraphTraits (simple) {} 162 }; 163 164 } // End llvm namespace 165 166 #endif 167