[cfe-dev] Using Clang AST classes to generate LLVM IR for a compiler front-end

João Matos ripzonetriton at gmail.com
Mon Dec 24 15:55:57 PST 2012


On Mon, Dec 24, 2012 at 7:31 PM, Sean Silva <silvas at purdue.edu> wrote:

> Longer explanation: I have not heard of anybody directly creating
> Clang AST's for a foreign language, and I don't think that the AST API
> is meant for doing that. If you want to directly build AST's, it
> should be relatively straightforward (at a high level) to just
> instantiate the AST classes (in include/clang/AST) and link them
> together in "appropriate ways". However, although I do not have superb
> knowledge of the AST, my belief is that you will run into a lot of
> "devil is in the details" problems due to unspoken invariants in the
> AST which makes "link them together in "appropriate ways"" very hard
> to achieve.


I've done something like this. I create a (fake) AST from the metadata in
.NET DLLs for an implementation of the C++/CLI standard. As you say the
devil is in the details, and I had to read and debug lots of problems due
to the rest of Clang expecting some AST invariants that are not exactly
obvious. Still it's a nice approach since you get the rest of the compiler
basically for free. You might have to extend the AST / IR gen to support
some different details of your language, but overall I would say this
approach works fine and saves you a lot of work.



-- 
João Matos
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20121224/097866a9/attachment.html>


More information about the cfe-dev mailing list