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 93<br />
let initOps (it : Th.theory) (dt : Th.theory) (mt : Th.theory) : ops =<br />
{iplus op = Th.ns find ls it.Th.th export ["infix +"];<br />
iminus op = Th.ns find ls it.Th.th export ["infix -"];<br />
(∗...∗)<br />
}<br />
The function initWhyCtxt initializes the Why3 context and directs it to use the prover specied<br />
by the string p. It uses the Why3 API to read its conguration, load its plug-ins, nd the specied<br />
prover, and load the theories we'll need into the wctxt.<br />
let initWhyCtxt (p : string) (pv : string) : wctxt =<br />
(∗ ... ∗)<br />
As with the other attributes in previous chapters, we introduce global variables for string constants<br />
for the attribute syntax.<br />
let invariantAttrStr = "invariant"<br />
let postAttrStr = "post"<br />
let preAttrStr = "pre"<br />
let tut11 attrs = [invariantAttrStr; postAttrStr; preAttrStr; ]<br />
The functions term <strong>of</strong> int and term <strong>of</strong> int64 convert OCaml integers (which we'll extract from<br />
the <strong>CIL</strong> AST) into Why3 terms.<br />
let term <strong>of</strong> int (i : int) : T.term = i | > string <strong>of</strong> int | > T.t int const<br />
let term <strong>of</strong> i64 (i : int64) : T.term = i | > Int64.to string | > T.t int const<br />
We'll use the functions make symbol and freshvar <strong>of</strong> ap to make fresh symbols for the variables<br />
bound by quantiers that appear in attribute parameters.<br />
let make symbol (s : string) : T.vsymbol =<br />
T.create vsymbol (W.Ident.id fresh s) W.Ty.ty int<br />
let freshvar <strong>of</strong> ap (ap : attrparam) : string × T.vsymbol =<br />
match ap with<br />
| ACons(n, [ ]) → n, make symbol n<br />
| → Em.s(Em.error "Names only")<br />
The function term <strong>of</strong> attrparam converts an attribute parameter into a Why3 term. For variable<br />
references, it looks up symbols in the vars eld <strong>of</strong> the context. For binary and unary operations, it<br />
uses the operations dened in the ops eld.<br />
For memory references it uses the get and set operations and the memory eld <strong>of</strong> the context to<br />
generate the appropriate Why3 terms. In particular, memory is modeled as one large array indexed