[cfe-dev] Custom pragmas handling

Sylvain HENRY hsyl20 at gmail.com
Fri Oct 30 04:03:28 PDT 2009


Hi,

I would like to have a C compiler which can handle some custom
pragmas. For instance consider the following C file:

#pragma starpu interface
void foo();

#pragma starpu implements(foo)
void foo_v1() {...}

#pragma starpu implements(foo)
void foo_v2() {...}

I would like the compiler to transform it into:

void foo() {
   //do something with foo_v1() and/or foo_v2()
}
void foo_v1() {...}
void foo_v2() {...}

And finally compile it.

I have copied clang-cc and modified it to detect "starpu" pragmas by
adding a PragmaHandler to the preprocessor. However I have a few
questions:
1) Is there a non intrusive way (ie without modifying clang-cc or
clang) to add this kind a custom pragma handling in Clang? That would
be helpful to implement OpenMP too. Maybe a plan for some sort of
plugin system?
2) How can I determine in the PragmaHandler which function the pragma
applies to? Then, how can I modify the function's body to add some
statements? I think I could create a custom Action class, which would
perform AST modification in the appropriate ActOn* callbacks, and
replace the ParseAST call in clang-cc by a call to an other Parser
using my Action, but then how do I compile/ast-dump/...  the modified
AST?

Any help appreciated.
Thanks
-- Sylvain



More information about the cfe-dev mailing list