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

29.01.2014 Views

References [1] Mike Barnett and K. Rustan M. Leino. Weakest-precondition of unstructured programs. In Proceedings of the 6th ACM SIGPLAN-SIGSOFT workshop on Program analysis for software tools and engineering, PASTE '05, pages 8287, New York, NY, USA, 2005. ACM. [2] Yves Bertot and Pierre Castéran. Interactive Theorem Proving and Program Development. Coq'Art: The Calculus of Inductive Constructions. Texts in Theoretical Computer Science. Springer Verlag, 2004. [3] Jean-Christophe Filliâtre. Verifying two lines of C with Why3: an exercise in program verication. In Veried Software: Theories, Tools and Experiments (VSTTE), Philadelphia, USA, January 2012. [4] Thomas A. Henzinger, Ranjit Jhala, Rupak Majumdar, and Grégoire Sutre. Lazy abstraction. In Proceedings of the 29th ACM SIGPLAN-SIGACT symposium on Principles of programming languages, POPL '02, pages 5870, New York, NY, USA, 2002. ACM. [5] Koushik Sen, Darko Marinov, and Gul Agha. Cute: a concolic unit testing engine for c. In Proceedings of the 10th European software engineering conference held jointly with 13th ACM SIG- SOFT international symposium on Foundations of software engineering, ESEC/FSE-13, pages 263272, New York, NY, USA, 2005. ACM. [6] Glynn Winskel. The formal semantics of programming languages - an introduction. Foundation of computing series. MIT Press, 1993. 104

Chapter 12 Comments CIL has a very basic mechanism for tracking comments. In this chapter we'll see how to use it. CIL only sees comments when they are maintained in the output of the preprocessor. The preprocessor may be instructed to maintain comments in its output by using the -C switch to ciltutcc. Then, the comments in the source are collected by CIL's parser and placed in the array Cabshelper.commentsGA. commentsGA is a GrowArray.t of triples of type (Cabs.cabsloc × string × bool). The cabsloc is the source location of the comment. The string is the comment itself, and the bool is set aside for application bookkeeping. 12.1 tut12.ml In this example, we'll visit the AST and print out comments nearby instructions and statements, taking care to only print each comment once. This will be accomplished by extracting the source location from instructions and statements and then doing a binary search on the array of comments. The array of comments lives in the Cabshelper module. The locations of the comments are dened in terms of the Cabs.cabsloc record type. module GA = GrowArray module A = Cabs module CH = Cabshelper First, we'll need a few utility functions, some of which are hidden away in Tututil (e.g. functions for ordering source locations and comments). prepareCommentArray lters out comments not from source le fname, and sorts the results according to source location. let prepareCommentArray (cca : comment array) (fname : string) : comment array = cca | > array filter (fun (cl, , ) → fname = cl.A.filename) |> array sort result comment compare The funcion commentsAdjacent returns the indexes of at most two comments that are immediately 105

References<br />

[1] Mike Barnett and K. Rustan M. Leino. Weakest-precondition <strong>of</strong> unstructured programs. In<br />

Proceedings <strong>of</strong> the 6th ACM SIGPLAN-SIGSOFT workshop on Program analysis for s<strong>of</strong>tware<br />

tools and engineering, PASTE '05, pages 8287, New York, NY, USA, 2005. ACM.<br />

[2] Yves Bertot and Pierre Castéran. Interactive Theorem Proving and Program Development.<br />

Coq'Art: The Calculus <strong>of</strong> Inductive Constructions. Texts in Theoretical <strong>Computer</strong> <strong>Science</strong>.<br />

Springer Verlag, 2004.<br />

[3] Jean-Christophe Filliâtre. Verifying two lines <strong>of</strong> C with Why3: an exercise in program verication.<br />

In Veried S<strong>of</strong>tware: Theories, Tools and Experiments (VSTTE), Philadelphia, USA,<br />

January 2012.<br />

[4] Thomas A. Henzinger, Ranjit Jhala, Rupak Majumdar, and Grégoire Sutre. Lazy abstraction.<br />

In Proceedings <strong>of</strong> the 29th ACM SIGPLAN-SIGACT symposium on Principles <strong>of</strong> programming<br />

languages, POPL '02, pages 5870, New York, NY, USA, 2002. ACM.<br />

[5] Koushik Sen, Darko Marinov, and Gul Agha. Cute: a concolic unit testing engine for c. In Proceedings<br />

<strong>of</strong> the 10th European s<strong>of</strong>tware engineering conference held jointly with 13th ACM SIG-<br />

SOFT international symposium on Foundations <strong>of</strong> s<strong>of</strong>tware engineering, ESEC/FSE-13, pages<br />

263272, New York, NY, USA, 2005. ACM.<br />

[6] Glynn Winskel. The formal semantics <strong>of</strong> programming languages - an introduction. Foundation<br />

<strong>of</strong> computing series. MIT Press, 1993.<br />

104

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

Saved successfully!

Ooh no, something went wrong!