-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrsmast.ml
462 lines (385 loc) · 12.9 KB
/
rsmast.ml
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
open Formula_datatype
open Atoms
(*open Cil_datatype
*)
type tag =
|Inf (** A state holding this tag means it belongs to an infinite path *)
|Fin (** A state holding this tag means it belongs to an finite path *)
type info =
|Tag of tag
|TagR (** Considered as tag fin *)
(*
module RState_Functor:Datatype.Functor_info = struct let module_name = ".Set" end
*)
(*
module type Minimum_Input =
sig
type t
val equal : t -> t -> bool
val hash : t -> int
val compare : t -> t -> int
end
module type S_with_simple_collections =
sig
type t
module Set:(FCSet.S with type elt = t)
module Map: (FCMap.S with type key = t)
module Hashtbl:(FCHashtbl.S with type key = t)
val equal : t -> t -> bool
val hash : t -> int
val compare : t -> t -> int
end
module Make_with_simple_collections (X:Minimum_Input) =
struct
include X
module Set = FCSet.Make (X)
module Map = FCMap.Make (X)
module Hashtbl = FCHashtbl.Make (X)
end
*)
(* Sorry, but necessary *)
let empty_structure = Obj.magic 0
module rec Type_RState :(
sig
type t =
{
s_id : int ; (** Identification of the
node *)
mutable s_name : string ; (** RState name *)
mutable deleted : bool; (** true iff the node has been deleted *)
mutable s_accept : Id_Formula.Set.t ; (** Set of buchi conditions
the state
satisfies. *)
mutable call : (Type_Box.t * RState.Set.t) option ; (** Some box is the state
calls
a module via a box
(call state)
else None *)
mutable return : (Type_Box.t * RState.Set.t) option ;
(** Some box if the state returns from a box (return state),
else None *)
(** Use the plug functions in Rsm.mli to change the two previous
fields. *)
mutable s_stmt : Cil_types.stmt ; (** Statement corresponding to the
state *)
mutable s_atom : atom ; (** Atom hold by the state *)
mutable s_info : info ; (** Information hold by the state *)
mutable s_mod : Type_Rsm_module.t ;(** Module in which the state is. *)
mutable s_succs : RState.Set.t ; (** RStates accessible from this state
*)
mutable s_preds : RState.Set.t ; (** Predecessors of this state *)
mutable summary_succs :
(((Ext_state.t list) * Id_Formula.Set.t) list) RState.Map.t ;
mutable summary_preds : RState.Set.t ;
}
end)
=
struct
type t = {
s_id : int ; (** Identification of the
node *)
mutable s_name : string ; (** RState name *)
mutable deleted : bool; (** true iff the node has been deleted *)
mutable s_accept : Id_Formula.Set.t ; (** Set of buchi conditions
the state
satisfies. *)
mutable call : (Type_Box.t * RState.Set.t) option ; (** Some box is the state
calls
a module via a box
(call state)
else None *)
mutable return : (Type_Box.t * RState.Set.t) option ;
(** Some box if the state
returns from a box
(return state),
else None *)
(** Use the plug functions in Rsm.mli to change the two previous
fields. *)
mutable s_stmt : Cil_types.stmt ; (** Statement corresponding to the
state *)
mutable s_atom : atom ; (** Atom hold by the state *)
mutable s_info : info ; (** Information hold by the state *)
mutable s_mod : Type_Rsm_module.t ;(** Module in which the state is. *)
mutable s_succs : RState.Set.t ; (** RStates accessible from this state
*)
mutable s_preds : RState.Set.t ; (** Predecessors of this state *)
mutable summary_succs :
(((Ext_state.t list) * Id_Formula.Set.t) list) RState.Map.t ;
mutable summary_preds : RState.Set.t ;
}
end
and RState_Make_Input:(Datatype.Make_input with type t = Type_RState.t) =
struct
include Datatype.Undefined
include Type_RState
let name = "RState"
let equal (x:t) (y:t) =
x.s_id = y.s_id
let hash (x:t) = x.s_id
let compare (x:t) (y:t) =
Pervasives.compare x.s_id y.s_id
let varname (x:t) =
"state_" ^ (string_of_int x.s_id) ^ "_" ^ (x.s_name)
let pretty fmt (x:t) =
Format.fprintf fmt "%s" (varname x)
let reprs =
[{
s_id = -1;
s_name = "";
deleted = true;
s_accept = Id_Formula.Set.empty ;
call = None;
return = None;
s_stmt = Cil.mkEmptyStmt ();
s_atom = List.hd Atom.reprs;
s_info = TagR;
s_mod = List.hd Rsm_module.reprs ;
(* Sorry. *)
s_succs = empty_structure;
s_preds = empty_structure;
summary_succs = empty_structure;
summary_preds = empty_structure;
}
]
let copy = Datatype.identity
let rehash = Datatype.identity
let mem_project = Datatype.never_any_project
end
and RState:
sig
include (Datatype.S_with_collections with type t = Type_RState.t)
val pretty_state_set : Format.formatter -> Set.t -> unit
end =
struct
include Datatype.Make_with_collections (RState_Make_Input)
let pretty_state_set fmt s =
Set.iter
(fun s -> Format.fprintf fmt "%a --" pretty s)
s
end
and Ext_state : sig
type t =
State of RState.t
| Summary of (t list * Id_Formula.Set.t) list
val equal : t -> t -> bool
val to_state : t -> RState.t
end
=
struct
type t =
State of RState.t
| Summary of (t list * Id_Formula.Set.t) list
let equal s1 s2 = match s1,s2 with
State s11, State s22 -> RState.equal s11 s22
| _,_ -> false
let to_state = function
| State s -> s
| Summary paths ->
match (List.hd (fst (List.hd paths))) with
State s -> s
| Summary _ -> assert false
end
and Type_Box:
sig
type t =
{
b_id : int ; (** Box's ID *)
mutable b_name : string ; (** Name of the box *)
mutable r_mod_repres : Type_Rsm_module.t ; (** Module represented by the box *)
mutable r_mod_belong : Type_Rsm_module.t ; (** Module the box belong to *)
mutable box_atom : atom ; (** Atom hold by the box *)
mutable box_tag : tag ; (** Tag hold by the box *)
(** The "plug" part. These lists refers to the transition
between a call / an exit to an entry / a return. *)
mutable b_entries : RState.Set.t RState.Map.t;
mutable b_exits : RState.Set.t RState.Map.t
}
end
=
struct
type t =
{
b_id : int ; (** Box's ID *)
mutable b_name : string ; (** Name of the box *)
mutable r_mod_repres : Type_Rsm_module.t ; (** Module represented by the box *)
mutable r_mod_belong : Type_Rsm_module.t ; (** Module the box belong to *)
mutable box_atom : atom ; (** Atom hold by the box *)
mutable box_tag : tag ; (** Tag hold by the box *)
(** The "plug" part. These lists refers to the transition
between a call / an exit to an entry / a return. *)
mutable b_entries : RState.Set.t RState.Map.t;
mutable b_exits : RState.Set.t RState.Map.t
}
end
and Box_Make_Input:(Datatype.Make_input with type t = Type_Box.t) =
struct
include Datatype.Undefined
include Type_Box
let name = "Box"
let equal (x:t) (y:t) = x.b_id = y.b_id
let hash (x:t) = Hashtbl.hash x
let compare (x:t) (y:t) = Pervasives.compare x.b_id y.b_id
let varname (x:t) = "box_" ^ (string_of_int x.b_id) ^ "_" ^ (x.b_name)
let reprs =
[
{
b_id = -1;
b_name = "";
r_mod_repres = List.hd Rsm_module.reprs;
r_mod_belong = List.hd Rsm_module.reprs;
box_atom = List.hd Atom.reprs;
box_tag = Fin;
b_entries = empty_structure;
b_exits = empty_structure;
}
]
let pretty fmt b = Format.fprintf fmt "%s" (varname b)
let copy = Datatype.identity
let rehash = Datatype.identity
let mem_project = Datatype.never_any_project
end
and Box :
sig
include (Datatype.S_with_collections with type t = Type_Box.t)
val pretty_complete : Format.formatter -> t -> unit
end
=
struct
include Datatype.Make_with_collections (Box_Make_Input)
let pretty_state_map fmt s =
RState.Map.iter
(fun s1 s2 -> Format.fprintf fmt "%a -> %a\n" RState.pretty s1 RState.pretty_state_set s2)
s
let pretty_complete fmt (box:t) =
Format.fprintf fmt
"Box %a_%d\n\
Atom: %a\n\n\
Entries: %a\n\n\
Exits:%a\n\n"
pretty box box.Type_Box.b_id
Atoms.Atom.pretty box.Type_Box.box_atom
pretty_state_map box.Type_Box.b_entries
pretty_state_map box.Type_Box.b_exits
end
and Type_Rsm_module:
sig
type t =
{
mutable mid : int ; (** Numerical ID of the module *)
mod_name : string ; (** Module name. Invariant : the main
module must be called "main" *)
is_func : Cil_types.varinfo ; (** Function represented by the
module *)
mutable states : RState.Set.t ; (** RStates of the module *)
mutable entries : RState.Set.t ; (** RStates at the beginning of a
module *)
mutable exits : RState.Set.t ; (** RStates at the end of a module *)
mutable box_repres : Box.Set.t ; (** Boxes that represents this module *)
mutable box_belong : Box.Set.t (** Boxes that belong to this module *)
}
end
=
struct
type t =
{
mutable mid : int ; (** Numerical ID of the module *)
mod_name : string ; (** Module name. Invariant : the main
module must be called "main" *)
is_func : Cil_types.varinfo ; (** Function represented by the
module *)
mutable states : RState.Set.t ; (** RStates of the module *)
mutable entries : RState.Set.t ; (** RStates at the beginning of a
module *)
mutable exits : RState.Set.t ; (** RStates at the end of a module *)
mutable box_repres : Box.Set.t ; (** Boxes that represents this module *)
mutable box_belong : Box.Set.t (** Boxes that belong to this module *)
}
end
and Rsm_module:Datatype.S_with_collections with type t = Type_Rsm_module.t =
Datatype.Make_with_collections
(struct
include Datatype.Undefined
include Type_Rsm_module
let name = "Rsm_module"
let equal (x:t) (y:t) = x.mid = y.mid
let compare (x:t) (y:t) = Pervasives.compare x.mid y.mid
let hash (x:t) = x.mid
let copy = Datatype.identity
let rehash = Datatype.identity
let mem_project = Datatype.never_any_project
let varname (m:t) = "module_" ^ m.mod_name
let pretty fmt t = Format.fprintf fmt "%s" (varname t)
let reprs =
[{
mod_name = "";
is_func = (
Cil.makeGlobalVar
"__tmp__"
(Cil_types.TVoid
[]));
states = empty_structure;
entries = empty_structure;
exits = empty_structure;
mid = -1;
box_repres = empty_structure;
box_belong = empty_structure;
}]
end)
type rsm = {
rsm_id : int ; (** Unique Id of the rsm *)
mutable name : string; (** Name of the rsm *)
mutable rsm_mod : Rsm_module.Set.t; (** Module list of the automaton *)
mutable start : RState.Set.t ; (** Initial state of the automaton *)
(** The two last fields are used for generalized buchi condition in
the case this RSM is a RGBA. The accepting condition is :
There is a path going infinitely often through the states of each
following sets :
- RStates tagged as Inf
- For each Global Until and Abstract Until formula in the closure,
there is a set of states in which the said formula is true.
*)
(*mutable inf_states : state list;*)
mutable until_set : Id_Formula.Set.t; (** Set of the Buchi conditions. *)
}
type state = Type_RState.t
type box = Type_Box.t
type r_module = Type_Rsm_module.t
type extended_state = Ext_state.t
module Config: (Datatype.S_with_collections with type t = state * (box list))
=
Datatype.Make_with_collections(
struct
include Datatype.Undefined
type t = RState.t * Box.t list
let name = "Config"
let varname ((x,_):t) = RState.varname x (* todo : make it better *)
let hash (x:t) = Hashtbl.hash x
let reprs = [(List.hd RState.reprs , Box.reprs)]
let equal ((s1,b1):t) ((s2,b2):t) =
RState.equal s1 s2 &&
(List.for_all2
Box.equal
b1
b2
)
let compare ((s1,b1):t) ((s2,b2):t) =
if RState.equal s1 s2
then
let rec comp_b_lists b1 b2 =
match b1,b2 with
hd1 :: tl1 , hd2 :: tl2 ->
if Box.equal hd1 hd2
then comp_b_lists tl1 tl2
else Box.compare hd1 hd2
| [] , [] -> 0
| [] , _ -> -1
| _ , [] -> 1
in
comp_b_lists b1 b2
else
RState.compare s1 s2
let copy = Datatype.identity
let rehash = Datatype.identity
let mem_project = Datatype.never_any_project
end
)