
Next: Layout Algorithms
Up: GDL Examples
Previous: A Cyclic Graph
The following three graphs 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
test and a main routine in a pseudo imperative language.
PROCEDURE test( VAR b : INTEGER; 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.
Example 7: Control Flow Graph 1
This example shows a simple visualization of the control flow graph.
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 1: Simple version
|
Example 8: Control Flow Graph 2
This example shows an improved visualization of the control
flow graph. The start, exit and branch nodes are drawn in different shapes
so that they can be better recognized. The edges closing a cycle are specified
as back edges in order to see the uniform flow of control in the other edges.
The edges at the branch nodes are anchored at the left and right via the bent
near edge specification.
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" shape: ellipse}
node: { title:"16" label: "test (x,3)" }
node: { title:"15" label: "x := 8" }
node: { title:"14" label: "x=7" shape: rhomb }
node: { title:"13" label: "x := 6" }
node: { title:"12" label: "x=1" shape: rhomb }
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" shape: rhomb }
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" shape: rhomb }
node: { title:"3" label: "x := 1" }
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}
edge: { source:"18" target:"1" }
edge: { source:"0" target:"18" }
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" }
edge: { source:"13" target:"14" }
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" }
edge: { source:"10" target:"11" }
edge: { source:"9" target:"10" }
bentnearedge: { source:"8" target:"9" label: "true" }
edge: { source:"3" target:"4" }
backedge: { source:"7" target:"4" label: "back" }
edge: { source:"6" target:"7" }
edge: { source:"5" target:"6" }
bentnearedge: { source:"4" target:"5" label: "true" }
edge: { source:"2" target:"3" }
}
|
|

Control flow graph 2: Different node shapes and edge types
|
Example 9: Control Flow Graph 3
|
This example shows another improved visualization of the control
flow graph of Example 7. Here an orthogonal layout is used so that the graph looks
like a typical flowchart. For orthogonal layout, a large down factor (and a large
near factor as well as an up factor of zero) is recommended. This improves the
layout of long vertical edges. Add the following lines to the graph specification
in Example 8:
manhattan_edges: yes
equalydist : yes
layout_downfactor: 8
|
|

Control flow graph 3: Manhattan edges
|

Last modified on 22 November 2001 by webmaster.
© 2000-2001 AbsInt