From af8a42445c99d2d733caf1f9ef3e3b53827613d5 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 8 Aug 2004 03:27:49 +0000 Subject: [PATCH] Add standard print/dump methods to CallGraph classes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15569 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Analysis/CallGraph.h | 8 +++++++ lib/Analysis/IPA/CallGraph.cpp | 38 ++++++++++++++++++------------- 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/include/llvm/Analysis/CallGraph.h b/include/llvm/Analysis/CallGraph.h index 901100dd1f1..86a2b53ad49 100644 --- a/include/llvm/Analysis/CallGraph.h +++ b/include/llvm/Analysis/CallGraph.h @@ -166,6 +166,10 @@ public: /// void print(std::ostream &o, const Module *M) const; + /// dump - Print out this call graph. + /// + void dump() const; + // stub - dummy function, just ignore it static void stub(); private: @@ -217,6 +221,10 @@ public: // CallGraphNode *operator[](unsigned i) const { return CalledFunctions[i];} + /// dump - Print out this call graph node. + /// + void dump() const; + void print(std::ostream &OS) const; //===--------------------------------------------------------------------- // Methods to keep a call graph up to date with a function that has been diff --git a/lib/Analysis/IPA/CallGraph.cpp b/lib/Analysis/IPA/CallGraph.cpp index 197c7c53d60..8025ab2d9ac 100644 --- a/lib/Analysis/IPA/CallGraph.cpp +++ b/lib/Analysis/IPA/CallGraph.cpp @@ -17,6 +17,7 @@ #include "llvm/Instructions.h" #include "llvm/Support/CallSite.h" #include "Support/STLExtras.h" +#include using namespace llvm; static RegisterAnalysis X("callgraph", "Call Graph Construction"); @@ -126,30 +127,35 @@ void CallGraph::destroy() { CallsExternalNode = 0; } -static void WriteToOutput(const CallGraphNode *CGN, std::ostream &o) { - if (CGN->getFunction()) - o << "Call graph node for function: '" - << CGN->getFunction()->getName() <<"'\n"; +void CallGraphNode::print(std::ostream &OS) const { + if (Function *F = getFunction()) + OS << "Call graph node for function: '" << F->getName() <<"'\n"; else - o << "Call graph node <>:\n"; + OS << "Call graph node <>:\n"; - for (unsigned i = 0; i < CGN->size(); ++i) - if ((*CGN)[i]->getFunction()) - o << " Calls function '" << (*CGN)[i]->getFunction()->getName() << "'\n"; + for (const_iterator I = begin(), E = end(); I != E; ++I) + if ((*I)->getFunction()) + OS << " Calls function '" << (*I)->getFunction()->getName() << "'\n"; else - o << " Calls external node\n"; - o << "\n"; + OS << " Calls external node\n"; + OS << "\n"; } -void CallGraph::print(std::ostream &o, const Module *M) const { - o << "CallGraph Root is: "; - if (getRoot()->getFunction()) - o << getRoot()->getFunction()->getName() << "\n"; +void CallGraphNode::dump() const { print(std::cerr); } + +void CallGraph::print(std::ostream &OS, const Module *M) const { + OS << "CallGraph Root is: "; + if (Function *F = getRoot()->getFunction()) + OS << F->getName() << "\n"; else - o << "<>\n"; + OS << "<>\n"; for (CallGraph::const_iterator I = begin(), E = end(); I != E; ++I) - WriteToOutput(I->second, o); + I->second->print(OS); +} + +void CallGraph::dump() const { + print(std::cerr, 0); } -- 2.34.1