//===- llvm/Support/GraphWriter.h - Write graph to a .dot file --*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // This file defines a simple interface that can be used to print out generic // LLVM graphs to ".dot" files. "dot" is a tool that is part of the AT&T // graphviz package (http://www.research.att.com/sw/tools/graphviz/) which can // be used to turn the files output by this interface into a variety of // different graphics formats. // // Graphs do not need to implement any interface past what is already required // by the GraphTraits template, but they can choose to implement specializations // of the DOTGraphTraits template if they want to customize the graphs output in // any way. // //===----------------------------------------------------------------------===// #ifndef LLVM_SUPPORT_GRAPHWRITER_H #define LLVM_SUPPORT_GRAPHWRITER_H #include "llvm/ADT/GraphTraits.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/Twine.h" #include "llvm/Support/DOTGraphTraits.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/raw_ostream.h" #include <iterator> #include <string> #include <type_traits> #include <vector> namespace llvm { namespace DOT { // Private functions... std::string EscapeString(const std::string &Label); /// Get a color string for this node number. Simply round-robin selects /// from a reasonable number of colors. StringRef getColorString(unsigned NodeNumber); } // end namespace DOT namespace GraphProgram { enum Name { … }; } // end namespace GraphProgram bool DisplayGraph(StringRef Filename, bool wait = true, GraphProgram::Name program = GraphProgram::DOT); template<typename GraphType> class GraphWriter { … }; template<typename GraphType> raw_ostream &WriteGraph(raw_ostream &O, const GraphType &G, bool ShortNames = false, const Twine &Title = "") { … } std::string createGraphFilename(const Twine &Name, int &FD); /// Writes graph into a provided @c Filename. /// If @c Filename is empty, generates a random one. /// \return The resulting filename, or an empty string if writing /// failed. template <typename GraphType> std::string WriteGraph(const GraphType &G, const Twine &Name, bool ShortNames = false, const Twine &Title = "", std::string Filename = "") { … } /// DumpDotGraph - Just dump a dot graph to the user-provided file name. #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) template <typename GraphType> LLVM_DUMP_METHOD void dumpDotGraphToFile(const GraphType &G, const Twine &FileName, const Twine &Title, bool ShortNames = false, const Twine &Name = "") { llvm::WriteGraph(G, Name, ShortNames, Title, FileName.str()); } #endif /// ViewGraph - Emit a dot graph, run 'dot', run gv on the postscript file, /// then cleanup. For use from the debugger. /// template<typename GraphType> void ViewGraph(const GraphType &G, const Twine &Name, bool ShortNames = false, const Twine &Title = "", GraphProgram::Name Program = GraphProgram::DOT) { … } } // end namespace llvm #endif // LLVM_SUPPORT_GRAPHWRITER_H