/// CallerCtx maps a caller to its ASTContext.
llvm::DenseMap<CallGraphNode *, ASTContext *> CallerCtx;
- /// Entry node of the call graph.
- // FIXME: find the entry of the graph.
- CallGraphNode *Entry;
+ /// Root node is the 'main' function or 0.
+ CallGraphNode *Root;
+
+ /// ExternalCallingNode has edges to all external functions.
+ CallGraphNode *ExternalCallingNode;
public:
+ CallGraph();
~CallGraph();
typedef FunctionMapTy::iterator iterator;
const_iterator begin() const { return FunctionMap.begin(); }
const_iterator end() const { return FunctionMap.end(); }
- CallGraphNode *getEntry() { return Entry; }
+ CallGraphNode *getRoot() { return Root; }
+
+ CallGraphNode *getExternalCallingNode() { return ExternalCallingNode; }
void addTU(ASTUnit &AST);
typedef mapped_iterator<NodeType::iterator, CGNDerefFun> ChildIteratorType;
static NodeType *getEntryNode(GraphType *CG) {
- return CG->getEntry();
+ return CG->getExternalCallingNode();
}
static ChildIteratorType child_begin(NodeType *N) {
}
}
+CallGraph::CallGraph() : Root(0) {
+ ExternalCallingNode = getOrInsertFunction(Entity());
+}
+
CallGraph::~CallGraph() {
if (!FunctionMap.empty()) {
for (FunctionMapTy::iterator I = FunctionMap.begin(), E = FunctionMap.end();
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());