Derive MDNode from MetadataBase instead of Constant. Emit MDNodes into METADATA_BLOCK...
[oota-llvm.git] / include / llvm / Support / DOTGraphTraits.h
1 //===-- llvm/Support/DotGraphTraits.h - Customize .dot output ---*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // 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 LLVM_SUPPORT_DOTGRAPHTRAITS_H
18 #define LLVM_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   template<typename GraphType>
34   static std::string getGraphName(const GraphType& Graph) { return ""; }
35
36   /// getGraphProperties - Return any custom properties that should be included
37   /// in the top level graph structure for dot.
38   ///
39   template<typename GraphType>
40   static std::string getGraphProperties(const GraphType& Graph) {
41     return "";
42   }
43
44   /// renderGraphFromBottomUp - If this function returns true, the graph is
45   /// emitted bottom-up instead of top-down.  This requires graphviz 2.0 to work
46   /// though.
47   static bool renderGraphFromBottomUp() {
48     return false;
49   }
50
51   /// getNodeLabel - Given a node and a pointer to the top level graph, return
52   /// the label to print in the node.
53   template<typename GraphType>
54   static std::string getNodeLabel(const void *Node,
55                                   const GraphType& Graph, bool ShortNames) {
56     return "";
57   }
58
59   /// hasNodeAddressLabel - If this method returns true, the address of the node
60   /// is added to the label of the node.
61   template<typename GraphType>
62   static bool hasNodeAddressLabel(const void *Node, const GraphType& Graph) {
63     return false;
64   }
65
66   /// If you want to specify custom node attributes, this is the place to do so
67   ///
68   template<typename GraphType>
69   static std::string getNodeAttributes(const void *Node,
70                                        const GraphType& Graph) {
71     return "";
72   }
73
74   /// If you want to override the dot attributes printed for a particular edge,
75   /// override this method.
76   template<typename EdgeIter>
77   static std::string getEdgeAttributes(const void *Node, EdgeIter EI) {
78     return "";
79   }
80
81   /// getEdgeSourceLabel - If you want to label the edge source itself,
82   /// implement this method.
83   template<typename EdgeIter>
84   static std::string getEdgeSourceLabel(const void *Node, EdgeIter I) {
85     return "";
86   }
87
88   /// edgeTargetsEdgeSource - This method returns true if this outgoing edge
89   /// should actually target another edge source, not a node.  If this method is
90   /// implemented, getEdgeTarget should be implemented.
91   template<typename EdgeIter>
92   static bool edgeTargetsEdgeSource(const void *Node, EdgeIter I) {
93     return false;
94   }
95
96   /// getEdgeTarget - If edgeTargetsEdgeSource returns true, this method is
97   /// called to determine which outgoing edge of Node is the target of this
98   /// edge.
99   template<typename EdgeIter>
100   static EdgeIter getEdgeTarget(const void *Node, EdgeIter I) {
101     return I;
102   }
103
104   /// hasEdgeDestLabels - If this function returns true, the graph is able
105   /// to provide labels for edge destinations.
106   static bool hasEdgeDestLabels() {
107     return false;
108   }
109
110   /// numEdgeDestLabels - If hasEdgeDestLabels, this function returns the
111   /// number of incoming edge labels the given node has.
112   static unsigned numEdgeDestLabels(const void *Node) {
113     return 0;
114   }
115
116   /// getEdgeDestLabel - If hasEdgeDestLabels, this function returns the
117   /// incoming edge label with the given index in the given node.
118   static std::string getEdgeDestLabel(const void *Node, unsigned i) {
119     return "";
120   }
121
122   /// addCustomGraphFeatures - If a graph is made up of more than just
123   /// straight-forward nodes and edges, this is the place to put all of the
124   /// custom stuff necessary.  The GraphWriter object, instantiated with your
125   /// GraphType is passed in as an argument.  You may call arbitrary methods on
126   /// it to add things to the output graph.
127   ///
128   template<typename GraphType, typename GraphWriter>
129   static void addCustomGraphFeatures(const GraphType& Graph, GraphWriter &GW) {}
130 };
131
132
133 /// DOTGraphTraits - Template class that can be specialized to customize how
134 /// graphs are converted to 'dot' graphs.  When specializing, you may inherit
135 /// from DefaultDOTGraphTraits if you don't need to override everything.
136 ///
137 template <typename Ty>
138 struct DOTGraphTraits : public DefaultDOTGraphTraits {};
139
140 } // End llvm namespace
141
142 #endif