DOTGraphTraits.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===-- llvm/Support/DOTGraphTraits.h - Customize .dot output ---*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // This file defines a template class that can be used to customize dot output
  15. // graphs generated by the GraphWriter.h file. The default implementation of
  16. // this file will produce a simple, but not very polished graph. By
  17. // specializing this template, lots of customization opportunities are possible.
  18. //
  19. //===----------------------------------------------------------------------===//
  20. #ifndef LLVM_SUPPORT_DOTGRAPHTRAITS_H
  21. #define LLVM_SUPPORT_DOTGRAPHTRAITS_H
  22. #include <string>
  23. namespace llvm {
  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. private:
  31. bool IsSimple;
  32. protected:
  33. bool isSimple() {
  34. return IsSimple;
  35. }
  36. public:
  37. explicit DefaultDOTGraphTraits(bool simple=false) : IsSimple (simple) {}
  38. /// getGraphName - Return the label for the graph as a whole. Printed at the
  39. /// top of the graph.
  40. ///
  41. template<typename GraphType>
  42. static std::string getGraphName(const GraphType &) { return ""; }
  43. /// getGraphProperties - Return any custom properties that should be included
  44. /// in the top level graph structure for dot.
  45. ///
  46. template<typename GraphType>
  47. static std::string getGraphProperties(const GraphType &) {
  48. return "";
  49. }
  50. /// renderGraphFromBottomUp - If this function returns true, the graph is
  51. /// emitted bottom-up instead of top-down. This requires graphviz 2.0 to work
  52. /// though.
  53. static bool renderGraphFromBottomUp() {
  54. return false;
  55. }
  56. /// isNodeHidden - If the function returns true, the given node is not
  57. /// displayed in the graph.
  58. template <typename GraphType>
  59. static bool isNodeHidden(const void *, const GraphType &) {
  60. return false;
  61. }
  62. // renderNodesUsingHTML - If the function returns true, nodes will be
  63. // rendered using HTML-like labels which allows colors, etc in the nodes
  64. // and the edge source labels.
  65. static bool renderNodesUsingHTML() { return false; }
  66. /// getNodeLabel - Given a node and a pointer to the top level graph, return
  67. /// the label to print in the node.
  68. template<typename GraphType>
  69. std::string getNodeLabel(const void *, const GraphType &) {
  70. return "";
  71. }
  72. // getNodeIdentifierLabel - Returns a string representing the
  73. // address or other unique identifier of the node. (Only used if
  74. // non-empty.)
  75. template <typename GraphType>
  76. static std::string getNodeIdentifierLabel(const void *, const GraphType &) {
  77. return "";
  78. }
  79. template<typename GraphType>
  80. static std::string getNodeDescription(const void *, const GraphType &) {
  81. return "";
  82. }
  83. /// If you want to specify custom node attributes, this is the place to do so
  84. ///
  85. template<typename GraphType>
  86. static std::string getNodeAttributes(const void *,
  87. const GraphType &) {
  88. return "";
  89. }
  90. /// If you want to override the dot attributes printed for a particular edge,
  91. /// override this method.
  92. template<typename EdgeIter, typename GraphType>
  93. static std::string getEdgeAttributes(const void *, EdgeIter,
  94. const GraphType &) {
  95. return "";
  96. }
  97. /// getEdgeSourceLabel - If you want to label the edge source itself,
  98. /// implement this method.
  99. template<typename EdgeIter>
  100. static std::string getEdgeSourceLabel(const void *, EdgeIter) {
  101. return "";
  102. }
  103. /// edgeTargetsEdgeSource - This method returns true if this outgoing edge
  104. /// should actually target another edge source, not a node. If this method is
  105. /// implemented, getEdgeTarget should be implemented.
  106. template<typename EdgeIter>
  107. static bool edgeTargetsEdgeSource(const void *, EdgeIter) {
  108. return false;
  109. }
  110. /// getEdgeTarget - If edgeTargetsEdgeSource returns true, this method is
  111. /// called to determine which outgoing edge of Node is the target of this
  112. /// edge.
  113. template<typename EdgeIter>
  114. static EdgeIter getEdgeTarget(const void *, EdgeIter I) {
  115. return I;
  116. }
  117. /// hasEdgeDestLabels - If this function returns true, the graph is able
  118. /// to provide labels for edge destinations.
  119. static bool hasEdgeDestLabels() {
  120. return false;
  121. }
  122. /// numEdgeDestLabels - If hasEdgeDestLabels, this function returns the
  123. /// number of incoming edge labels the given node has.
  124. static unsigned numEdgeDestLabels(const void *) {
  125. return 0;
  126. }
  127. /// getEdgeDestLabel - If hasEdgeDestLabels, this function returns the
  128. /// incoming edge label with the given index in the given node.
  129. static std::string getEdgeDestLabel(const void *, unsigned) {
  130. return "";
  131. }
  132. /// addCustomGraphFeatures - If a graph is made up of more than just
  133. /// straight-forward nodes and edges, this is the place to put all of the
  134. /// custom stuff necessary. The GraphWriter object, instantiated with your
  135. /// GraphType is passed in as an argument. You may call arbitrary methods on
  136. /// it to add things to the output graph.
  137. ///
  138. template<typename GraphType, typename GraphWriter>
  139. static void addCustomGraphFeatures(const GraphType &, GraphWriter &) {}
  140. };
  141. /// DOTGraphTraits - Template class that can be specialized to customize how
  142. /// graphs are converted to 'dot' graphs. When specializing, you may inherit
  143. /// from DefaultDOTGraphTraits if you don't need to override everything.
  144. ///
  145. template <typename Ty>
  146. struct DOTGraphTraits : public DefaultDOTGraphTraits {
  147. DOTGraphTraits (bool simple=false) : DefaultDOTGraphTraits (simple) {}
  148. };
  149. } // End llvm namespace
  150. #endif
  151. #ifdef __GNUC__
  152. #pragma GCC diagnostic pop
  153. #endif