29.01.2014 Views

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

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER 3. DATAFLOW ANALYSIS 33<br />

test/tut3.c:19:<br />

test/tut3.c:19:<br />

(c, Even)<br />

(d, Even)<br />

Since the program is small, we can check by inspection that the results <strong>of</strong> the analysis are correct.<br />

Note, however, that for the variable a at line 19, the result is Top. This occurs because the analysis<br />

made no attempt to interpret the guard <strong>of</strong> the if-statement on that line. Thus, at the join point<br />

after the if-statement, as far as this analysis knows, a could be either Even or Odd.<br />

3.3 Exercises<br />

1. Create an option in src/ciltutoptions.ml that controls whether debugging information for<br />

the analysis is printed.<br />

2. We could represent the mapping from variables to oekinds many other ways. If the analysis<br />

had to be super-fast, we could use bitsets. Then, the abstract state would be four bitsets,<br />

one for each oekind, with each local variable <strong>of</strong> integral type belonging to exactly one <strong>of</strong> the<br />

bitsets. Note the Bitmap module in cil/ocamlutil/bitmap.ml.<br />

3. In oekind <strong>of</strong> unop for the LNot case, there are two cases e = 0 and e ≠ 0. If we know<br />

that e will be zero, then !e will be 1 and therefore Odd. If we know that e will be non-zero,<br />

then !e will be zero and therefore Even. If we don't know anything about e, then !e is Top as<br />

we have here. Modify this analysis to also track whether variables are zero or non-zero. (Such<br />

an analysis can have wider applications. Think about pointers.)<br />

4. There are a number <strong>of</strong> other binary operations. Figure out how to handle them in oekind <strong>of</strong> binop.<br />

item Modify the analysis to handle not only local variables, but also global variables. What<br />

should their initial state be? How would the analysis change in the presence <strong>of</strong> multiple<br />

threads?<br />

5. Implement the doGuard function <strong>of</strong> OddEvenDF so that the analysis may conclude that a is<br />

Even at line 19.<br />

Project: Add another layer <strong>of</strong> generalization on top <strong>of</strong> <strong>CIL</strong>'s Dataflow functors<br />

so that one must only dene the functions operating on the abstract state<br />

(and possibly also a function for giving the initial state for a function.) One<br />

should then get a function for invoking the analysis and a visitor class for visiting<br />

the AST with the results <strong>of</strong> the analysis. (Essentially everything from<br />

the module OddEvenDF and down to the end <strong>of</strong> vmlVisitorClass, except for<br />

collectVars, should be automatic).

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!