diff options
author | Zhongxing Xu <xuzhongxing@gmail.com> | 2009-07-23 13:39:38 +0000 |
---|---|---|
committer | Zhongxing Xu <xuzhongxing@gmail.com> | 2009-07-23 13:39:38 +0000 |
commit | ee5d708e555b56a760f3b18e43c1ae4661e170cb (patch) | |
tree | c6da78c377b57d991450e411909e2799efb43608 /clang/lib/Analysis/CallGraph.cpp | |
parent | a598e5c9d515beaedff2412dba4f72e5be0068ba (diff) | |
download | llvm-ee5d708e555b56a760f3b18e43c1ae4661e170cb.zip llvm-ee5d708e555b56a760f3b18e43c1ae4661e170cb.tar.gz llvm-ee5d708e555b56a760f3b18e43c1ae4661e170cb.tar.bz2 |
Add two nodes to the call graph:
- Root is the main function or 0.
- ExternalCallingNode has edges to all external functions.
llvm-svn: 76876
Diffstat (limited to 'clang/lib/Analysis/CallGraph.cpp')
-rw-r--r-- | clang/lib/Analysis/CallGraph.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/clang/lib/Analysis/CallGraph.cpp b/clang/lib/Analysis/CallGraph.cpp index bfc2c0d..07c2b353 100644 --- a/clang/lib/Analysis/CallGraph.cpp +++ b/clang/lib/Analysis/CallGraph.cpp @@ -58,6 +58,10 @@ void CGBuilder::VisitCallExpr(CallExpr *CE) { } } +CallGraph::CallGraph() : Root(0) { + ExternalCallingNode = getOrInsertFunction(Entity()); +} + CallGraph::~CallGraph() { if (!FunctionMap.empty()) { for (FunctionMapTy::iterator I = FunctionMap.begin(), E = FunctionMap.end(); @@ -80,6 +84,14 @@ void CallGraph::addTU(ASTUnit &AST) { Entity Ent = Entity::get(FD, Prog); CallGraphNode *Node = getOrInsertFunction(Ent); CallerCtx[Node] = &Ctx; + + // If this function has external linkage, anything could call it. + if (FD->isGlobal()) + ExternalCallingNode->addCallee(idx::ASTLocation(), Node); + + // Set root node to 'main' function. + if (FD->getNameAsString() == "main") + Root = Node; CGBuilder builder(*this, FD, Ent, Node); builder.Visit(FD->getBody()); |