LLVM API Documentation
00001 //===-- llvm/Support/DotGraphTraits.h - Customize .dot output ---*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file was developed by the LLVM research group and is distributed under 00006 // the University of Illinois Open Source License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file defines a template class that can be used to customize dot output 00011 // graphs generated by the GraphWriter.h file. The default implementation of 00012 // this file will produce a simple, but not very polished graph. By 00013 // specializing this template, lots of customization opportunities are possible. 00014 // 00015 //===----------------------------------------------------------------------===// 00016 00017 #ifndef LLVM_SUPPORT_DOTGRAPHTRAITS_H 00018 #define LLVM_SUPPORT_DOTGRAPHTRAITS_H 00019 00020 #include <string> 00021 00022 namespace llvm { 00023 00024 /// DefaultDOTGraphTraits - This class provides the default implementations of 00025 /// all of the DOTGraphTraits methods. If a specialization does not need to 00026 /// override all methods here it should inherit so that it can get the default 00027 /// implementations. 00028 /// 00029 struct DefaultDOTGraphTraits { 00030 /// getGraphName - Return the label for the graph as a whole. Printed at the 00031 /// top of the graph. 00032 /// 00033 static std::string getGraphName(const void *Graph) { return ""; } 00034 00035 /// getGraphProperties - Return any custom properties that should be included 00036 /// in the top level graph structure for dot. 00037 /// 00038 static std::string getGraphProperties(const void *Graph) { 00039 return ""; 00040 } 00041 00042 /// renderGraphFromBottomUp - If this function returns true, the graph is 00043 /// emitted bottom-up instead of top-down. This requires graphviz 2.0 to work 00044 /// though. 00045 static bool renderGraphFromBottomUp() { 00046 return false; 00047 } 00048 00049 /// getNodeLabel - Given a node and a pointer to the top level graph, return 00050 /// the label to print in the node. 00051 static std::string getNodeLabel(const void *Node, const void *Graph) { 00052 return ""; 00053 } 00054 00055 /// hasNodeAddressLabel - If this method returns true, the address of the node 00056 /// is added to the label of the node. 00057 static bool hasNodeAddressLabel(const void *Node, const void *Graph) { 00058 return false; 00059 } 00060 00061 /// If you want to specify custom node attributes, this is the place to do so 00062 /// 00063 static std::string getNodeAttributes(const void *Node) { return ""; } 00064 00065 /// If you want to override the dot attributes printed for a particular edge, 00066 /// override this method. 00067 template<typename EdgeIter> 00068 static std::string getEdgeAttributes(const void *Node, EdgeIter EI) { 00069 return ""; 00070 } 00071 00072 /// getEdgeSourceLabel - If you want to label the edge source itself, 00073 /// implement this method. 00074 template<typename EdgeIter> 00075 static std::string getEdgeSourceLabel(const void *Node, EdgeIter I) { 00076 return ""; 00077 } 00078 00079 /// edgeTargetsEdgeSource - This method returns true if this outgoing edge 00080 /// should actually target another edge source, not a node. If this method is 00081 /// implemented, getEdgeTarget should be implemented. 00082 template<typename EdgeIter> 00083 static bool edgeTargetsEdgeSource(const void *Node, EdgeIter I) { 00084 return false; 00085 } 00086 00087 /// getEdgeTarget - If edgeTargetsEdgeSource returns true, this method is 00088 /// called to determine which outgoing edge of Node is the target of this 00089 /// edge. 00090 template<typename EdgeIter> 00091 static EdgeIter getEdgeTarget(const void *Node, EdgeIter I) { 00092 return I; 00093 } 00094 00095 /// addCustomGraphFeatures - If a graph is made up of more than just 00096 /// straight-forward nodes and edges, this is the place to put all of the 00097 /// custom stuff necessary. The GraphWriter object, instantiated with your 00098 /// GraphType is passed in as an argument. You may call arbitrary methods on 00099 /// it to add things to the output graph. 00100 /// 00101 template<typename GraphWriter> 00102 static void addCustomGraphFeatures(const void *Graph, GraphWriter &GW) {} 00103 }; 00104 00105 00106 /// DOTGraphTraits - Template class that can be specialized to customize how 00107 /// graphs are converted to 'dot' graphs. When specializing, you may inherit 00108 /// from DefaultDOTGraphTraits if you don't need to override everything. 00109 /// 00110 template <typename Ty> 00111 struct DOTGraphTraits : public DefaultDOTGraphTraits {}; 00112 00113 } // End llvm namespace 00114 00115 #endif