29.01.2014 Views

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

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER 4. INSTRUMENTATION 37<br />

type functions = {<br />

mutable begin loop : varinfo;<br />

mutable end loop : varinfo;<br />

}<br />

A dummy varinfo that we can use to initialize the functions record<br />

let dummyVar = makeVarinfo false " tut foo" voidType<br />

tutfuns is an instance <strong>of</strong> the record type functions that lets us quickly refer to the varinfos for<br />

our instrumentation functions.<br />

let tutfuns = {<br />

begin loop = dummyVar;<br />

end loop = dummyVar;<br />

}<br />

We set up some variables for the names <strong>of</strong> the instrumentation functions so that we only have one<br />

string to change if the name <strong>of</strong> the functions changes in the C code.<br />

let begin loop str = "tut begin loop"<br />

let end loop str = "tut end loop"<br />

We may wish subsequent passes over the code to ignore calls to instrumentation that we have added.<br />

To make that easier, we dene a list <strong>of</strong> the function names, tut function names, and a function<br />

isTutFun that tells if a function is an instrumentation call.<br />

let tut function names = [<br />

begin loop str;<br />

end loop str;<br />

]<br />

let isTutFun (name : string) : bool =<br />

L.mem name tut function names<br />

The function mkFunTyp is a helper function for making simple function types. It can be used when<br />

arguments and the function type itself have no attributes.<br />

let mkFunTyp (rt : typ) (args : (string × typ) list) : typ =<br />

TFun(rt, Some(L.map (fun a → (fst a, snd a, [ ])) args), false, [ ])<br />

The function initTutFunctions initializes the tutfuns record.<br />

function:<br />

It does this by calling the Cil

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

Saved successfully!

Ooh no, something went wrong!