Index of /~cram/cse637/Notes
C-to-AST
Click here for the tool for dumping C programs into AST in Prolog.
Only the pre-compiled binary for RedHat 9 is in there. Binaries for
other Linux systems and Solaris can be produced as requested. The source code
is also available for those who want deal with Ocaml and CIL by themselves.
A readme is in the end of this message.
Please tell me your comments on the AST syntax as well as any bugs of the
tool. Thanks.
-Wei Xu
----------------------------------------------------------------------------------
README
C2AST is a tool for dumping C programs into AST in Prolog. It is
implemented based on CIL (http://manju.cs.berkeley.edu/cil/).
To use C2AST, please first run
./configure
to set up proper program paths. After that you can use
bin/c2ast
wherever gcc appears. The AST output file is specified by the "--out"
option.
There are three examples (rfib.c, swap.c, and matrix.c) in the test/
directory. Running
make test
in the C2AST directory will produce the corresponding AST files (rfib.P,
swap.P, and matrix.P) for the C programs. You may see error messages
like "undefined reference to `main'" during compilation. They are normal
and can be safely ignored.
Syntax of AST (By Examples)
===========================
1. Program
prog(globals([v1,v2,v3]), functions([f1,f2]), entry(s10)).
2. Functions
func(f1, fn_main, formals([]), locals([v5,v6]), entry(s10)).
3. Variables
var(v1, global_a).
var(v5, local_main_i).
4. Statements
stmt(s1, skip).
stmt(s5, assign(e2,e9)).
stmt(s6, call(e1,e5,[e6,e7]).
stmt(s7, if(e6,s11,s12)).
stmt(s9, while(e8,s15)).
stmt(s10, return(e20)).
stmt(s12, block([s5,s7])).
stmt(s14, goto(s1)).
5. Expressions
expr(e1, number(1)).
expr(e3, string('Hello')).
expr(e2, variable(global_a, [idx(e1)])).
expr(e6, variable(local_main_s, [field(fld_name), idx(e1)])).
expr(e7, deref(e2, [field(val_name)])).
expr(e9, addrof(e6)).
expr(e10, not(e1)). % Unary Ops: neg, not, bitnot
expr(e11, add(e7, e1)). % Binary Ops: add, sub, mul, div, mod,
% greater, less, equal,
% geq, leq, neq, and, or,
% bitand, bitor, bitxor,
% lshift, rshift