Clang / GCC插件来解释自定义c ++ 11属性 [英] Clang/GCC plugin to interpret custom c++11 attributes

查看:196
本文介绍了Clang / GCC插件来解释自定义c ++ 11属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我自己写了一个插件来叮当声或gcc来解释自定义[[cxx11 :: attributes]]并生成一些代码。版本4.5,gcc支持几乎每个编译步骤都可以挂钩的插件。然而,我认为gcc并不是很清楚如何修改它的AST并浏览它(至少我尝试了很糟糕的时间...)。

然后我记得铿锵被设计作为一个图书馆的延伸和使用,我给它一个镜头。挖掘周围后,我发现一些话题说铿锵不支持自定义属性。我哭了。



我的主要目标是根据用户可以在代码中使用的任何种类的注释生成代码。我想使用c ++ 11属性,因为它们非常清晰。 Pragma也是一种选择,但它们有一些限制。



以下是问题:

1)真的(目前)不可能在叮当中拥有自定义属性?
2)学习gcc内部的最好方法是什么? (我读了很多页面的文档,但他们没有说我想要的)
3)gcc是否有一些转储函数来打印它的AST像clang那样?这将有助于探索它的树。



谢谢!任何信息/提示将不胜感激!

解决方案

GCC插件特定于GCC,甚至(原则上)的GCC(不能保证为GCC 4.8编码的插件可以在GCC 4.9上工作)。



你可以考虑使用 MELT ,这是一个用于扩展GCC的特定语言的语言,作为GCC(meta-)插件实现。



但是,您需要了解GCC的内部表示(Gimple,Trees,通过经理,...)。请先阅读我的幻灯片,其内容是 GCC插件,通过MELT示例(Linux Collaboration Summit ,2014年3月)



您可以轻松添加 GCC属性带插件和MELT,可能还有C ++ 11属性。



是的,GCC有很多可能的转储(尝试使用 -fdump-tree-all )。



您最好使用最新版本的GCC 4.9.1)和MELT(例如1.1.2或更高版本;我可能会在一两周内发布MELT 1.1.3)

I'm trying to write a plugin to clang or gcc to interpret custom [[cxx11::attributes]] and generate some code based on that.

Since version 4.5, gcc supports plugins that can be hooked at almost every compilation steps. However, I think gcc is not very clear about how modify its AST and navigate through it (at least I'm having a bad time trying...).

Then I remembered that clang was designed to be extended and used as a library and I gave it a shot. After digging around I found some topics saying clang does not support custom attributes. I cried.

My main goal is to generate code based on any kind of annotations that user can use at code. I'd like to use c++11 attributes because they are very clear. Pragmas are also an option but they have some limitations.

Here are the questions:

1) Is it really (currently) impossible to have custom attributes in clang? 2) What is the best way to learn gcc internals? (I read lots of pages of documentation but still they didn't say what I want) 3) Does gcc have some dump function to print its AST like clang does? It would help a lot to explore its tree.

Thank you! Any information/tip would be appreciated!

解决方案

GCC plugins are specific to GCC, and even (in principle) to a particular version of GCC (there is no guarantee that a plugin coded for GCC 4.8 would work on GCC 4.9).

You might consider extending GCC with MELT, which is a lispy domain specific language to extend GCC, implemented as a GCC (meta-) plugin.

However, you need to understand the internal representations of GCC (Gimple, Trees, the pass manager, ...). Read first my slides on GCC plugins thru the MELT example (Linux Collaboration Summit, march 2014)

You can easily add GCC attributes with plugins and with MELT, and probably also C++11 attributes.

And yes, GCC has a lot of possible dumps (try using -fdump-tree-all).

You'll better use recent versions of GCC (e.g. 4.9.1) and of MELT (e.g. 1.1.2 or later; I'll probably release MELT 1.1.3 within a week or two)

这篇关于Clang / GCC插件来解释自定义c ++ 11属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆