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
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
CHAPTER 11. PROGRAM VERIFICATION 99<br />
and term <strong>of</strong> loop (wc : wctxt) (b : block) : T.term → T.term =<br />
let test, body = L.hd b.bstmts, L.tl b.bstmts in<br />
let body block = body | > L.hd | > force block in<br />
let bf = term <strong>of</strong> block wc (mkBlock (body block.bstmts @ (L.tl body))) in<br />
let ct, li, lvl = inv <strong>of</strong> attrs wc body block.battrs in<br />
let lvl' = wc.memory :: lvl in<br />
(fun t → t<br />
|> T.t if ct (bf li) (∗ if c then V C(b, inv) else t ∗)<br />
|> T.t implies li (∗ inv => previous line ∗)<br />
|> T.t forall close lvl' [ ] (∗ ∀ x1,...,x n<br />
(previous line) ∗)<br />
|> T.t and li) (∗ inv ∧ previous line ∗)<br />
The function term <strong>of</strong> block folds over the statements <strong>of</strong> a block, processing the last statement<br />
rst, to generate a continuation for the VC.<br />
and term <strong>of</strong> block (wc : wctxt) (b : block) : T.term → T.term =<br />
L.fold right (term <strong>of</strong> stmt wc) b.bstmts<br />
The function vsymbols <strong>of</strong> function collects the Why3 symbols for the formal parameters to a<br />
function in addition to the symbol for the memory.<br />
let vsymbols <strong>of</strong> function (wc : wctxt) (fd : fundec) : T.vsymbol list =<br />
fd.sformals<br />
|> L.map (fun vi → vi.vname)<br />
|> sm find all wc.vars<br />
|> L.append [wc.memory]<br />
If there is a precondition, the function pre impl t returns a continuation that generates a term in<br />
which the precondition implies the VC generated for the function body and the term. Otherwise,<br />
it simply gives the continuation that generates the VC for the function body and the term.<br />
let pre impl t (wc : wctxt) (fd : fundec) (pre : T.term option) : T.term → T.term =<br />
match pre with<br />
| None → term <strong>of</strong> block wc fd.sbody<br />
| Some pre → (fun t → T.t implies pre (term <strong>of</strong> block wc fd.sbody t))<br />
Finally the function vcgen generates a function that will take the function postcondition as the<br />
argument and produce the verication condition for the function. It does this by quantifying over<br />
the memory and formal parameters as given by vsymbols <strong>of</strong> function, with the VC continuation<br />
for the function body given by pre impl t.