LLVM API Documentation

DOTGraphTraits.h

Go to the documentation of this file.
00001 //===-- llvm/Support/DotGraphTraits.h - Customize .dot output ---*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file defines a template class that can be used to customize dot output
00011 // graphs generated by the GraphWriter.h file.  The default implementation of
00012 // this file will produce a simple, but not very polished graph.  By
00013 // specializing this template, lots of customization opportunities are possible.
00014 //
00015 //===----------------------------------------------------------------------===//
00016 
00017 #ifndef LLVM_SUPPORT_DOTGRAPHTRAITS_H
00018 #define LLVM_SUPPORT_DOTGRAPHTRAITS_H
00019 
00020 #include <string>
00021 
00022 namespace llvm {
00023 
00024 /// DefaultDOTGraphTraits - This class provides the default implementations of
00025 /// all of the DOTGraphTraits methods.  If a specialization does not need to
00026 /// override all methods here it should inherit so that it can get the default
00027 /// implementations.
00028 ///
00029 struct DefaultDOTGraphTraits {
00030   /// getGraphName - Return the label for the graph as a whole.  Printed at the
00031   /// top of the graph.
00032   ///
00033   template<typename GraphType>
00034   static std::string getGraphName(const GraphType& Graph) { return ""; }
00035 
00036   /// getGraphProperties - Return any custom properties that should be included
00037   /// in the top level graph structure for dot.
00038   ///
00039   template<typename GraphType>
00040   static std::string getGraphProperties(const GraphType& Graph) {
00041     return "";
00042   }
00043 
00044   /// renderGraphFromBottomUp - If this function returns true, the graph is
00045   /// emitted bottom-up instead of top-down.  This requires graphviz 2.0 to work
00046   /// though.
00047   static bool renderGraphFromBottomUp() {
00048     return false;
00049   }
00050 
00051   /// getNodeLabel - Given a node and a pointer to the top level graph, return
00052   /// the label to print in the node.
00053   template<typename GraphType>
00054   static std::string getNodeLabel(const void *Node, const GraphType& Graph) {
00055     return "";
00056   }
00057   
00058   /// hasNodeAddressLabel - If this method returns true, the address of the node
00059   /// is added to the label of the node.
00060   template<typename GraphType>
00061   static bool hasNodeAddressLabel(const void *Node, const GraphType& Graph) {
00062     return false;
00063   }
00064 
00065   /// If you want to specify custom node attributes, this is the place to do so
00066   ///
00067   template<typename GraphType>
00068   static std::string getNodeAttributes(const void *Node,
00069                                        const GraphType& Graph) {
00070     return "";
00071   }
00072 
00073   /// If you want to override the dot attributes printed for a particular edge,
00074   /// override this method.
00075   template<typename EdgeIter>
00076   static std::string getEdgeAttributes(const void *Node, EdgeIter EI) {
00077     return "";
00078   }
00079 
00080   /// getEdgeSourceLabel - If you want to label the edge source itself,
00081   /// implement this method.
00082   template<typename EdgeIter>
00083   static std::string getEdgeSourceLabel(const void *Node, EdgeIter I) {
00084     return "";
00085   }
00086 
00087   /// edgeTargetsEdgeSource - This method returns true if this outgoing edge
00088   /// should actually target another edge source, not a node.  If this method is
00089   /// implemented, getEdgeTarget should be implemented.
00090   template<typename EdgeIter>
00091   static bool edgeTargetsEdgeSource(const void *Node, EdgeIter I) {
00092     return false;
00093   }
00094 
00095   /// getEdgeTarget - If edgeTargetsEdgeSource returns true, this method is
00096   /// called to determine which outgoing edge of Node is the target of this
00097   /// edge.
00098   template<typename EdgeIter>
00099   static EdgeIter getEdgeTarget(const void *Node, EdgeIter I) {
00100     return I;
00101   }
00102 
00103   /// hasEdgeDestLabels - If this function returns true, the graph is able
00104   /// to provide labels for edge destinations.
00105   static bool hasEdgeDestLabels() {
00106     return false;
00107   }
00108 
00109   /// numEdgeDestLabels - If hasEdgeDestLabels, this function returns the
00110   /// number of incoming edge labels the given node has.
00111   static unsigned numEdgeDestLabels(const void *Node) {
00112     return 0;
00113   }
00114 
00115   /// getEdgeDestLabel - If hasEdgeDestLabels, this function returns the
00116   /// incoming edge label with the given index in the given node.
00117   static std::string getEdgeDestLabel(const void *Node, unsigned i) {
00118     return "";
00119   }
00120 
00121   /// addCustomGraphFeatures - If a graph is made up of more than just
00122   /// straight-forward nodes and edges, this is the place to put all of the
00123   /// custom stuff necessary.  The GraphWriter object, instantiated with your
00124   /// GraphType is passed in as an argument.  You may call arbitrary methods on
00125   /// it to add things to the output graph.
00126   ///
00127   template<typename GraphType, typename GraphWriter>
00128   static void addCustomGraphFeatures(const GraphType& Graph, GraphWriter &GW) {}
00129 };
00130 
00131 
00132 /// DOTGraphTraits - Template class that can be specialized to customize how
00133 /// graphs are converted to 'dot' graphs.  When specializing, you may inherit
00134 /// from DefaultDOTGraphTraits if you don't need to override everything.
00135 ///
00136 template <typename Ty>
00137 struct DOTGraphTraits : public DefaultDOTGraphTraits {};
00138 
00139 } // End llvm namespace
00140 
00141 #endif