[cfe-dev] LLVM IR Question

Chris Lattner clattner at apple.com
Fri Jun 11 10:28:14 PDT 2010


On Jun 11, 2010, at 10:18 AM, Kyle Girard wrote:

> I've just stumbled upon clang and have been reading the documentation
> and such and I have a couple of questions that I'm hoping someone can
> answer and save me some time.  
> 
> I am playing around with converting C/C++ files into a format that is
> very similar to the LLVM IR output however I still need some information
> that I believe is only found in the AST.  Can clang give me the ability
> to iterate through the LLVM IR statements and still reference original
> source lines in the AST?  

No, not really.  However, you can add stuff to the Clang "codegen" library, which is the part responsible for building LLVM IR from the AST.  This gives you access to both at the same time.

> If that is possible how exactly do I access this information?  I've
> looked at the clang-interpreter example and it would be similar to what
> I thought of doing just the my interpreter would output my type of file.

When debug information is enabled, clang does attach debug metadata to the instructions it generates.  This only gets you file/line/col information though, not full AST mapping.

-Chris



More information about the cfe-dev mailing list