blob: 002a78ec4f8bc4872db8ba9f675e3872826b5dcd [file] [log] [blame]
Chris Lattner48486892003-09-30 18:37:50 +00001//===-- Support/DotGraphTraits.h - Customize .dot output --------*- C++ -*-===//
John Criswellb2109ce2003-10-20 19:46:57 +00002//
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 Lattner95b923d2002-10-07 18:37:10 +00009//
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
22/// DefaultDOTGraphTraits - This class provides the default implementations of
23/// all of the DOTGraphTraits methods. If a specialization does not need to
24/// override all methods here it should inherit so that it can get the default
25/// implementations.
26///
27struct DefaultDOTGraphTraits {
28 /// getGraphName - Return the label for the graph as a whole. Printed at the
29 /// top of the graph.
30 ///
Chris Lattnera16adb72002-10-17 00:16:39 +000031 static std::string getGraphName(const void *Graph) { return ""; }
Chris Lattner95b923d2002-10-07 18:37:10 +000032
Chris Lattnere9812832002-10-10 22:29:10 +000033 /// getGraphProperties - Return any custom properties that should be included
34 /// in the top level graph structure for dot. By default, we resize the graph
35 /// to fit on a letter size page.
36 ///
Chris Lattnera16adb72002-10-17 00:16:39 +000037 static std::string getGraphProperties(const void *Graph) {
Chris Lattnere9812832002-10-10 22:29:10 +000038 return "\tsize=\"7.5,10\";\n"; // Size to fit on a page
39 }
40
Chris Lattner95b923d2002-10-07 18:37:10 +000041 /// getNodeLabel - Given a node and a pointer to the top level graph, return
42 /// the label to print in the node.
Chris Lattnera16adb72002-10-17 00:16:39 +000043 static std::string getNodeLabel(const void *Node, const void *Graph) {
44 return "";
45 }
Chris Lattner95b923d2002-10-07 18:37:10 +000046
47 /// If you want to specify custom node attributes, this is the place to do so
48 ///
Chris Lattnera16adb72002-10-17 00:16:39 +000049 static std::string getNodeAttributes(const void *Node) { return ""; }
Chris Lattner95b923d2002-10-07 18:37:10 +000050
51 /// If you want to override the dot attributes printed for a particular edge,
52 /// override this method.
53 template<typename EdgeIter>
Chris Lattnera16adb72002-10-17 00:16:39 +000054 static std::string getEdgeAttributes(const void *Node, EdgeIter EI) {
55 return "";
56 }
Chris Lattner95b923d2002-10-07 18:37:10 +000057
58 /// getEdgeSourceLabel - If you want to label the edge source itself,
59 /// implement this method.
60 template<typename EdgeIter>
Chris Lattnera16adb72002-10-17 00:16:39 +000061 static std::string getEdgeSourceLabel(const void *Node, EdgeIter I) {
62 return "";
63 }
Chris Lattner95b923d2002-10-07 18:37:10 +000064
65 /// edgeTargetsEdgeSource - This method returns true if this outgoing edge
66 /// should actually target another edge source, not a node. If this method is
67 /// implemented, getEdgeTarget should be implemented.
68 template<typename EdgeIter>
Chris Lattnera16adb72002-10-17 00:16:39 +000069 static bool edgeTargetsEdgeSource(const void *Node, EdgeIter I) {
70 return false;
71 }
Chris Lattner95b923d2002-10-07 18:37:10 +000072
73 /// getEdgeTarget - If edgeTargetsEdgeSource returns true, this method is
74 /// called to determine which outgoing edge of Node is the target of this
75 /// edge.
76 template<typename EdgeIter>
Chris Lattnera16adb72002-10-17 00:16:39 +000077 static EdgeIter getEdgeTarget(const void *Node, EdgeIter I) {
78 return I;
79 }
Chris Lattner834a9d12002-10-16 01:44:59 +000080
81 /// addCustomGraphFeatures - If a graph is made up of more than just
82 /// straight-forward nodes and edges, this is the place to put all of the
Misha Brukman5560c9d2003-08-18 14:43:39 +000083 /// custom stuff necessary. The GraphWriter object, instantiated with your
Chris Lattner834a9d12002-10-16 01:44:59 +000084 /// GraphType is passed in as an argument. You may call arbitrary methods on
85 /// it to add things to the output graph.
86 ///
87 template<typename GraphWriter>
Chris Lattnera16adb72002-10-17 00:16:39 +000088 static void addCustomGraphFeatures(const void *Graph, GraphWriter &GW) {}
Chris Lattner95b923d2002-10-07 18:37:10 +000089};
90
91
92/// DOTGraphTraits - Template class that can be specialized to customize how
93/// graphs are converted to 'dot' graphs. When specializing, you may inherit
94/// from DefaultDOTGraphTraits if you don't need to override everything.
95///
96template <typename Ty>
97class DOTGraphTraits : public DefaultDOTGraphTraits {};
98
99#endif