16

For a long time now I've been using pygccxml to parse and introspect my C++ source code: it helps me to do some clever code-generation during our build process.

Recently I've read a lot about the benefits of the LLVM stack, and especially the benefits that the LLVM Clang parser brings to C++ compilation. I am now wondering if there is any Python interface to Clang such that I could use it as the basis for some of my existing code generation tasks?

4
  • Maybe you could try generating an interface with SWIG? Commented Jul 26, 2010 at 20:41
  • 1
    @Zifre: Actually it's the other way around...I'm trying to generate SWIG interfaces so I need to introspect the C++ code I want to wrap. I used pygccxml for this right now...I'd like to use something LLVM-based. Commented Jul 27, 2010 at 6:42
  • No, I meant generating Python bindings for the Clang libraries using SWIG. You might want to try this if the real Python bindings you found are too incomplete (but SWIG generated bindings are generally harder to use, since they directly mirror the C/C++ API). Commented Jul 27, 2010 at 15:08
  • 2
    @Zifre: ahhh, I'm with you now. And yes, I know a fair bit about our old friend (or foe depending on your inclination) SWIG. Thanks for the idea though....I think I'll wait for something more mature to appear before looking at this properly. Commented Jul 27, 2010 at 17:03

1 Answer 1

5

After further digging I found that in the LLVM 2.7 release there could be the beginings of something useful:

In the LLVM 2.7 time-frame, the Clang team has made many improvements....

CIndex API and Python bindings: Clang now includes a C API as part of the CIndex library. Although we make make some changes to the API in the future, it is intended to be stable and has been designed for use by external projects. See the Clang doxygen CIndex documentation for more details. The CIndex API also includings an preliminary set of Python bindings.

I'm not sure how useful this is in practice, certainly it looks like it could be the foundation for building a pygccxml equivalent based on LLVM but it is not in itself such a library.

Sign up to request clarification or add additional context in comments.

1 Comment

I wanted to see how feasible this was now a few months have gone by: from the look of this python module (llvm.org/svn/llvm-project/cfe/trunk/bindings/python/clang/…) it looks like it's totally feasible to do now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.