[cfe-dev] Adding custom pragma to Clang

Alexandre Isoard via cfe-dev cfe-dev at lists.llvm.org
Tue Aug 23 05:18:01 PDT 2016


Hi,

It might be interesting to look at http://repo.or.cz/w/pet.git

They create new PragmaHandler that are called by clang when processing
pragma (see pet.cc). The problem is that (if I remember correctly) it
happens before semantic processing and it is therefore hard to match them
to actual loops or objects, at that time you mostly have access to the line
number.

Maybe using a secondary pass on the clang ast to add the attributes is all
that is needed.

Regards.

On Tue, Aug 23, 2016 at 9:26 AM, Hahnfeld, Jonas via cfe-dev <
cfe-dev at lists.llvm.org> wrote:

> Hi,
>
>
>
> don’t know whether this helps (or even still works), but some time ago I
> had some fun with the attached patch: It stops compilation until user has
> accepted an EULA (please don’t kill me, this was no serious work…)
>
> I mostly copied from PragmaOnce, but you may need to do some more work to
> finally annotate variables and loops.
>
>
>
> Cheers,
>
> Jonas
>
>
>
> *From:* cfe-dev [mailto:cfe-dev-bounces at lists.llvm.org] *On Behalf Of *Hongbin
> Zheng via cfe-dev
> *Sent:* Tuesday, August 23, 2016 9:50 AM
> *To:* cfe-dev at lists.llvm.org
> *Subject:* [cfe-dev] Adding custom pragma to Clang
>
>
>
> Hi,
>
>
>
> I am trying to add custom pragma to clang to annotate extra infromation to
> variables and loops.
>
>
>
> I had a look at the OpenMP pragma handling a little bit, and found that
> adding custom pragma like OpenMP to clang is not easy, one need to modify
> the lexer, introduce dedicated node to AST, etc.
>
>
>
> But on the other hand, I am thinking the pragma for variable and loop
> annotating may not as complicated as those OpenMP pragmas. Is
> there any simple pragma in clang that I can look at?
>
>
>
> Thanks
>
> Hongbin
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
>


-- 
*Alexandre Isoard*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20160823/98869426/attachment.html>


More information about the cfe-dev mailing list