Quantcast

Source transformations in frontend plugin before compilation

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Source transformations in frontend plugin before compilation

Lang Hames via cfe-dev
Hi all,

I want to annotate malloc(sizeof(ty)) calls with the type in the sizeof so that I can use the information in the IR later on (in a transformation plugin). My current approach is to do a somewhat hacky source transformation, replacing the call with:
  malloc(({ ty * volatile ptr = NULL; (size_t)(ptr + 1); }))
so that I can take the pointer type and replace the size back with a constant in the IR.

If someone can think of a better way to do this inside a clang frontend plugin, I'm open to that, but currently I'm having issues just getting this to work. I have a working plugin that finds the sizeof expressions and a Rewriter instance that replaces them. However, I don't know how to apply the changes to the input file so that the input with be parsed again before being passed on to the codegen. There is a Reparse function in ASTUnit, but I cannot find (in the docs or online) how this is supposed to be used.
Does anyone know how to correctly use this?

Cheers,
Taddeüs

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Source transformations in frontend plugin before compilation

Lang Hames via cfe-dev
Taddeus,

Maybe you will find this thread useful: [cfe-dev] AST modifications that apply to the binary
http://lists.llvm.org/pipermail/cfe-dev/2016-November/051668.html

~Jakub

On 4 May 2017 at 13:58, Taddeus via cfe-dev <[hidden email]> wrote:
Hi all,

I want to annotate malloc(sizeof(ty)) calls with the type in the sizeof so that I can use the information in the IR later on (in a transformation plugin). My current approach is to do a somewhat hacky source transformation, replacing the call with:
  malloc(({ ty * volatile ptr = NULL; (size_t)(ptr + 1); }))
so that I can take the pointer type and replace the size back with a constant in the IR.

If someone can think of a better way to do this inside a clang frontend plugin, I'm open to that, but currently I'm having issues just getting this to work. I have a working plugin that finds the sizeof expressions and a Rewriter instance that replaces them. However, I don't know how to apply the changes to the input file so that the input with be parsed again before being passed on to the codegen. There is a Reparse function in ASTUnit, but I cannot find (in the docs or online) how this is supposed to be used.
Does anyone know how to correctly use this?

Cheers,
Taddeüs

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev




--
Jakub Kuderski

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Loading...