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 2. VISITING THE AST 18<br />
Coding Hint: The inx function |> has type (α → (α →<br />
β) → β). The code in tut2 is another way <strong>of</strong> writing<br />
iterGlobals f (onlyFunctions (processFunction funvar)) but without<br />
all the extra parenthesis. |> is included in the F# standard library,<br />
but since it isn't in OCaml's we dene it in Tututil. You can read it as<br />
expression on the left is passed to function on right, and we can chain them<br />
up like I have in tut2 without writing lots <strong>of</strong> extra parenthesis.<br />
let tut2 (funvar : string × string) (f : file) : unit =<br />
funvar | > processFunction | > onlyFunctions | > iterGlobals f<br />
2.2 test/tut2.c<br />
In main.ml tut2 in tut2.ml is called with argument ("foo","bar") meaning that assignments to<br />
global variables called bar should be removed from functions called foo. Thus, when the code below<br />
is compiled with tut2 enabled, the program should print 37 and exit.<br />
# include <br />
int bar = 37;<br />
int foo()<br />
{<br />
int l;<br />
bar = 0;<br />
l = bar;<br />
return l;<br />
}<br />
int main()<br />
{<br />
int r;<br />
r = foo();<br />
printf("r = %d\n", r);<br />
return 0;<br />
}<br />
../test/tut2.c<br />
As with test/tut1.c, we can build this le with the following command: