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,
00055                                   const GraphType& Graph, bool ShortNames) {
00056     return "";
00057   }
00058 
00059   /// hasNodeAddressLabel - If this method returns true, the address of the node
00060   /// is added to the label of the node.
00061   template<typename GraphType>
00062   static bool hasNodeAddressLabel(const void *Node, const GraphType& Graph) {
00063     return false;
00064   }
00065 
00066   /// If you want to specify custom node attributes, this is the place to do so
00067   ///
00068   template<typename GraphType>
00069   static std::string getNodeAttributes(const void *Node,
00070                                        const GraphType& Graph) {
00071     return "";
00072   }
00073 
00074   /// If you want to override the dot attributes printed for a particular edge,
00075   /// override this method.
00076   template<typename EdgeIter>
00077   static std::string getEdgeAttributes(const void *Node, EdgeIter EI) {
00078     return "";
00079   }
00080 
00081   /// getEdgeSourceLabel - If you want to label the edge source itself,
00082   /// implement this method.
00083   template<typename EdgeIter>
00084   static std::string getEdgeSourceLabel(const void *Node, EdgeIter I) {
00085     return "";
00086   }
00087 
00088   /// edgeTargetsEdgeSource - This method returns true if this outgoing edge
00089   /// should actually target another edge source, not a node.  If this method is
00090   /// implemented, getEdgeTarget should be implemented.
00091   template<typename EdgeIter>
00092   static bool edgeTargetsEdgeSource(const void *Node, EdgeIter I) {
00093     return false;
00094   }
00095 
00096   /// getEdgeTarget - If edgeTargetsEdgeSource returns true, this method is
00097   /// called to determine which outgoing edge of Node is the target of this
00098   /// edge.
00099   template<typename EdgeIter>
00100   static EdgeIter getEdgeTarget(const void *Node, EdgeIter I) {
00101     return I;
00102   }
00103 
00104   /// hasEdgeDestLabels - If this function returns true, the graph is able
00105   /// to provide labels for edge destinations.
00106   static bool hasEdgeDestLabels() {
00107     return false;
00108   }
00109 
00110   /// numEdgeDestLabels - If hasEdgeDestLabels, this function returns the
00111   /// number of incoming edge labels the given node has.
00112   static unsigned numEdgeDestLabels(const void *Node) {
00113     return 0;
00114   }
00115 
00116   /// getEdgeDestLabel - If hasEdgeDestLabels, this function returns the
00117   /// incoming edge label with the given index in the given node.
00118   static std::string getEdgeDestLabel(const void *Node, unsigned i) {
00119     return "";
00120   }
00121 
00122   /// addCustomGraphFeatures - If a graph is made up of more than just
00123   /// straight-forward nodes and edges, this is the place to put all of the
00124   /// custom stuff necessary.  The GraphWriter object, instantiated with your
00125   /// GraphType is passed in as an argument.  You may call arbitrary methods on
00126   /// it to add things to the output graph.
00127   ///
00128   template<typename GraphType, typename GraphWriter>
00129   static void addCustomGraphFeatures(const GraphType& Graph, GraphWriter &GW) {}
00130 };
00131 
00132 
00133 /// DOTGraphTraits - Template class that can be specialized to customize how
00134 /// graphs are converted to 'dot' graphs.  When specializing, you may inherit
00135 /// from DefaultDOTGraphTraits if you don't need to override everything.
00136 ///
00137 template <typename Ty>
00138 struct DOTGraphTraits : public DefaultDOTGraphTraits {};
00139 
00140 } // End llvm namespace
00141 
00142 #endif