邓淏仁
邓淏仁

Reputation: 49

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?

Upvotes: 4

Views: 1985

Answers (1)

Booo
Booo

Reputation: 503

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.

Upvotes: 2

Related Questions