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 3. DATAFLOW ANALYSIS 24<br />
The function varmap list pretty uses the functions string <strong>of</strong> varmap list and Pretty.text<br />
to convert a varmap list to a doc:<br />
let varmap list pretty () (vml : varmap list) =<br />
vml | > string <strong>of</strong> varmap list | > text<br />
3.1.3 Functions for manipulating kinds and states<br />
Now, we must dene some functions that manipulate lists <strong>of</strong> varmaps, culminating in the functions<br />
varmap list combine and varmap list replace. varmap list combine nds the least-upperbound<br />
<strong>of</strong> two varmap lists. This function is responsible for determining the abstract state <strong>of</strong> the<br />
program at a join point. varmap list replace adds or replaces a mapping from the varmap list.<br />
It is used in the transfer function for assignments.<br />
The function oekind neg gets the opposite kind:<br />
let oekind neg (k : oekind) : oekind =<br />
match k with<br />
| Even → Odd<br />
| Odd → Even<br />
| → k<br />
The function varmap equal checks if two varmap's are exactly the same:<br />
let varmap equal (vm1 : varmap) (vm2 : varmap) : bool =<br />
(id <strong>of</strong> vm vm1) = (id <strong>of</strong> vm vm2) ∧<br />
(kind <strong>of</strong> vm vm1) = (kind <strong>of</strong> vm vm2)<br />
The function varmap list equal checks that two varmap lists are exactly the same. We sort the<br />
lists rst because order doesn't matter.<br />
let varmap list equal (vml1 : varmap list) (vml2 : varmap list) : bool =<br />
let sort = L.sort (fun (id1, ) (id2, ) → compare id1 id2) in<br />
list equal varmap equal (sort vml1) (sort vml2)<br />
The function oekind includes denes the partial order for our lattice:<br />
• Bottom, Odd, Even < Top<br />
• Bottom < Odd, Even<br />
• But Even Odd