Skip to content

Commit 9d57a66

Browse files
DLS Shim
1 parent d1db705 commit 9d57a66

4 files changed

Lines changed: 82 additions & 3 deletions

File tree

dune-project

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ This is a fork of the 'cil' package used for 'goblint'. Major changes include:
3535
conf-perl
3636
cppo
3737
conf-gcc
38-
domain_shims
3938
)
4039
(conflicts cil) ; only because we both install the cilly executable
4140
)

goblint-cil.opam

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ depends: [
4242
"conf-perl"
4343
"cppo"
4444
"conf-gcc"
45-
"domain_shims"
4645
]
4746
conflicts: ["cil"]
4847
build: [

src/domain.ocaml4.ml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
module Domain = struct
2+
3+
(**************************************************************************)
4+
(* *)
5+
(* OCaml *)
6+
(* *)
7+
(* KC Sivaramakrishnan, Indian Institute of Technology, Madras *)
8+
(* Stephen Dolan, University of Cambridge *)
9+
(* Tom Kelly, OCaml Labs Consultancy *)
10+
(* *)
11+
(* Copyright 2019 Indian Institute of Technology, Madras *)
12+
(* Copyright 2014 University of Cambridge *)
13+
(* Copyright 2021 OCaml Labs Consultancy Ltd *)
14+
(* *)
15+
(* All rights reserved. The type DLST is distributed under the terms of *)
16+
(* the GNU Lesser General Public License version 2.1, with the *)
17+
(* special exception on linking described in the LICENSE file *)
18+
(* of the OCaml distribution: *)
19+
(* https://github.com/ocaml/ocaml/blob/4.14.0/LICENSE *)
20+
(* *)
21+
(**************************************************************************)
22+
23+
module type DLSS = sig
24+
(** Domain-local Storage *)
25+
26+
type 'a key
27+
(** Type of a DLS key *)
28+
29+
val new_key : ?split_from_parent:('a -> 'a) -> (unit -> 'a) -> 'a key
30+
(** [new_key f] returns a new key bound to initialiser [f] for accessing
31+
domain-local variables.
32+
33+
If [split_from_parent] is provided, spawning a domain will derive the
34+
child value (for this key) from the parent value.
35+
36+
Note that the [split_from_parent] call is computed in the parent
37+
domain, and is always computed regardless of whether the child domain
38+
will use it. If the splitting function is expensive or requires
39+
client-side computation, consider using ['a Lazy.t key].
40+
*)
41+
42+
val get : 'a key -> 'a
43+
(** [get k] returns [v] if a value [v] is associated to the key [k] on
44+
the calling domain's domain-local state. Sets [k]'s value with its
45+
initialiser and returns it otherwise. *)
46+
47+
val set : 'a key -> 'a -> unit
48+
(** [set k v] updates the calling domain's domain-local state to associate
49+
the key [k] with value [v]. It overwrites any previous values associated
50+
to [k], which cannot be restored later. *)
51+
end
52+
53+
module DLS : DLSS = struct
54+
type 'a key = {
55+
value: 'a option ref;
56+
initialiser: unit -> 'a;
57+
}
58+
59+
let new_key ?split_from_parent initialiser =
60+
{ value = None; initialiser }
61+
62+
let get k =
63+
match k.value with
64+
| Some v -> v
65+
| None ->
66+
let v = k.initialiser () in
67+
k.value <- Some v;
68+
v
69+
70+
let set k v =
71+
k.value <- Some v
72+
end
73+
end

src/dune

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
(library
44
(public_name goblint-cil)
55
(name goblintCil)
6-
(libraries zarith unix str stdlib-shims domain_shims)
6+
(libraries zarith unix str stdlib-shims)
77
(modules (:standard \ main mainFeature ciloptions machdepConfigure machdepArchConfigure modelConfigure))
88
)
99

@@ -16,6 +16,14 @@
1616
(target machdep-config.h)
1717
(action (run ./machdepConfigure.exe)))
1818

19+
(rule
20+
(target domain.ml)
21+
(deps domain.ocaml4.ml)
22+
(enabled_if (< %{ocaml_version} 5.0))
23+
(action
24+
(progn
25+
(copy domain.ocaml4.ml domain.ml))))
26+
1927
(rule
2028
(deps machdep-config.h machdep-ml.c)
2129
(target machdep-ml.exe)

0 commit comments

Comments
 (0)