aiSee for Unix: User Manual<>index

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 test and a main routine in a pseudo imperative language.

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

Control flow graph 1: Simple versionThis 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 2

Control flow graph 2: Different node shapes and edge typesThis 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.

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

Control flow graph 3: Manhattan edgesThis example shows another improved visualization of the control flow graph. 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:

manhattan_edges: yes
equal_y_dist   : yes
layout_downfactor: 8

» Related graphs:

» Next: The effect of the layout algorithms
» Prev.: Example of a cyclic graph

HomeSitemapai
Last modified on 3 August 2003 by webmaster. © 2000-2003 AbsInt.
URL: http://www.aisee.com/manual/unix/39.htm


Home
About
Examples
Free trial

 Help
» FAQs
» Quick Guide
» User Manual
   » Windows
   » Mac
» GDL
» Options
» Changelog
» GDLedit

Store
Legal
Contact
Extras
Sitemap