6.3 CFG
A CFG is a fundamental data structure in compiler design and static program analysis, representing all paths that might be traversed through a program during execution.
A CFG consists of the following key components:
Nodes: Correspond to basic blocks, a straight-line sequence of operations with one entry and one exit point
Edges: Represent the flow of control from one block to another, including both conditional and unconditional branches
Start and end nodes: Every CFG has a unique entry node and one or more exit nodes
As an example of a CFG, consider the function to calculate the maximum of two integer numbers that we used as an example before; see Figure 2.5:
1Â int max(int a, int b) {Â 2Â Â Â if (a > b)Â 3Â Â Â Â Â return a;Â 4Â Â Â return b;Â 5Â }
Figure 6.1: CFG example C++ code: max.cpp
The corresponding CFG can be represented as follows:
Figure 6.2: CFG example for...