|
Example of a control flow graph The following three examples show the control flow graph
of a procedural program. The nodes contain the text of statements as
labels. Not all edges have labels. The visualized control flow comes
from the following nonsense program, which consists of a procedure
PROCEDURE test( VAR b, c : INTEGER );
BEGIN
b := c + 5;
END
BEGIN /* main routine of a nonsense program */
x := 1;
WHILE (x = 1) DO
x := 2;
test ( x, 1 );
x := 3;
OD;
WHILE (x = 1) DO
x := 4;
x := 5;
test ( x, 2 );
OD;
WHILE (x = 1) DO
x := 6;
IF (x = 7) THEN x := 8; ELSE test ( x, 3 );
FI;
OD;
END.
Control flow graph 1
graph: {title: "Control Flow Graph" layoutalgorithm: dfs finetuning : no display_edge_labels: yes yspace : 55 edge.thickness : 3 node: { title:"18" label: "test_b := test_c+5"} node: { title:"17" label: "Exit" } node: { title:"16" label: "test (x,3)" } node: { title:"15" label: "x := 8" } node: { title:"14" label: "x=7" } node: { title:"13" label: "x := 6" } node: { title:"12" label: "x=1" } node: { title:"11" label: "test (x,2)" } node: { title:"10" label: "x := 5" } node: { title:"9" label: "x := 4" } node: { title:"8" label: "x=1" } node: { title:"7" label: "x := 3" } node: { title:"6" label: "test (x,1)" } node: { title:"5" label: "x := 2" } node: { title:"4" label: "x=1" } node: { title:"3" label: "x := 1" } node: { title:"2" label: "Start" } node: { title:"1" label: "Exit point\ntest" } node: { title:"0" label: "Entry point\ntest" } edge: { source:"18" target:"1" } edge: { source:"0" target:"18" } edge: { source:"12" target:"17" label: "false"} edge: { source:"8" target:"12" label: "false"} edge: { source:"16" target:"12" label: "back" } edge: { source:"15" target:"12" label: "back" } edge: { source:"13" target:"14" } edge: { source:"14" target:"16" label: "false"} edge: { source:"14" target:"15" label: "true" } edge: { source:"12" target:"13" label: "true" } edge: { source:"4" target:"8" label: "false"} edge: { source:"11" target:"8" label: "back" } edge: { source:"10" target:"11" } edge: { source:"9" target:"10" } edge: { source:"8" target:"9" label: "true" } edge: { source:"3" target:"4" } edge: { source:"7" target:"4" label: "back" } edge: { source:"6" target:"7" } edge: { source:"5" target:"6" } edge: { source:"4" target:"5" label: "true" } edge: { source:"2" target:"3" } } Control flow graph 2
// ... node: { title:"17" label: "Exit" shape: ellipse} node: { title:"14" label: "x=7" shape: rhomb } node: { title:"12" label: "x=1" shape: rhomb } node: { title:"8" label: "x=1" shape: rhomb } node: { title:"4" label: "x=1" shape: rhomb } node: { title:"2" label: "Start" shape: ellipse} node: { title:"1" label: "Exit point\ntest" shape: ellipse} node: { title:"0" label: "Entry point\ntest" shape: ellipse} bentnearedge: { source:"12" target:"17" label: "false"} bentnearedge: { source:"8" target:"12" label: "false"} backedge: { source:"16" target:"12" label: "back" } backedge: { source:"15" target:"12" label: "back" } bentnearedge: { source:"14" target:"16" label: "false"} bentnearedge: { source:"14" target:"15" label: "true" } bentnearedge: { source:"12" target:"13" label: "true" } bentnearedge: { source:"4" target:"8" label: "false"} backedge: { source:"11" target:"8" label: "back" } bentnearedge: { source:"8" target:"9" label: "true" } backedge: { source:"7" target:"4" label: "back" } bentnearedge: { source:"4" target:"5" label: "true" } //... Control flow graph 3
manhattan_edges: yes equal_y_dist : yes layout_downfactor: 8
» Next: The effect of the layout algorithms
|
|