- Allow printing generic LLVM graphs to 'dot' files, so they can be
[oota-llvm.git] / include / Support / DOTGraphTraits.h
1 //===-- Support/DotGraphTraits.h - Customize .dot output -------*- C++ -*--===//
2 //
3 // This file defines a template class that can be used to customize dot output
4 // graphs generated by the GraphWriter.h file.  The default implementation of
5 // this file will produce a simple, but not very polished graph.  By
6 // specializing this template, lots of customization opportunities are possible.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef SUPPORT_DOTGRAPHTRAITS_H
11 #define SUPPORT_DOTGRAPHTRAITS_H
12
13 #include <string>
14
15 /// DefaultDOTGraphTraits - This class provides the default implementations of
16 /// all of the DOTGraphTraits methods.  If a specialization does not need to
17 /// override all methods here it should inherit so that it can get the default
18 /// implementations.
19 ///
20 struct DefaultDOTGraphTraits {
21   /// getGraphName - Return the label for the graph as a whole.  Printed at the
22   /// top of the graph.
23   ///
24   static std::string getGraphName(void *Graph) { return ""; }
25
26   /// getNodeLabel - Given a node and a pointer to the top level graph, return
27   /// the label to print in the node.
28   static std::string getNodeLabel(void *Node, void *Graph) { return ""; }
29
30   /// If you want to specify custom node attributes, this is the place to do so
31   ///
32   static std::string getNodeAttributes(void *Node) { return ""; }
33
34   /// If you want to override the dot attributes printed for a particular edge,
35   /// override this method.
36   template<typename EdgeIter>
37   static std::string getEdgeAttributes(void *Node, EdgeIter EI) { return ""; }
38
39   /// getEdgeSourceLabel - If you want to label the edge source itself,
40   /// implement this method.
41   template<typename EdgeIter>
42   static std::string getEdgeSourceLabel(void *Node, EdgeIter I) { return ""; }
43
44   /// edgeTargetsEdgeSource - This method returns true if this outgoing edge
45   /// should actually target another edge source, not a node.  If this method is
46   /// implemented, getEdgeTarget should be implemented.
47   template<typename EdgeIter>
48   static bool edgeTargetsEdgeSource(void *Node, EdgeIter I) { return false; }
49
50   /// getEdgeTarget - If edgeTargetsEdgeSource returns true, this method is
51   /// called to determine which outgoing edge of Node is the target of this
52   /// edge.
53   template<typename EdgeIter>
54   static EdgeIter getEdgeTarget(void *Node, EdgeIter I) { return I; }
55 };
56
57
58 /// DOTGraphTraits - Template class that can be specialized to customize how
59 /// graphs are converted to 'dot' graphs.  When specializing, you may inherit
60 /// from DefaultDOTGraphTraits if you don't need to override everything.
61 ///
62 template <typename Ty>
63 class DOTGraphTraits : public DefaultDOTGraphTraits {};
64
65 #endif