A CIL Tutorial - Department of Computer Science - ETH Zürich
A CIL Tutorial - Department of Computer Science - ETH Zürich
A CIL Tutorial - Department of Computer Science - ETH Zürich
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Chapter 13<br />
Whole-program Analysis<br />
<strong>CIL</strong> has a simple mechanism for allowing whole-program analysis. This mechanism is invoked when<br />
the --merge switch is passed to ciltutcc. First, in the compilation phase, instead <strong>of</strong> compiling<br />
source code to an object le with the back-end compiler, the emitted .o le will contain the preprocessed<br />
source. Then, in the link stage, ciltutcc parses the .o les, and uses the <strong>CIL</strong> Mergecil<br />
module to combine the separate source les into a single Cil.file. More details <strong>of</strong> this process can<br />
be found in the ocial <strong>CIL</strong> documentation.<br />
13.1 tut13.ml<br />
In this tutorial, we'll see how to compute a whole-program call graph. The code in thie module is very<br />
simple since there is already a pretty good module for computing call graphs in cil/src/ext/callgraph.ml.<br />
Additionally, we'll use the ocamlgraph library to output a .dot le, which can be used to generate<br />
an image <strong>of</strong> the call-graph.<br />
module H = Hashtbl<br />
module CG = Callgraph<br />
This module uses the Ocamlgraph library, which must be installed to build the code for this tutorial.<br />
Here, we use its functorial interface to dene a module for functions on a graph type that mirrors<br />
the graph we get back from the Callgraph module.<br />
module SG = Graph.Imperative.Digraph.ConcreteBidirectional(struct<br />
(∗ ... ∗)<br />
end)<br />
We'll also need to dene a module that extends the graph module above with functions to dene<br />
properties <strong>of</strong> vertices used by Dot to draw the graph. We'll just use the defaults. These functions<br />
can be modied to add more information to the graph.<br />
110