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