forked from ocaml-flambda/flambda-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchecks.ml
66 lines (49 loc) · 1.84 KB
/
checks.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
module String = Misc.Stdlib.String
(* CR gyorsh: Add [t] per analysis when at least one more analysis is
implemented *)
type t =
{ mutable zero_alloc : int String.Map.t;
mutable enabled : bool
}
let create () = { zero_alloc = String.Map.empty; enabled = false }
let reset t =
t.zero_alloc <- String.Map.empty;
t.enabled <- false
let merge src ~into:dst =
let join key b1 b2 =
Misc.fatal_errorf "Unexpected merge %s %d %d" key b1 b2
in
dst.zero_alloc <- String.Map.union join dst.zero_alloc src.zero_alloc;
dst.enabled <- dst.enabled || src.enabled
type value = int option
let get_value (t : t) s : value = String.Map.find_opt s t.zero_alloc
let get_value (t : t) s : value option =
match t.enabled with false -> None | true -> Some (get_value t s)
let set_value (t : t) s (v : value) =
let f new_ old =
if not (Option.is_none old)
then Misc.fatal_errorf "Value of %s is already set" s;
new_
in
t.zero_alloc <- String.Map.update s (f v) t.zero_alloc;
t.enabled <- true
module Raw = struct
type entries = (string * int) list
type r = { zero_alloc : entries }
type t = r option
let entries_to_map (e : entries) =
List.fold_left (fun acc (k, v) -> String.Map.add k v acc) String.Map.empty e
let print t =
let print (name, v) = Printf.printf "\t\t%s = %#x\n" name v in
(* CR gyorsh: move encode/decode here somehow for noalloc *)
Printf.printf "Function summaries for static checks:\n";
List.iter print t.zero_alloc
let print = function None -> () | Some t -> print t
end
let to_raw (t : t) : Raw.r = { zero_alloc = String.Map.bindings t.zero_alloc }
let to_raw (t : t) : Raw.t =
match t.enabled with false -> None | true -> Some (to_raw t)
let of_raw (t : Raw.t) : t =
match t with
| None -> create ()
| Some t -> { zero_alloc = Raw.entries_to_map t.zero_alloc; enabled = true }