Add standard print/dump methods to CallGraph classes.

llvm-svn: 15569
This commit is contained in:
Chris Lattner 2004-08-08 03:27:49 +00:00
parent 92b9906199
commit 6b54110281
2 changed files with 30 additions and 16 deletions

View File

@ -166,6 +166,10 @@ public:
/// ///
void print(std::ostream &o, const Module *M) const; void print(std::ostream &o, const Module *M) const;
/// dump - Print out this call graph.
///
void dump() const;
// stub - dummy function, just ignore it // stub - dummy function, just ignore it
static void stub(); static void stub();
private: private:
@ -217,6 +221,10 @@ public:
// //
CallGraphNode *operator[](unsigned i) const { return CalledFunctions[i];} 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 // Methods to keep a call graph up to date with a function that has been

View File

@ -17,6 +17,7 @@
#include "llvm/Instructions.h" #include "llvm/Instructions.h"
#include "llvm/Support/CallSite.h" #include "llvm/Support/CallSite.h"
#include "Support/STLExtras.h" #include "Support/STLExtras.h"
#include <iostream>
using namespace llvm; using namespace llvm;
static RegisterAnalysis<CallGraph> X("callgraph", "Call Graph Construction"); static RegisterAnalysis<CallGraph> X("callgraph", "Call Graph Construction");
@ -126,30 +127,35 @@ void CallGraph::destroy() {
CallsExternalNode = 0; CallsExternalNode = 0;
} }
static void WriteToOutput(const CallGraphNode *CGN, std::ostream &o) { void CallGraphNode::print(std::ostream &OS) const {
if (CGN->getFunction()) if (Function *F = getFunction())
o << "Call graph node for function: '" OS << "Call graph node for function: '" << F->getName() <<"'\n";
<< CGN->getFunction()->getName() <<"'\n";
else else
o << "Call graph node <<null function: 0x" << CGN << ">>:\n"; OS << "Call graph node <<null function: 0x" << this << ">>:\n";
for (unsigned i = 0; i < CGN->size(); ++i) for (const_iterator I = begin(), E = end(); I != E; ++I)
if ((*CGN)[i]->getFunction()) if ((*I)->getFunction())
o << " Calls function '" << (*CGN)[i]->getFunction()->getName() << "'\n"; OS << " Calls function '" << (*I)->getFunction()->getName() << "'\n";
else else
o << " Calls external node\n"; OS << " Calls external node\n";
o << "\n"; OS << "\n";
} }
void CallGraph::print(std::ostream &o, const Module *M) const { void CallGraphNode::dump() const { print(std::cerr); }
o << "CallGraph Root is: ";
if (getRoot()->getFunction()) void CallGraph::print(std::ostream &OS, const Module *M) const {
o << getRoot()->getFunction()->getName() << "\n"; OS << "CallGraph Root is: ";
if (Function *F = getRoot()->getFunction())
OS << F->getName() << "\n";
else else
o << "<<null function: 0x" << getRoot() << ">>\n"; OS << "<<null function: 0x" << getRoot() << ">>\n";
for (CallGraph::const_iterator I = begin(), E = end(); I != E; ++I) 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);
} }