Creating call graphs for C and FORTRAN programs

From ASCEND
Jump to: navigation, search

Creating a call graph for C or FORTRAN program is pretty simple using GCC.

For both FORTRAN and C programs, the trick is to compile the program using the compiler flag -fdump-rtl-expand (see documentation).

Once the program is compiled, a file with a name like solergya.f.144f.expand will be created.

That file can be easily processed using the Perl-based utility egypt. Download egypt 1.10 from here or use our local copy, egypt-1.10.tar.gz, and to install it use

tar zxvf egypt-1.10.tar.gz
cd egypt-1.10
perl Makefile.PL
make
sudo make install

For example, to generate a call graph for the FORTRAN 77 program SOLERGY, the following SConstruct file will build the program and generate the RTL (*.expand) file:

env = Environment()
env.Append(FORTRANFLAGS=["-fdump-rtl-expand"])
env.Program("solergy","solergya.f")

Then, use egypt to convert the RTL file into a nice GraphViz diagram:

egypt solergya.f.144r.expand | dot -Tpng > callgraph.png

The result is a nice callgraph like so:

Callgraph for the SOLERGY program, written in FORTRAN 77

You can use exactly the same approach for C programs. In the sample SConstruct file, just change FORTRANFLAGS to CFLAGS and change the name of the source code file accordingly.