Skip to content

Commit a10c973

Browse files
committed
Deduplicate witness ghost entry creation
1 parent 516e3ad commit a10c973

2 files changed

Lines changed: 28 additions & 20 deletions

File tree

src/analyses/mutexGhosts.ml

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -48,43 +48,29 @@ struct
4848
| YamlEntryGlobal (g, task) ->
4949
let g: V.t = Obj.obj g in
5050
let (locked, unlocked, multithread) = ctx.global g in
51-
let loc = Node.location g in
52-
let location_function = (Node.find_fundec g).svar.vname in
53-
let location = YamlWitness.Entry.location ~location:loc ~location_function in
5451
let entries =
55-
(* TODO: do ghost_variable-s only once *)
52+
(* TODO: do variable_entry-s only once *)
5653
Locked.fold (fun l acc ->
57-
let variable = WitnessGhost.name_varinfo (Locked l) in
58-
let type_ = "int" in
59-
let initial = "0" in
60-
let entry = YamlWitness.Entry.ghost_variable ~task ~variable ~type_ ~initial in
54+
let entry = WitnessGhost.variable_entry ~task (Locked l) in
6155
Queries.YS.add entry acc
6256
) (Locked.union locked unlocked) (Queries.YS.empty ())
6357
in
6458
let entries =
6559
Locked.fold (fun l acc ->
66-
let variable = WitnessGhost.name_varinfo (Locked l) in
67-
let expression = "1" in
68-
let entry = YamlWitness.Entry.ghost_update ~task ~location ~variable ~expression in
60+
let entry = WitnessGhost.update_entry ~task ~node:g (Locked l) GoblintCil.one in
6961
Queries.YS.add entry acc
7062
) locked entries
7163
in
7264
let entries =
7365
Unlocked.fold (fun l acc ->
74-
let variable = WitnessGhost.name_varinfo (Locked l) in
75-
let expression = "0" in
76-
let entry = YamlWitness.Entry.ghost_update ~task ~location ~variable ~expression in
66+
let entry = WitnessGhost.update_entry ~task ~node:g (Locked l) GoblintCil.zero in
7767
Queries.YS.add entry acc
7868
) unlocked entries
7969
in
8070
let entries =
8171
if not (GobConfig.get_bool "exp.earlyglobs") && multithread then (
82-
let variable = WitnessGhost.name_varinfo Multithreaded in
83-
let type_ = "int" in
84-
let initial = "0" in
85-
let entry = YamlWitness.Entry.ghost_variable ~task ~variable ~type_ ~initial in
86-
let expression = "1" in
87-
let entry' = YamlWitness.Entry.ghost_update ~task ~location ~variable ~expression in
72+
let entry = WitnessGhost.variable_entry ~task Multithreaded in
73+
let entry' = WitnessGhost.update_entry ~task ~node:g Multithreaded GoblintCil.one in
8874
Queries.YS.add entry (Queries.YS.add entry' entries)
8975
)
9076
else

src/witness/witnessGhost.ml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,32 @@ struct
1212
| Multithreaded -> "multithreaded"
1313

1414
(* TODO: define correct types *)
15+
16+
let type_ = function
17+
| Locked _ -> GoblintCil.intType
18+
| Multithreaded -> GoblintCil.intType
19+
20+
let initial = function
21+
| Locked _ -> GoblintCil.zero
22+
| Multithreaded -> GoblintCil.zero
1523
end
1624

1725
include Var
1826

1927
module Map = RichVarinfo.Make (Var)
2028

2129
include Map
30+
31+
let variable_entry ~task x =
32+
let variable = name_varinfo x in
33+
let type_ = String.trim (CilType.Typ.show (type_ x)) in (* CIL printer puts space at the end of some types *)
34+
let initial = CilType.Exp.show (initial x) in
35+
YamlWitness.Entry.ghost_variable ~task ~variable ~type_ ~initial
36+
37+
let update_entry ~task ~node x e =
38+
let loc = Node.location node in
39+
let location_function = (Node.find_fundec node).svar.vname in
40+
let location = YamlWitness.Entry.location ~location:loc ~location_function in
41+
let variable = name_varinfo x in
42+
let expression = CilType.Exp.show e in
43+
YamlWitness.Entry.ghost_update ~task ~location ~variable ~expression

0 commit comments

Comments
 (0)