Data flow analysis for Nim. We transform the AST into a linear list of instructions first to make this easier to handle: There are only 3 different branching instructions: 'goto X' is an unconditional goto, 'fork X' is a conditional goto (either the next instruction or 'X' can be taken), 'loop X' is the only jump that jumps back.
Exhaustive case statements are translated so that the last branch is transformed into an 'else' branch. return and break are all covered by 'goto'.
The data structures and algorithms used here are inspired by "A Graph–Free Approach to Data–Flow Analysis" by Markus Mohnen. https://link.springer.com/content/pdf/10.1007/3-540-45937-5_6.pdf
Procs
proc constructCfg(s: PSym; body: PNode; root: PSym): ControlFlowGraph {. ...raises: [Exception], tags: [RootEffect], forbids: [].}
- constructs a control flow graph for body. Source Edit
proc echoCfg(c: ControlFlowGraph; start = 0; last = -1) {....deprecated, raises: [Exception, KeyError], tags: [RootEffect], forbids: [].}
- Source Edit echos the ControlFlowGraph for debugging purposes.