![]() |
|
Navigation |
Synopsis Compute the control flow graph for a Pico program.
Examples A control flow graph shows how the entry and exit points of a program are connected with each other via all
decision points and statements in the program. Typically, an assignment statement is a single node in the graph
and an if-then-else statement creates a decision point (its test) that connects the then branch and the else branch.
The exits of each branch are connected to the exit of the if-then-else statement as a whole.
A control flow graph for Pico programs can be created as follows: module demo::lang::Pico::ControlFlow import Prelude; import analysis::graphs::Graph; import demo::lang::Pico::Abstract; import demo::lang::Pico::Load; public data CFNodeNotes:
rascal>import demo::lang::Pico::ControlFlow; ok rascal>cflowProgram("begin declare n : natural, s : string; n := 10; s := \"a\"; while n do s := s + \"a\"; n := n - 1 od end"); CFGraph: <{entry(|file://-|(0,100,<1,0>,<1,100>))},{ <statement( |file://-|(48,8,<1,48>,<1,56>), asgStat( "s", strCon("\"a\"")[ @location=|file://-|(53,3,<1,53>,<1,56>), @comments=() ])[ @location=|file://-|(48,8,<1,48>,<1,56>), @comments=() ]),choice( |file://-|(64,1,<1,64>,<1,65>), id("n")[ @location=|file://-|(64,1,<1,64>,<1,65>), @comments=() ])>, <choice( |file://-|(64,1,<1,64>,<1,65>), id("n")[ @location=|file://-|(64,1,<1,64>,<1,65>), @comments=() ]),exit()>, <choice( |file://-|(64,1,<1,64>,<1,65>), id("n")[ @location=|file://-|(64,1,<1,64>,<1,65>), @comments=() ]),statement( |file://-|(69,12,<1,69>,<1,81>), asgStat( "s", add( id("s")[ @location=|file://-|(74,1,<1,74>,<1,75>), @comments=() ], strCon("\"a\"")[ @location=|file://-|(78,3,<1,78>,<1,81>), @comments=() ])[ @location=|file://-|(74,7,<1,74>,<1,81>), @comments=() ])[ @location=|file://-|(69,12,<1,69>,<1,81>), @comments=() ])>, <statement( |file://-|(69,12,<1,69>,<1,81>), asgStat( "s", add( id("s")[ @location=|file://-|(74,1,<1,74>,<1,75>), @comments=() ], strCon("\"a\"")[ @location=|file://-|(78,3,<1,78>,<1,81>), @comments=() ])[ @location=|file://-|(74,7,<1,74>,<1,81>), @comments=() ])[ @location=|file://-|(69,12,<1,69>,<1,81>), @comments=() ]),statement( |file://-|(83,10,<1,83>,<1,93>), asgStat( "n", sub( id("n")[ @location=|file://-|(88,1,<1,88>,<1,89>), @comments=() ], natCon(1)[ @location=|file://-|(92,1,<1,92>,<1,93>), @comments=() ])[ @location=|file://-|(88,5,<1,88>,<1,93>), @comments=() ])[ @location=|file://-|(83,10,<1,83>,<1,93>), @comments=() ])>, <statement( |file://-|(83,10,<1,83>,<1,93>), asgStat( "n", sub( id("n")[ @location=|file://-|(88,1,<1,88>,<1,89>), @comments=() ], natCon(1)[ @location=|file://-|(92,1,<1,92>,<1,93>), @comments=() ])[ @location=|file://-|(88,5,<1,88>,<1,93>), @comments=() ])[ @location=|file://-|(83,10,<1,83>,<1,93>), @comments=() ]),choice( |file://-|(64,1,<1,64>,<1,65>), id("n")[ @location=|file://-|(64,1,<1,64>,<1,65>), @comments=() ])>, <entry(|file://-|(0,100,<1,0>,<1,100>)),statement( |file://-|(39,7,<1,39>,<1,46>), asgStat( "n", natCon(10)[ @location=|file://-|(44,2,<1,44>,<1,46>), @comments=() ])[ @location=|file://-|(39,7,<1,39>,<1,46>), @comments=() ])>, <statement( |file://-|(39,7,<1,39>,<1,46>), asgStat( "n", natCon(10)[ @location=|file://-|(44,2,<1,44>,<1,46>), @comments=() ])[ @location=|file://-|(39,7,<1,39>,<1,46>), @comments=() ]),statement( |file://-|(48,8,<1,48>,<1,56>), asgStat( "s", strCon("\"a\"")[ @location=|file://-|(53,3,<1,53>,<1,56>), @comments=() ])[ @location=|file://-|(48,8,<1,48>,<1,56>), @comments=() ])> },{exit()}>Is the above not very motivating to move on to Pico/Visualize? ![]() |