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 10. ADDING A NEW KIND OF STATEMENT 82<br />

let isCacheReportStmt (s : stmt) : block option =<br />

match s.skind with<br />

| If(CastE(t, z), b, , ) when z = zero ∧ isCacheReportType t → Some b<br />

| Block b when hasCacheReportAttrs b.battrs → Some b<br />

| → None<br />

Now, if we make the following macro:<br />

#define cache report if((void * attribute ((cache report)))0)<br />

We can write code like the following:<br />

cache report {<br />

...<br />

}<br />

Alternately (or in addition), if we make the following macro:<br />

#define CACHE REPORT blockattribute ((cache report))<br />

We can write code like the following:<br />

{ CACHE REPORT<br />

...<br />

}<br />

The above syntactic constructs will be replaced by calls to two functions, one at the beginning<br />

<strong>of</strong> the block <strong>of</strong> code we want to prole, and one at the end.<br />

We create instrumentation functions just as we did back in Chapter 4, so we just include the<br />

code here that builds the function call instructions.<br />

The functions are dened in ciltut-lib/src/tut10.c and set up using the function initCacheFunctions.<br />

The function makeCacheReportStmts builds the function calls for source location loc, and returns<br />

a pair <strong>of</strong> statements containing the instructions.<br />

let makeCacheReportStmts (loc : location) : stmt × stmt =<br />

let f, l = mkString loc.file, integer loc.line in<br />

i2s (Call(None, v2e cachefuns.cache begin, [f; l; ], loc)),<br />

i2s (Call(None, v2e cachefuns.cache end, [f; l; ], loc))

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

Saved successfully!

Ooh no, something went wrong!