How to write a program using clang libraries to generate the AST and the CFG of C source code

Hello,

I am trying to write a program using clang libraries to generate the AST and the CFG of C source code, For example,

int foo(int x){

x=x+1;

if(x>2)x++;

else{

x+=2;

x*=2;

}

return x;

}

Using “clang –cc1 –ast-dump foo.c” can generate the AST of foo.c

Using “clang –cc1 –analyze –analyzer-checker=debug.DumpCFG foo.c” can generate the CFG of foo.c

But I dont know which libraries should be used and I dont know how to write my own program using the libraries to generate the AST and the CFG of C source code

Are there any documents about how to use the libraries?

Besh Wishes

Raymond Chen

ECNU