Be a bit more efficient when processing the active and inactive
[oota-llvm.git] / include / llvm / Support / DOTGraphTraits.h
1 //===-- Support/DotGraphTraits.h - Customize .dot output --------*- C++ -*-===//
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 //===----------------------------------------------------------------------===//
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
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   /// getGraphName - Return the label for the graph as a whole.  Printed at the
31   /// top of the graph.
32   ///
33   static std::string getGraphName(const void *Graph) { return ""; }
34
35   /// getGraphProperties - Return any custom properties that should be included
36   /// in the top level graph structure for dot.
37   ///
38   static std::string getGraphProperties(const void *Graph) {
39     return "";
40   }
41
42   /// getNodeLabel - Given a node and a pointer to the top level graph, return
43   /// the label to print in the node.
44   static std::string getNodeLabel(const void *Node, const void *Graph) {
45     return "";
46   }
47
48   /// If you want to specify custom node attributes, this is the place to do so
49   ///
50   static std::string getNodeAttributes(const void *Node) { return ""; }
51
52   /// If you want to override the dot attributes printed for a particular edge,
53   /// override this method.
54   template<typename EdgeIter>
55   static std::string getEdgeAttributes(const void *Node, EdgeIter EI) {
56     return "";
57   }
58
59   /// getEdgeSourceLabel - If you want to label the edge source itself,
60   /// implement this method.
61   template<typename EdgeIter>
62   static std::string getEdgeSourceLabel(const void *Node, EdgeIter I) {
63     return "";
64   }
65
66   /// edgeTargetsEdgeSource - This method returns true if this outgoing edge
67   /// should actually target another edge source, not a node.  If this method is
68   /// implemented, getEdgeTarget should be implemented.
69   template<typename EdgeIter>
70   static bool edgeTargetsEdgeSource(const void *Node, EdgeIter I) {
71     return false;
72   }
73
74   /// getEdgeTarget - If edgeTargetsEdgeSource returns true, this method is
75   /// called to determine which outgoing edge of Node is the target of this
76   /// edge.
77   template<typename EdgeIter>
78   static EdgeIter getEdgeTarget(const void *Node, EdgeIter I) {
79     return I;
80   }
81
82   /// addCustomGraphFeatures - If a graph is made up of more than just
83   /// straight-forward nodes and edges, this is the place to put all of the
84   /// custom stuff necessary.  The GraphWriter object, instantiated with your
85   /// GraphType is passed in as an argument.  You may call arbitrary methods on
86   /// it to add things to the output graph.
87   ///
88   template<typename GraphWriter>
89   static void addCustomGraphFeatures(const void *Graph, GraphWriter &GW) {}
90 };
91
92
93 /// DOTGraphTraits - Template class that can be specialized to customize how
94 /// graphs are converted to 'dot' graphs.  When specializing, you may inherit
95 /// from DefaultDOTGraphTraits if you don't need to override everything.
96 ///
97 template <typename Ty>
98 class DOTGraphTraits : public DefaultDOTGraphTraits {};
99
100 } // End llvm namespace
101
102 #endif