Emacs – 如何得到gcc的抽象语法树(AST) fdump-translation-unit

作者:fangzhzh
声明:允许未经作者的同意进行非商业目的的转载,但必须保证原文完整性

无数论文上看到,gcc -fdump-transaltion-unit 就可以得到很具体的抽象语法树,可是我换了N多版本,得到最多
信息的就算自定义函数的语句序列了,

也试验了N多的工具,能用(gcc 4.3下成功编译)的工具就不多,得出的信息更是不适合。
于是,自己写算了!!

折腾了半天,看了一个叫print_node的函数,结果却是gcc debug用的,发现不行,就没有深究。

问了下google, 找到这个比较有用的信息。

On Mon, Mar 23, 2009 at 10:17, Praveen D V <for.pdv@gmail.com> wrote:

With the new version I’m not able to get those dumps.> I just downloaded latest release and

compiled it. ÂIt too doesn’t dump> those typedef trees.> Any other pointers?

You will need to modify the GCC dump routines yourself to dump thetypedefs. Start with dump_node
and the calls made to dump_begin(TDI_tu,…).

As I said before, these routines change almost constantly and we don’teven try to keep the output
pconsistent. They are just debuginstruments for us.

简单翻译下:有人抱怨说,-fdump-translation-unit 写的信息不够!怎么办?

gcc的开发者说,呵呵,俺们本来没有打算保持输出信息的完整性,但是毛主席他老人家说过,自己动手,丰衣足
食,所以,你自己把dump_begin和dump_node改吧改吧, 把你想要的都打出,不就得了。

呵呵,受教了


Last updated 2010 年 02 月 28 日 by fangzhzh
© 2012 Tao of Programmer Suffusion theme by Sayontan Sinha