如何将 gcc 生成的抽象语法树转储到 .dot 文件中? [英] How can I dump an abstract syntax tree generated by gcc into a .dot file?

查看:45
本文介绍了如何将 gcc 生成的抽象语法树转储到 .dot 文件中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为问题的标题是不言自明的,我想将 gcc 生成的抽象语法树转储到 .dot 文件(Graphviz 生成的那些文件)中,因为然后我想在 .png 文件或类似文件中查看它.有什么办法可以做到吗?

I think the question's title is self explanatory, I want to dump an abstract syntax tree generated by gcc into a .dot file (Those files generated by Graphviz) because then I want to view it in a .png file or similar. Is there any way I can do that?

提前致谢:)

推荐答案

有两种方法,都包含两个步骤

There are two methods, both including two steps

  1. 使用 GCC 内部 vcg 支持

  1. Using GCC internal vcg support

  1. 用 vcg dumps 编译你的代码(比如 test.c)

  1. Compile your code (say test.c) with vcg dumps

gcc -fdump-tree-vcg -g test.c

使用任何第三方工具从 vcg 获取点输出

Use any third party tool to get dot output from vcg

graph-easy test.c.006t.vcg --as_dot

  • 使用原始转储进行编译,然后使用一些脚本对它们进行预处理以形成点文件(如 这篇有用的文章)

    这两种方法都有自己的优点和缺点——首先,在 gimple 翻译之前,你真的只能得到一个 AST 转储,但这很容易.使用第二个,您可以将任何原始转储转换为点格式,但您必须支持脚本,这是开销.

    Both methods have their own good and bad sides -- with first you can really get only one dump of AST before gimple translation, but it is easy. With second you may convert any raw dump to dot-format, but you must support scripts, that is overhead.

    更喜欢什么 - 取决于您自己的选择.

    What to prefer -- is on your own choice.

    UPD:时代在变.gcc 4.8.2 的全新选项可以立即生成点文件.只供应:

    UPD: times are changing. Brand new option for gcc 4.8.2 makes it possible to generate dot files immediately. Just supply:

    gcc test.c -fdump-tree-all-graph
    

    你会得到大量已经格式化的点文件:

    and you will get a plenty of already formatted for you dot files:

    test.c.008t.lower.dot
    test.c.012t.cfg.dot
    test.c.016t.ssa.dot
    ... etc ...
    

    请务必使用带有此选项的新版本 GCC.

    Please be sure to use new versions of GCC with this option.

    这篇关于如何将 gcc 生成的抽象语法树转储到 .dot 文件中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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