From ee64370eb563e17211c83659ea8707069d8bf2e2 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 13 Oct 2002 19:31:57 +0000 Subject: [PATCH] Halfway conversion from custom printing to GraphWriter printing llvm-svn: 4146 --- lib/Analysis/DataStructure/Printer.cpp | 33 ++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/lib/Analysis/DataStructure/Printer.cpp b/lib/Analysis/DataStructure/Printer.cpp index 51ebe632eb4..b7c27148362 100644 --- a/lib/Analysis/DataStructure/Printer.cpp +++ b/lib/Analysis/DataStructure/Printer.cpp @@ -6,9 +6,11 @@ #include "llvm/Analysis/DataStructure.h" #include "llvm/Analysis/DSGraph.h" +#include "llvm/Analysis/DSGraphTraits.h" #include "llvm/Module.h" #include "llvm/Assembly/Writer.h" #include "Support/CommandLine.h" +#include "Support/GraphWriter.h" #include #include using std::string; @@ -165,6 +167,36 @@ void DSGraph::print(std::ostream &O) const { O << "}\n"; } +template<> +struct DOTGraphTraits : public DefaultDOTGraphTraits { + static std::string getGraphName(DSGraph *G) { + if (G->hasFunction()) + return "Function " + G->getFunction().getName(); + else + return "Non-function graph"; + } + + static const char *getGraphProperties(DSGraph *G) { + return "\tnode [shape=Mrecord];\n" + "\tedge [arrowtail=\"dot\"];\n" + "\tsize=\"10,7.5\";\n" + "\trotate=\"90\";\n"; + } + + static std::string getNodeLabel(DSNode *Node, DSGraph *Graph) { + return getCaption(Node, Graph); + } + + static std::string getNodeAttributes(DSNode *N) { + return "";//fontname=Courier"; + } + + //static int getEdgeSourceLabel(DSNode *Node, node_iterator I) { + // return MergeMap[i]; + // } +}; + + void DSGraph::writeGraphToFile(std::ostream &O, const string &GraphName) { string Filename = GraphName + ".dot"; @@ -172,6 +204,7 @@ void DSGraph::writeGraphToFile(std::ostream &O, const string &GraphName) { std::ofstream F(Filename.c_str()); if (F.good()) { + WriteGraph(F, this); print(F); O << " [" << getGraphSize() << "+" << getFunctionCalls().size() << "]\n"; } else {