Tool (c/c++) for parsing/evaluating a c header file?

Started by
5 comments, last by bubu LV 12 years ago
Hi, I'm looking for a tool/library to parse a c header file, while also evaluating the preprocessor macros and any calculations like the values of enum items or any constant math expressions.(things usually done during compile time e.g."#define bla ~4 << 2").

I've been using swig with the xml output, but I find it painful to generate all the xml files, and then parsing them and calculating all the math expressions, enums, and then storing values of identifiers to be used in further math expression. Also swig has trouble with some uses of unions in structs as well.

I've been searching, but I haven't really found anything to fit that criteria. though there seems to be a lot of libaries out there that do parsing, so I am hoping that I've missed or overlooked one that could help me.

Thanks.
Advertisement
I haven't used it, so take this with a huge pinch of salt, but I believe this is one of the main use-cases for LLVM. See, for example, Writing an LLVM Pass.
[TheUnbeliever]

I haven't used it, so take this with a huge pinch of salt, but I believe this is one of the main use-cases for LLVM. See, for example, Writing an LLVM Pass.


Looks promising, thanks.

... taking forever to compile though :)
I use mcpp a standard c/c++ preprocessor to build my shader/xml files.

I use mcpp a standard c/c++ preprocessor to build my shader/xml files.


Looks pretty useful, but not enough for what I need.

I've given up on anything c/c++ based, can't get any of the libraries/tools to compile under windows/mingw/cygwin.

Python seems to have a few c parsing tools like pycparser, and it takes hardly any effort to install unlike c/c++.
gccxml ?
Boost.Wave

This topic is closed to new replies.

Advertisement