Chris Lattner | 4848689 | 2003-09-30 18:37:50 +0000 | [diff] [blame] | 1 | //===-- Support/DotGraphTraits.h - Customize .dot output --------*- C++ -*-===// |
John Criswell | b2109ce | 2003-10-20 19:46:57 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by the LLVM research group and is distributed under |
| 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
Chris Lattner | 95b923d | 2002-10-07 18:37:10 +0000 | [diff] [blame] | 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 SUPPORT_DOTGRAPHTRAITS_H |
| 18 | #define SUPPORT_DOTGRAPHTRAITS_H |
| 19 | |
| 20 | #include <string> |
| 21 | |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 22 | namespace llvm { |
| 23 | |
Chris Lattner | 95b923d | 2002-10-07 18:37:10 +0000 | [diff] [blame] | 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 | /// getGraphName - Return the label for the graph as a whole. Printed at the |
| 31 | /// top of the graph. |
| 32 | /// |
Chris Lattner | a16adb7 | 2002-10-17 00:16:39 +0000 | [diff] [blame] | 33 | static std::string getGraphName(const void *Graph) { return ""; } |
Chris Lattner | 95b923d | 2002-10-07 18:37:10 +0000 | [diff] [blame] | 34 | |
Chris Lattner | e981283 | 2002-10-10 22:29:10 +0000 | [diff] [blame] | 35 | /// getGraphProperties - Return any custom properties that should be included |
| 36 | /// in the top level graph structure for dot. By default, we resize the graph |
| 37 | /// to fit on a letter size page. |
| 38 | /// |
Chris Lattner | a16adb7 | 2002-10-17 00:16:39 +0000 | [diff] [blame] | 39 | static std::string getGraphProperties(const void *Graph) { |
Chris Lattner | e981283 | 2002-10-10 22:29:10 +0000 | [diff] [blame] | 40 | return "\tsize=\"7.5,10\";\n"; // Size to fit on a page |
| 41 | } |
| 42 | |
Chris Lattner | 95b923d | 2002-10-07 18:37:10 +0000 | [diff] [blame] | 43 | /// getNodeLabel - Given a node and a pointer to the top level graph, return |
| 44 | /// the label to print in the node. |
Chris Lattner | a16adb7 | 2002-10-17 00:16:39 +0000 | [diff] [blame] | 45 | static std::string getNodeLabel(const void *Node, const void *Graph) { |
| 46 | return ""; |
| 47 | } |
Chris Lattner | 95b923d | 2002-10-07 18:37:10 +0000 | [diff] [blame] | 48 | |
| 49 | /// If you want to specify custom node attributes, this is the place to do so |
| 50 | /// |
Chris Lattner | a16adb7 | 2002-10-17 00:16:39 +0000 | [diff] [blame] | 51 | static std::string getNodeAttributes(const void *Node) { return ""; } |
Chris Lattner | 95b923d | 2002-10-07 18:37:10 +0000 | [diff] [blame] | 52 | |
| 53 | /// If you want to override the dot attributes printed for a particular edge, |
| 54 | /// override this method. |
| 55 | template<typename EdgeIter> |
Chris Lattner | a16adb7 | 2002-10-17 00:16:39 +0000 | [diff] [blame] | 56 | static std::string getEdgeAttributes(const void *Node, EdgeIter EI) { |
| 57 | return ""; |
| 58 | } |
Chris Lattner | 95b923d | 2002-10-07 18:37:10 +0000 | [diff] [blame] | 59 | |
| 60 | /// getEdgeSourceLabel - If you want to label the edge source itself, |
| 61 | /// implement this method. |
| 62 | template<typename EdgeIter> |
Chris Lattner | a16adb7 | 2002-10-17 00:16:39 +0000 | [diff] [blame] | 63 | static std::string getEdgeSourceLabel(const void *Node, EdgeIter I) { |
| 64 | return ""; |
| 65 | } |
Chris Lattner | 95b923d | 2002-10-07 18:37:10 +0000 | [diff] [blame] | 66 | |
| 67 | /// edgeTargetsEdgeSource - This method returns true if this outgoing edge |
| 68 | /// should actually target another edge source, not a node. If this method is |
| 69 | /// implemented, getEdgeTarget should be implemented. |
| 70 | template<typename EdgeIter> |
Chris Lattner | a16adb7 | 2002-10-17 00:16:39 +0000 | [diff] [blame] | 71 | static bool edgeTargetsEdgeSource(const void *Node, EdgeIter I) { |
| 72 | return false; |
| 73 | } |
Chris Lattner | 95b923d | 2002-10-07 18:37:10 +0000 | [diff] [blame] | 74 | |
| 75 | /// getEdgeTarget - If edgeTargetsEdgeSource returns true, this method is |
| 76 | /// called to determine which outgoing edge of Node is the target of this |
| 77 | /// edge. |
| 78 | template<typename EdgeIter> |
Chris Lattner | a16adb7 | 2002-10-17 00:16:39 +0000 | [diff] [blame] | 79 | static EdgeIter getEdgeTarget(const void *Node, EdgeIter I) { |
| 80 | return I; |
| 81 | } |
Chris Lattner | 834a9d1 | 2002-10-16 01:44:59 +0000 | [diff] [blame] | 82 | |
| 83 | /// addCustomGraphFeatures - If a graph is made up of more than just |
| 84 | /// straight-forward nodes and edges, this is the place to put all of the |
Misha Brukman | 5560c9d | 2003-08-18 14:43:39 +0000 | [diff] [blame] | 85 | /// custom stuff necessary. The GraphWriter object, instantiated with your |
Chris Lattner | 834a9d1 | 2002-10-16 01:44:59 +0000 | [diff] [blame] | 86 | /// GraphType is passed in as an argument. You may call arbitrary methods on |
| 87 | /// it to add things to the output graph. |
| 88 | /// |
| 89 | template<typename GraphWriter> |
Chris Lattner | a16adb7 | 2002-10-17 00:16:39 +0000 | [diff] [blame] | 90 | static void addCustomGraphFeatures(const void *Graph, GraphWriter &GW) {} |
Chris Lattner | 95b923d | 2002-10-07 18:37:10 +0000 | [diff] [blame] | 91 | }; |
| 92 | |
| 93 | |
| 94 | /// DOTGraphTraits - Template class that can be specialized to customize how |
| 95 | /// graphs are converted to 'dot' graphs. When specializing, you may inherit |
| 96 | /// from DefaultDOTGraphTraits if you don't need to override everything. |
| 97 | /// |
| 98 | template <typename Ty> |
| 99 | class DOTGraphTraits : public DefaultDOTGraphTraits {}; |
| 100 | |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 101 | } // End llvm namespace |
| 102 | |
Chris Lattner | 95b923d | 2002-10-07 18:37:10 +0000 | [diff] [blame] | 103 | #endif |