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 11. PROGRAM VERIFICATION 95<br />
The functions term <strong>of</strong> apuop and term <strong>of</strong> apbop translate AUnOp and ABinOp attribute parameters<br />
into Why3 terms.<br />
and term <strong>of</strong> apuop (wc : wctxt) (u : unop) (ap : attrparam) : T.term =<br />
let te = term <strong>of</strong> attrparam wc ap in<br />
match u with<br />
| Neg → T.t app infer wc.ops.iminus op [(term <strong>of</strong> int 0); te]<br />
| LNot → T.t equ te (term <strong>of</strong> int 0)<br />
| BNot → Em.s (Em.unimp "Attribute BNot: £%a\n" d attrparam ap)<br />
and term <strong>of</strong> apbop (wc : wctxt) (b : binop) (ap1 : attrparam) (ap2 : attrparam) : T.term =<br />
let te1 = term <strong>of</strong> attrparam wc ap1 in<br />
let te2 = term <strong>of</strong> attrparam wc ap2 in<br />
match b with<br />
| PlusA | PlusPI | IndexPI → T.t app infer wc.ops.iplus op [te1; te2]<br />
| MinusA | MinusPI | MinusPP → T.t app infer wc.ops.iminus op [te1; te2]<br />
(∗ ... ∗)<br />
| → Em.s (Em.error "term <strong>of</strong> bop failed: %a %a %a\n"<br />
d attrparam ap1 d binop b d attrparam ap2)<br />
The function term <strong>of</strong> star translates a memory referene in an attribute parameter into a Why3<br />
get operation <strong>of</strong> the address in the memory map <strong>of</strong> the Why3 context.<br />
and term <strong>of</strong> star (wc : wctxt) (a : attrparam) : T.term =<br />
let at = term <strong>of</strong> attrparam wc a in<br />
let mt = T.t var wc.memory in<br />
T.t app infer wc.ops.get op [mt; at]<br />
The function term <strong>of</strong> index is similar to term <strong>of</strong> star. First, though, we have to calculate the<br />
address by adding the index to the base pointer.<br />
and term <strong>of</strong> index (wc : wctxt) (base : attrparam) (index : attrparam) : T.term =<br />
let bt = term <strong>of</strong> attrparam wc base in<br />
let it = term <strong>of</strong> attrparam wc index in<br />
let addr = T.t app infer wc.ops.iplus op [bt; it] in<br />
let mt = T.t var wc.memory in<br />
T.t app infer wc.ops.get op [mt; addr]<br />
The function oldvar <strong>of</strong> ap nds the Why3 symbol for a variable in the context.<br />
let oldvar <strong>of</strong> ap (wc : wctxt) (ap : attrparam) : T.vsymbol =<br />
match ap with<br />
| ACons(n, [ ]) → SM.find n wc.vars<br />
| → Em.s(Em.error "Names only")