如何获得一个`C`程序的抽象语法树`GCC` [英] How to get abstract syntax tree of a `c` program in `GCC`

查看:232
本文介绍了如何获得一个`C`程序的抽象语法树`GCC`的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

怎样才能在GCC C程序的抽象语法树?结果
我想自动插入OpenMP编译到输入C程序。结果
我需要分析嵌套的循环查找的依赖关系,这样我可以插入相应的OpenMP编译。结果
所以基本上我想要做的是横向和分析输入C程序的抽象语法树。结果
我该如何实现这一目标?

How can I get the abstract syntax tree of a c program in gcc?
I'm trying to automatically insert OpenMP pragmas to the input c program.
I need to analyze nested for loops for finding dependencies so that I can insert appropriate OpenMP pragmas.
So basically what I want to do is traverse and analyze the abstract syntax tree of the input c program.
How do I achieve this?

推荐答案

您需要完全的数据流发现'依赖'。然后,你将需要真正的插入的OpenMP的要求。

You need full dataflow to find 'dependencies'. Then you will need to actually insert the OpenMP calls.

你想要的是一个程序转化体系。 GCC可能有相关性信息,但它是著名的困难的工作自定义的项目。其他人所说锵和罗斯。铛可能是一个不错的选择,但是自定义分析/转型不是它的主要目的。玫瑰旨在支持自定义的工具,但恕我直言是一个相当复杂的方案在实践中使用,因为其采用了EDG前端,这是不设计为支持改造。

What you want is a program transformation system. GCC probably has the dependency information, but it is famously difficult to work with for custom projects. Others have mentioned Clang and Rose. Clang might be a decent choice, but custom analysis/transformation isn't its main purpose. Rose is designed to support custom tools, but IMHO is a rather complicated scheme to use in practice because of its use of the EDG front end, which isn't designed to support transformation.

[以下文本被删除由一个主持人。我已经把它放回去,因为它是其中一个有效的转换系统完成这个任务。我负责它在没有办法FACT减少其值设为一个有用的答案OP]

[THE FOLLOWING TEXT WAS DELETED BY A MODERATOR. I HAVE PUT IT BACK, BECAUSE IT IS ONE THE VALID TRANSFORMATION SYSTEMS FOR THIS TASK. THE FACT THAT I AM RESPONSIBLE FOR IT IN NO WAY DIMINISHES ITS VALUE AS A USEFUL ANSWER TO THE OP.]

我们的DMS软件再造工具包具有其C前端明确设计成一个程序转化体系。它具有完整的数据流分析(包括指向的分析,调用图施工及范围分析)绑在合理的方式AST。它提供了源到源重写规则,使更改表面语法形式pssed的AST的前$ P $;您可以阅读变换而不是考察了一堆程序code的。随着修改后的AST,DMS可再生来源$ C ​​$ C,包括一个编译形式的评论。

Our DMS Software Reengineering Toolkit with its C front end is explicitly designed to be a program transformation system. It has full data flow analysis (including points-to analysis, call graph construction and range analyses) tied to the AST in sensible ways. It provides source-to-source rewrite rules enabling changes to the ASTs expressed in surface syntax form; you can read the transformations rather than inspect a bunch of procedural code. With a modified AST, DMS can regenerate source code including the comments in a compilable form.

这篇关于如何获得一个`C`程序的抽象语法树`GCC`的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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