且构网

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

数据流图构造

更新时间:2022-11-02 23:01:41

给出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.