[cfe-dev] [Beginner] Rewriting AST based on custom pragma

Julian Dunskus via cfe-dev cfe-dev at lists.llvm.org
Thu Aug 2 09:18:08 PDT 2018


Hi Everyone!

I hope this is the right place to ask this (if not, please redirect me to a more appropriate place). As written in the subject, I’d like to rewrite the AST of a C program based on custom pragmas. Specifically, I’d like to relate identifiers given in the pragma to variables in the scope (checking if they’re present, first of all, and more things later on) and extract code to functions, passing the function pointers to a utility in its place. I hope that gives you an idea of the extent of my modifications.

I’ve downloaded and compiled clang (+ llvm) and implemented a PragmaHandler which checks the format of the pragma contents and extracts certain identifiers from them. However, I haven’t found much information on all this (the most reliable source being the examples included with the source), and I’d like to do a quick sanity check that I’m actually approaching this correctly. A PragmaHandler seemed to be the simplest solution, but I’m not sure I can do all the rewriting and semantic analysis I’d like from there.

Do I need to implement a full-fledged plugin in order to rewrite the AST? If so, should I still use a PragmaHandler at all? Is there another option entirely which I should consider? I’m really new to this, but eager to learn and improve :)

Thanks in advance,
–Julian Dunskus


More information about the cfe-dev mailing list