Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to save the clang AST?

I am working on some project which needs to using the AST of c code. And i am thinking about using the clang. Such as,

clang -Xclang -ast-dump file_name.c
clang -Xclang -ast-print file_name.c

However, those command only can print the ast to the command. How can i save the AST as a file, such as .xml?

like image 261
邓淏仁 Avatar asked Oct 19 '25 08:10

邓淏仁


1 Answers

libclang allows you to save a parsed translation unit into a serialized representation that can later be read back into memory. Have a look at clang_saveTranslationUnit and clang_parseTranslationUnit2. Similar tools exist for Python bindings.

like image 66
Booo Avatar answered Oct 21 '25 23:10

Booo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!