Dynamic hardware with Clang

I am trying to speed up the use of Clang by executing a bit of dynamic code toolkit using C (and possibly C ++), where I take the source file and generate the instrumental output. I would like to add a function call at the beginning of any block, and also change all Boolean expressions to call some function so that I can track this too. For instance:

foo = a && (b || c); 

will become something like:

 foo = EXPR_AND(a, EXPR_OR(b, c)); 

and therefore I can track all combinations of conditions that occur.

I suppose using RecursiveASTVisitor would be a better approach, but is there an easy way to output C code for every node I visit?

Any suggestions on what to look for in order to do something like this will be most appreciated!

Note. After some further research, I just opened libclang, which looks like it might be my best friend. Combined with a rewriter, I can just have what I need. Any pointers to good examples (I just found some great Apple developers who put together videos on libclang) would be great.

+6
source share
1 answer

For a good example, see this project .

It uses clang to enter and exit instrumental calls, and also checks the types of arguments passed.

+2
source

Source: https://habr.com/ru/post/906498/


All Articles