-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathifds2.mlog
125 lines (91 loc) · 2.74 KB
/
ifds2.mlog
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
module type IFDS_PROGRAM = sig
type procedure
type point
(* intra-procedural edges *)
edge : point * point
(* edge from a procedure call to first node in procedure *)
start_edge : procedure * point
(* call edge from one procedure to another *)
call : point * procedure
(* return (callsite, exitnode, returnnode) *)
return : point * point * point
(* set of procedures that are called initially *)
initial : procedure
end
module type IFDS_PROGRAM_EXT = sig
type procedure
type point
type entry_fact
type fact
edge : point * fact * point * fact
start_edge : procedure * entry_fact * point * fact
call : point * fact * procedure * entry_fact
return : point * fact * point * fact * point * fact
initial : procedure * entry_fact
end
module IFDS_of_Extended (P : IFDS_PROGRAM_EXT) = struct
type procedure = P.procedure * P.entry_fact
type point = P.point * P.fact
define
edge : point * point
edge ((?n,?s), (?n',?s')) :- P.edge (?n, ?s, ?n', ?s')
define
start_edge : procedure * point
start_edge ((?p, ?ef), (?n, ?s)) :- P.start_edge (?p, ?ef, ?n, ?s)
define
call : point * procedure
call ((?n, ?s), (?p, ?ef)) :- P.call (?n, ?s, ?p, ?ef)
define
return : point * point * point
return ((?nc,?sc), (?ne, ?se), (?nr, ?sr)) :-
P.return (?nc, ?sc, ?ne, ?se, ?nr, ?sr)
define
initial : procedure
initial ((?p, ?ef)) :- P.initial (?p, ?ef)
end
module IFDS (P : IFDS_PROGRAM) = struct
define
intra : P.procedure * P.point
intra (?Proc, ?Node) :- invoked (?Proc), P.start_edge (?Proc, ?Node)
intra (?Proc, ?Node) :- intra (?Proc, ?Node'), P.edge (?Node', ?Node)
intra (?Proc, ?Node) :- intra (?Proc, ?Node'), callreturn (?Node', ?Node)
and
invoked : P.procedure
invoked (?Proc) :- P.initial (?Proc)
invoked (?Proc) :- callsite (?Node, ?Proc)
and
callsite : P.point * P.procedure
callsite (?Node, ?CalledProc) :-
intra (?Proc, ?Node), P.call (?Node, ?CalledProc)
and
callreturn : P.point * P.point
callreturn (?CallNode, ?ReturnNode) :-
callsite (?CallNode, ?CalledProc),
intra (?CalledProc, ?ExitNode),
P.return (?CallNode, ?ExitNode, ?ReturnNode)
end
module Test (P : IFDS_PROGRAM_EXT) = struct
module P' = IFDS_of_Extended (P)
module A = IFDS (P')
end
(* A nonsense example program *)
module P = struct
type procedure = int
type point = int * int
define
edge : point * point
edge ((1,4),(2,5))
edge ((1,2),(4,3))
define
start_edge : procedure * point
start_edge (2,(1,4))
define
call : point * procedure
call ((2,5),2)
define
return : point * point * point
define
initial : procedure
initial (1)
end
module A = IFDS (P)