Add new types and functions to the program

Hi there,

this may be a dumb question, but we would like to add new types and new functions to the Clang AST. Just wondering if it is possible to do this since we are aware that the Clang AST is immutable. We somehow need more control to the AST rather than source level editing. Could anyone give us some ideas whether Clang is the right infrastructure to use or not?

Thank you very much in advance!

– Weiwei

How is this semantically different from sticking in a header at the top of the file? Can you use -include to just add code to every TU you care about?

Thanks for the response, Reid!

Yes, your suggestion is perfectly reasonable if the new types and functions are stand alone ones. However, our project may need to instrument / recode the program based on the knowledge / analysis of the code. For instance, to add wrapper functions for existing functions, add intermediate variables, or even change the control flow of the program for architecture mapping and optimization purpose. We are doing some surveys to decide which infrastructure is the best fit for our project. We would very much like to use Clang, but wanna make sure there won’t be too much hurdle to achieve our goal.

– Weiwei