mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-12 13:30:51 +00:00
Implement a new -print-callgraph analysis that turns a callgraph into a dot
graph git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@4524 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
af663465d6
commit
f74825436c
@ -10,10 +10,15 @@
|
||||
#include "Support/GraphWriter.h"
|
||||
#include "llvm/Pass.h"
|
||||
#include "llvm/iTerminators.h"
|
||||
#include "llvm/Analysis/CallGraph.h"
|
||||
#include "llvm/Support/CFG.h"
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Control Flow Graph Printer
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
template<>
|
||||
struct DOTGraphTraits<Function*> : public DefaultDOTGraphTraits {
|
||||
static std::string getGraphName(Function *F) {
|
||||
@ -70,7 +75,6 @@ static void WriteGraphToFile(std::ostream &O, const std::string &GraphName,
|
||||
|
||||
namespace {
|
||||
struct CFGPrinter : public FunctionPass {
|
||||
Function *F;
|
||||
virtual bool runOnFunction(Function &Func) {
|
||||
WriteGraphToFile(std::cerr, "cfg."+Func.getName(), &Func);
|
||||
return false;
|
||||
@ -86,3 +90,43 @@ namespace {
|
||||
RegisterAnalysis<CFGPrinter> P1("print-cfg",
|
||||
"Print CFG of function to 'dot' file");
|
||||
};
|
||||
|
||||
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Call Graph Printer
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
template<>
|
||||
struct DOTGraphTraits<CallGraph*> : public DefaultDOTGraphTraits {
|
||||
static std::string getGraphName(CallGraph *F) {
|
||||
return "Call Graph";
|
||||
}
|
||||
|
||||
static std::string getNodeLabel(CallGraphNode *Node, CallGraph *Graph) {
|
||||
if (Node->getFunction())
|
||||
return Node->getFunction()->getName();
|
||||
else
|
||||
return "Indirect call node";
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
namespace {
|
||||
struct CallGraphPrinter : public Pass {
|
||||
virtual bool run(Module &M) {
|
||||
WriteGraphToFile(std::cerr, "callgraph", &getAnalysis<CallGraph>());
|
||||
return false;
|
||||
}
|
||||
|
||||
void print(std::ostream &OS) const {}
|
||||
|
||||
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
||||
AU.addRequired<CallGraph>();
|
||||
AU.setPreservesAll();
|
||||
}
|
||||
};
|
||||
|
||||
RegisterAnalysis<CallGraphPrinter> P2("print-callgraph",
|
||||
"Print Call Graph to 'dot' file");
|
||||
};
|
||||
|
@ -10,10 +10,15 @@
|
||||
#include "Support/GraphWriter.h"
|
||||
#include "llvm/Pass.h"
|
||||
#include "llvm/iTerminators.h"
|
||||
#include "llvm/Analysis/CallGraph.h"
|
||||
#include "llvm/Support/CFG.h"
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Control Flow Graph Printer
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
template<>
|
||||
struct DOTGraphTraits<Function*> : public DefaultDOTGraphTraits {
|
||||
static std::string getGraphName(Function *F) {
|
||||
@ -70,7 +75,6 @@ static void WriteGraphToFile(std::ostream &O, const std::string &GraphName,
|
||||
|
||||
namespace {
|
||||
struct CFGPrinter : public FunctionPass {
|
||||
Function *F;
|
||||
virtual bool runOnFunction(Function &Func) {
|
||||
WriteGraphToFile(std::cerr, "cfg."+Func.getName(), &Func);
|
||||
return false;
|
||||
@ -86,3 +90,43 @@ namespace {
|
||||
RegisterAnalysis<CFGPrinter> P1("print-cfg",
|
||||
"Print CFG of function to 'dot' file");
|
||||
};
|
||||
|
||||
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Call Graph Printer
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
template<>
|
||||
struct DOTGraphTraits<CallGraph*> : public DefaultDOTGraphTraits {
|
||||
static std::string getGraphName(CallGraph *F) {
|
||||
return "Call Graph";
|
||||
}
|
||||
|
||||
static std::string getNodeLabel(CallGraphNode *Node, CallGraph *Graph) {
|
||||
if (Node->getFunction())
|
||||
return Node->getFunction()->getName();
|
||||
else
|
||||
return "Indirect call node";
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
namespace {
|
||||
struct CallGraphPrinter : public Pass {
|
||||
virtual bool run(Module &M) {
|
||||
WriteGraphToFile(std::cerr, "callgraph", &getAnalysis<CallGraph>());
|
||||
return false;
|
||||
}
|
||||
|
||||
void print(std::ostream &OS) const {}
|
||||
|
||||
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
||||
AU.addRequired<CallGraph>();
|
||||
AU.setPreservesAll();
|
||||
}
|
||||
};
|
||||
|
||||
RegisterAnalysis<CallGraphPrinter> P2("print-callgraph",
|
||||
"Print Call Graph to 'dot' file");
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user