[cfe-dev] Once I have an AST, how do I compile it?

Eli Friedman eli.friedman at gmail.com
Tue Apr 6 12:32:13 PDT 2010


On Tue, Apr 6, 2010 at 9:02 AM, Martin C.Martin
<martin at martincmartin.com> wrote:
> On 4/5/2010 4:58 PM, Eli Friedman wrote:
>>
>> On Mon, Apr 5, 2010 at 1:06 PM, Martin C.Martin
>> <martin at martincmartin.com>  wrote:
>>>
>>> I've managed to create a test program, included below for the curious,
>>> which creates a super simple AST corresponding to "void foo() { }".
>>> What do I call to generate code from it?  Any pointers on what
>>> classes/files to look at?
>>
>> Call CreateLLVMCodeGen in include/clang/CodeGen/ModuleBuilder.h to get
>> an ASTConsumer, then call the appropriate APIs (see
>> include/clang/AST/ASTConsumer.h) to make it generate code.
>>
>> -Eli
>
> Thanks Eli.  What's the memory contract?  Should I call delete on
> CreateLLVMCodeGen()'s value when I'm done with it?

Yes, delete to clean up (or use an llvm::OwningPtr).

-Eli




More information about the cfe-dev mailing list