Streamlining Control-Flow Graph Construction with DCFlow http://www.rascal-mpl.org
Mark Hills 7th International Conference on Software Language Engineering (SLE 2014) September 15-16, 2014 Västerås, Sweden
1
Streamlining Control-Flow Graph Construction with DCFlow Mark Hills - - PowerPoint PPT Presentation
Streamlining Control-Flow Graph Construction with DCFlow Mark Hills 7th International Conference on Software Language Engineering (SLE 2014) September 15-16, 2014 Vsters, Sweden http://www.rascal-mpl.org 1 Say you need a control flow
1
10 y := 10 exit 15 y := 15 3 x := 3 x true false entry
2
10 y := 10 exit 15 y := 15 3 x := 3 x true false entry
3
10 y := 10 exit 15 y := 15 3 x := 3 x true false entry
4
10 y := 10 exit 15 y := 15 3 x := 3 x true false entry
5
10 y := 10 exit 15 y := 15 3 x := 3 x true false entry
6
public data CFNode = entry(loc location) | exit() | choice(loc location, EXP exp) | statement(loc location, STATEMENT stat); alias CFGraph = tuple[set[CFNode] entry, Graph[CFNode] graph, set[CFNode] exit];
7
CFGraph cflowStat(s:asgStat(PicoId Id, EXP Exp)) { S = statement(s@location, s); return <{S}, {}, {S}>; } CFGraph cflowStat(ifElseStat(EXP Exp, list[STATEMENT] Stats1, list[STATEMENT] Stats2)){ CF1 = cflowStats(Stats1); CF2 = cflowStats(Stats2); E = {choice(Exp@location, Exp)}; return < E, (E * CF1.entry) + (E * CF2.entry) + CF1.graph + CF2.graph, CF1.exit + CF2.exit >; }
8
public rel[stat, def] reachingDefinitions( rel[stat,var] DEFS, rel[stat,stat] PRED) { set[stat] STATEMENT = carrier(PRED); rel[stat,def] DEF = definition(DEFS); rel[stat,def] KILL = kill(DEFS); rel[stat,def] IN = {}; rel[stat,def] OUT = DEF; solve (IN, OUT) { IN = {<S, D> | int S <- STATEMENT, stat P <- predecessors(PRED,S), def D <- OUT[P]}; OUT = {<S, D> | int S <- STATEMENT, def D <- DEF[S] + (IN[S] - KILL[S])}; }; return IN; }
9
10
11
12
13
DCFlow Translator (Rascal) DCFlow Definition Source Program (Input Language) DCFlow Libraries (Rascal) Language-Specific Functions (Rascal) CFG Builder Modules (Rascal) CFG Construction (Rascal) Control Flow Graphs (Rascal) CFG Visualization (Rascal) GraphViz Visualizations (GraphViz,dot)
14
15
16
cons( label( "add", adt( "EXP", [])), [ label( "left", adt( "EXP", [])), label( "right", adt( "EXP", [])) ], [], (), {}), public data EXP = id(PicoId name) | natCon(int iVal) | strCon(str sVal) | add(EXP left, EXP right) | sub(EXP left, EXP right) | conc(EXP left, EXP right) ;
17
18
19
20
21
22
23
24
25
26
27