数据流图构建 [英] Data Flow Graph Construction

查看:37
本文介绍了数据流图构建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我被要求编写一个程序来构建输入程序代码的数据流图,给定抽象语法树.我在网上搜索数据流图的定义,发现一个代码段的数据流分析有很多事情要做.我想知道为给定代码构建数据流图到底需要绘制什么.很感谢任何形式的帮助!

I have been asked to write a program to construct a data flow graph of a input program code, given the abstract syntax tree. I search for the definition of data flow graph online and found there are a lot of things that goes on in data flow analysis of a code segment. I want to know what exactly I have to draw to construct a data flow graph for a given code. Any help is very much appreciated!

推荐答案

给定一个 AST,要生成数据流图,您必须:

Given an AST, to produce a data flow graph, you must:

  • 建立符号表,以便使用的每个标识符都映射到其显式或隐式定义的类型,还允许您区分一个范围内的标识符与另一个范围内的相同标识符

  • build up symbol tables, so that every identifier used is mapped to its explicitly or implicitly defined type, also allowing you distinguish an identifier in one scope from the same identifier in another scope

构建一个控制流图,显示程序代码的顺序执行,和条件分支.(在函数之间构建调用图的加分项!)

construct a control flow graph, showing the order in which the program code is executed, and the conditional branches. (Bonus points for constructing a call graph between functions!)

确定数据如何沿着控制流图流动,通常使用某种数据流分析框架,建立对变量生命周期的引用,并将所有这些都捕获为图表.

determine how data flows along the control flow graph, usually using some kind of data flow analysis framework, building up references to variable lifetimes, and capturing all this as a graph.

您可以使用某种外部图形绘制包绘制最终图形.

You can draw the final graph using some kind of external graph drawing package.

所有这些步骤都非常复杂,而且工作量可能比您想象的要多得多.我的印象是你在这里没有太多背景.您可以通过研究标准编译器文本(Aho/Sethi/Ullman编译器")来获得该背景,该文本非常经典且非常好.但是您需要在开始之前这样做,否则您将不会真正理解这些步骤并将它们联系在一起.

All of these steps are pretty complicated, and are likely to be a lot more work than you might think. I get the impression you don't have much background here. You can get that background by studying a standard compiler text (Aho/Sethi/Ullman "Compilers") is pretty classic and very good. But you need to do that before you start, or you won't really understand the steps and they link together.

这篇关于数据流图构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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