Control Flow Graphs:
A control-flow graph (CFG) is a representation, using graph notation, of all paths that might be traversed through a program during its execution. The control-flow graph is due to Frances E. Allen, who notes that Reese T. Prosser used boolean connectivity matrices for flow analysis before.
In a control-flow graph each node in the graph represents a basic block, i.e. a straight-line piece of code without any jumps or jump targets; jump targets start a block, and jumps end a block. Directed edges are used to represent jumps in the control flow.
Steps:
Number all the statements of a program.
Numbered statements represent nodes of the control flow graph.
An edge from one node to another node exists:
if execution of the statement representing the first node can result in transfer of control to the other node.
Sequence:
- a=5;
- b=a*b-1
Selection:
- if(a>b) then
- c=3;
- Else
- c=5;
- c=c*c;
Iteration:
- while(a>b){
- b=b*a;
- b=b-1;
- }
- c=b+d;
Path:
- A path through a program:
- a node and edge sequence from the starting node to a terminal node of the control flow graph.
- There may be several terminal nodes for the program.
- Any path through the program:
- introducing at least one new node that is not included in any other independent paths.
- Provides a practical way of determining the maximum number of linearly independent paths in a program.
0 Comments