A utility to build a call graph given a C translation unit.
A call graph is a map from function names to the set of all functions which are called in the original function's body. For instance, consider the following C source file:
void bar(void); void foo(int x) { foo(x); bar(x); } void bar(int x) { foo(x); } int baz(int z) { if (z) { return z; } return baz(z - 1); } int main() { int x = 5; return foo(x); }
The call graph for this function would associate
If a call graph edge connects a function to itself, this function is directly recursive. We may also construct the transitive closure of the call graph given some initial function call-graph-transitive-closure). This closure represents all functions which are reachable through some path of function calls. Notably, a mutually recursive function is in its own transitive closure. See direct-recursivep and recursivep.
Note that call graph construction currently only recognizes direct
function calls. No sort of analysis is done to attempt to resolve calls
of dereferenced function pointers. We may wish to add such analysis in
the future. Although the problem is undecidable in general, many common
cases may be straightforward in practice. Currently, a call of a
function pointer is represented as