MPS
 
Get MPS

Data flow

Last modified: 11 February 2024

A language's data flow aspect allows you to find unreachable statements, detect unused assignments, check whether a variable might not be initialized before it's read, and so on. It also allows performing some code transformations, for example the 'extract method' refactoring.

Most users of data flow analyses aren't interested in details of its inner working, but are interested in getting the results they need. They want to know which of their statements are unreachable, and what can be read before it's initialized. In order to shield a user from the complexities of these analyses, we provide assembly-like intermediate language into which you translate your program. After translation, this intermediate presentation is analyzed and a user can find which of the statements of original language are unreachable etc.

For example here is the translation of a 'for' loop from baseLanguage:

dfx2.png

First, we emit a label so we can jump after it. Then we perform a conditional jump after the current node. Then we emit code for node.variable. Finally, we emit code for the loop's body, and jump to the previously emitted label.