|
|
|||
File indexing completed on 2026-05-10 08:44:29
0001 //===-- llvm/Support/DOTGraphTraits.h - Customize .dot output ---*- C++ -*-===// 0002 // 0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 0004 // See https://llvm.org/LICENSE.txt for license information. 0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 0006 // 0007 //===----------------------------------------------------------------------===// 0008 // 0009 // This file defines a template class that can be used to customize dot output 0010 // graphs generated by the GraphWriter.h file. The default implementation of 0011 // this file will produce a simple, but not very polished graph. By 0012 // specializing this template, lots of customization opportunities are possible. 0013 // 0014 //===----------------------------------------------------------------------===// 0015 0016 #ifndef LLVM_SUPPORT_DOTGRAPHTRAITS_H 0017 #define LLVM_SUPPORT_DOTGRAPHTRAITS_H 0018 0019 #include <string> 0020 0021 namespace llvm { 0022 0023 /// DefaultDOTGraphTraits - This class provides the default implementations of 0024 /// all of the DOTGraphTraits methods. If a specialization does not need to 0025 /// override all methods here it should inherit so that it can get the default 0026 /// implementations. 0027 /// 0028 struct DefaultDOTGraphTraits { 0029 private: 0030 bool IsSimple; 0031 0032 protected: 0033 bool isSimple() { 0034 return IsSimple; 0035 } 0036 0037 public: 0038 explicit DefaultDOTGraphTraits(bool simple=false) : IsSimple (simple) {} 0039 0040 /// getGraphName - Return the label for the graph as a whole. Printed at the 0041 /// top of the graph. 0042 /// 0043 template<typename GraphType> 0044 static std::string getGraphName(const GraphType &) { return ""; } 0045 0046 /// getGraphProperties - Return any custom properties that should be included 0047 /// in the top level graph structure for dot. 0048 /// 0049 template<typename GraphType> 0050 static std::string getGraphProperties(const GraphType &) { 0051 return ""; 0052 } 0053 0054 /// renderGraphFromBottomUp - If this function returns true, the graph is 0055 /// emitted bottom-up instead of top-down. This requires graphviz 2.0 to work 0056 /// though. 0057 static bool renderGraphFromBottomUp() { 0058 return false; 0059 } 0060 0061 /// isNodeHidden - If the function returns true, the given node is not 0062 /// displayed in the graph. 0063 template <typename GraphType> 0064 static bool isNodeHidden(const void *, const GraphType &) { 0065 return false; 0066 } 0067 0068 // renderNodesUsingHTML - If the function returns true, nodes will be 0069 // rendered using HTML-like labels which allows colors, etc in the nodes 0070 // and the edge source labels. 0071 static bool renderNodesUsingHTML() { return false; } 0072 0073 /// getNodeLabel - Given a node and a pointer to the top level graph, return 0074 /// the label to print in the node. 0075 template<typename GraphType> 0076 std::string getNodeLabel(const void *, const GraphType &) { 0077 return ""; 0078 } 0079 0080 // getNodeIdentifierLabel - Returns a string representing the 0081 // address or other unique identifier of the node. (Only used if 0082 // non-empty.) 0083 template <typename GraphType> 0084 static std::string getNodeIdentifierLabel(const void *, const GraphType &) { 0085 return ""; 0086 } 0087 0088 template<typename GraphType> 0089 static std::string getNodeDescription(const void *, const GraphType &) { 0090 return ""; 0091 } 0092 0093 /// If you want to specify custom node attributes, this is the place to do so 0094 /// 0095 template<typename GraphType> 0096 static std::string getNodeAttributes(const void *, 0097 const GraphType &) { 0098 return ""; 0099 } 0100 0101 /// If you want to override the dot attributes printed for a particular edge, 0102 /// override this method. 0103 template<typename EdgeIter, typename GraphType> 0104 static std::string getEdgeAttributes(const void *, EdgeIter, 0105 const GraphType &) { 0106 return ""; 0107 } 0108 0109 /// getEdgeSourceLabel - If you want to label the edge source itself, 0110 /// implement this method. 0111 template<typename EdgeIter> 0112 static std::string getEdgeSourceLabel(const void *, EdgeIter) { 0113 return ""; 0114 } 0115 0116 /// edgeTargetsEdgeSource - This method returns true if this outgoing edge 0117 /// should actually target another edge source, not a node. If this method is 0118 /// implemented, getEdgeTarget should be implemented. 0119 template<typename EdgeIter> 0120 static bool edgeTargetsEdgeSource(const void *, EdgeIter) { 0121 return false; 0122 } 0123 0124 /// getEdgeTarget - If edgeTargetsEdgeSource returns true, this method is 0125 /// called to determine which outgoing edge of Node is the target of this 0126 /// edge. 0127 template<typename EdgeIter> 0128 static EdgeIter getEdgeTarget(const void *, EdgeIter I) { 0129 return I; 0130 } 0131 0132 /// hasEdgeDestLabels - If this function returns true, the graph is able 0133 /// to provide labels for edge destinations. 0134 static bool hasEdgeDestLabels() { 0135 return false; 0136 } 0137 0138 /// numEdgeDestLabels - If hasEdgeDestLabels, this function returns the 0139 /// number of incoming edge labels the given node has. 0140 static unsigned numEdgeDestLabels(const void *) { 0141 return 0; 0142 } 0143 0144 /// getEdgeDestLabel - If hasEdgeDestLabels, this function returns the 0145 /// incoming edge label with the given index in the given node. 0146 static std::string getEdgeDestLabel(const void *, unsigned) { 0147 return ""; 0148 } 0149 0150 /// addCustomGraphFeatures - If a graph is made up of more than just 0151 /// straight-forward nodes and edges, this is the place to put all of the 0152 /// custom stuff necessary. The GraphWriter object, instantiated with your 0153 /// GraphType is passed in as an argument. You may call arbitrary methods on 0154 /// it to add things to the output graph. 0155 /// 0156 template<typename GraphType, typename GraphWriter> 0157 static void addCustomGraphFeatures(const GraphType &, GraphWriter &) {} 0158 }; 0159 0160 0161 /// DOTGraphTraits - Template class that can be specialized to customize how 0162 /// graphs are converted to 'dot' graphs. When specializing, you may inherit 0163 /// from DefaultDOTGraphTraits if you don't need to override everything. 0164 /// 0165 template <typename Ty> 0166 struct DOTGraphTraits : public DefaultDOTGraphTraits { 0167 DOTGraphTraits (bool simple=false) : DefaultDOTGraphTraits (simple) {} 0168 }; 0169 0170 } // End llvm namespace 0171 0172 #endif
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|