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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With