Repository navigation
Expand file tree
/
Copy pathProgramGraph.fs
More file actions
54 lines (47 loc) · 1.79 KB
/
Copy pathProgramGraph.fs
File metadata and controls
54 lines (47 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
module ProgramGraph
open System
open CalculatorTypesAST
let mutable nodeCount = 0
let mutable CmdArray:List<int * commands *int> = []
let mutable TestArray:List<int * boolExpr * int> = []
let rec edgesCmd (src:int, sink:int, commands) =
match commands with
| AssignVariableCommand(x,y) -> CmdArray <- CmdArray @ [(src, commands, sink)]
()
| AssignArrayValue(x,y,z) -> CmdArray <- CmdArray @ [(src, commands, sink)]
()
| SkipOperation -> CmdArray <- CmdArray @ [(src, commands, sink)]
()
| ExecuteLoop(x) -> edgesGC(src, src, x)
TestArray <- TestArray @ [(src, DONEGUARD(x), sink)]
()
| ExecuteIf(x) -> edgesGC(src, sink, x)
()
| CommandSequence(x,y) -> nodeCount<-nodeCount+1
let newnode = nodeCount
edgesCmd(src, nodeCount, x)
edgesCmd(newnode, sink, y)
()
and edgesGC (src:int, sink:int, GC) =
match GC with
| ExecuteCondition(x,y) -> nodeCount<-nodeCount+1;
TestArray <- TestArray @ [(src, x, nodeCount)]
edgesCmd(nodeCount, sink, y)
()
| ExecuteChoice(x,y) -> edgesGC(src, sink, x)
edgesGC(src, sink, y)
()
and DONEGUARD (GC) =
match GC with
| ExecuteCondition(x,y) -> NOTExpr(x)
| ExecuteChoice(x,y) -> BoolLogicAndExpr(DONEGUARD(x), DONEGUARD(y))
//variable, array, bool
//F# type expression
// Set of tuples(start end label)
//Node gen: let mutable count := 0 count <- count+1
let genPG e =
CmdArray <- []
TestArray <- []
edgesCmd (0, -1, e)
nodeCount <- 0
(CmdArray, TestArray)