[cfe-dev] Using an AST as a higher level interface to LLVM: getting started

Martin C.Martin martin at martincmartin.com
Fri Mar 12 10:30:19 PST 2010


Hi,

For an experimental project at work, I want to try my hand at code 
generation.  For the moment, I want my program to generate ASTs, not get 
them by parsing C files.  Then I'd like to translate them into code and 
call into them.  This is all on amd64.  For now Linux, if it proves 
successful, Windows as well.

How should I get started?  A couple questions:

- How easy is it to create an AST?  Can I just new the nodes I need and 
point them at each other?  Is there any non-obvious setup I need to do 
first?

- If I want to see the AST that corresponds to a given C construct, is 
here a way to hack clang to print out the AST?  Where would I put that 
function?

- Once I have my AST, how do I compile it, load it & run it?

Best,
Martin



More information about the cfe-dev mailing list