diff options
author | Reid Spencer <rspencer@reidspencer.com> | 2006-06-27 16:49:46 +0000 |
---|---|---|
committer | Reid Spencer <rspencer@reidspencer.com> | 2006-06-27 16:49:46 +0000 |
commit | 9d5b532de9bdca37810a59a93a69128441b02c55 (patch) | |
tree | a0590d47c0cbd3a7898f63ccf0ab7ce44c8f801f /include/llvm/Support/GraphWriter.h | |
parent | f9b238e93de0137510d4369015801e372ab0f879 (diff) |
For PR801:
Refactor the Graph writing code to use a common implementation which is
now in lib/Support/GraphWriter.cpp. This completes the PR.
Patch by Anton Korobeynikov. Thanks, Anton!
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@28925 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/Support/GraphWriter.h')
-rw-r--r-- | include/llvm/Support/GraphWriter.h | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/include/llvm/Support/GraphWriter.h b/include/llvm/Support/GraphWriter.h index ac0d52379f..9f96a77238 100644 --- a/include/llvm/Support/GraphWriter.h +++ b/include/llvm/Support/GraphWriter.h @@ -25,8 +25,10 @@ #include "llvm/Support/DOTGraphTraits.h" #include "llvm/ADT/GraphTraits.h" +#include "llvm/System/Path.h" #include <vector> #include <iostream> +#include <fstream> namespace llvm { @@ -59,6 +61,8 @@ namespace DOT { // Private functions... } } +void DisplayGraph(const sys::Path& Filename); + template<typename GraphType> class GraphWriter { std::ostream &O; @@ -236,6 +240,60 @@ std::ostream &WriteGraph(std::ostream &O, const GraphType &G, return O; } +template<typename GraphType> +sys::Path WriteGraph(const GraphType &G, + const std::string& Name, + const std::string& Title = "") { + sys::Path Filename = sys::Path::GetTemporaryDirectory();; + Filename.appendComponent(Name + ".dot"); + Filename.makeUnique(); + std::cerr << "Writing '" << Filename << "'... "; + + std::ofstream O(Filename.c_str()); + + if (O.good()) { + // Start the graph emission process... + GraphWriter<GraphType> W(O, G); + + // Output the header for the graph... + W.writeHeader(Title); + + // Emit all of the nodes in the graph... + W.writeNodes(); + + // Output any customizations on the graph + DOTGraphTraits<GraphType>::addCustomGraphFeatures(G, W); + + // Output the end of the graph + W.writeFooter(); + std::cerr << " done. \n"; + + O.close(); + + } else { + std::cerr << "error opening file for writing!\n"; + Filename.clear(); + } + + return Filename; +} + +/// 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 std::string& Name, + const std::string& Title = "") { + sys::Path Filename = WriteGraph(G, Name, Title); + + if (Filename.isEmpty()) { + return; + } + + DisplayGraph(Filename); +} + } // End llvm namespace #endif |