Using an AST as a higher level interface to LLVM: getting started

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Using an AST as a higher level interface to LLVM: getting started

Martin C. Martin-2
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
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Using an AST as a higher level interface to LLVM: getting started

Renato Golin
On 12 March 2010 18:30, Martin C.Martin <[hidden email]> wrote:
> How should I get started?

By reading the documentation, tutorials and FAQs:
http://llvm.org/docs/
http://llvm.org/docs/tutorial/
http://llvm.org/docs/FAQ.html
http://clang.llvm.org/get_started.html
http://clang.llvm.org/docs/UsersManual.html

I've done a similar "experimental project" last year, hope that helps:
http://www.systemcall.org/rengolin/stuff/compiler/
http://www.systemcall.org/rengolin/stuff/compiler/download/LLVM-pet-project.pdf


> 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?

Using regular pointers shouldn't be a problem... Normally, you build
the AST once, don't delete nodes, use it once and discard everything
altogether.


cheers,
--renato

http://systemcall.org/

Reclaim your digital rights, eliminate DRM, learn more at
http://www.defectivebydesign.org/what_is_drm
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev