[cfe-dev] Clang Library

Charles Davis cdavis at mymail.mines.edu
Tue Feb 16 16:23:15 PST 2010

Glenn R. Martin wrote:
> I am currently working on a personal project that would use on demand
> compilation of C code to load in new modules. I have been looking at
> clang and llvm and it seems like it has the capability to provide this
> ability. Is there anywhere i can look to see how i would be able to
> accomplish this programmatically? I have gone through the documentation
> on the Clang site as well as downloading and reviewing the source code
> from SVN. I have not seen anything directly on accessing the C
> preprocessing/compiler functionality programmatically.
There's several different objects you need to look into creating:

- Preprocessing is handled by a Preprocessor object.
- If you want to compile C code, you need to create an ASTContext (in
addition to a Preprocessor).
- The Sema (SEMAntic analyzer) object handles semantic checking, etc.
- The CodeGen library turns a fully-annotated AST into LLVM IR, which
you can then pass to LLVM libraries (like LLVM CodeGen and the Target
family) to generate executable code.
- The Frontend library handles much of the tedious process of setting up
these objects for you. In particular, look into the "CompilerInvocation"
and "CompilerInstance" classes.



More information about the cfe-dev mailing list