且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

数据流图构建

更新时间:2022-11-02 23:36:24

给定一个 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.