Skip to content
Snippets Groups Projects
Commit d0cb80a7 authored by Loïc Correnson's avatar Loïc Correnson
Browse files

[wp/region] refactor MemRegion

parent 400051de
No related branches found
No related tags found
No related merge requests found
...@@ -49,3 +49,4 @@ let exp m e = Option.map (Memory.node m) @@ Memory.exp m e ...@@ -49,3 +49,4 @@ let exp m e = Option.map (Memory.node m) @@ Memory.exp m e
let cvar = Memory.cvar let cvar = Memory.cvar
let field = Memory.field let field = Memory.field
let index = Memory.index let index = Memory.index
let shift m r ~size = Memory.sindex m r size
...@@ -125,3 +125,7 @@ val field : map -> node -> fieldinfo -> node ...@@ -125,3 +125,7 @@ val field : map -> node -> fieldinfo -> node
(** Unormalized. @raises Not_found *) (** Unormalized. @raises Not_found *)
val index : map -> node -> typ -> node val index : map -> node -> typ -> node
(** The size if the size of elements of the array, in bits.
Unormalized. @raises Not_found *)
val shift : map -> node -> size:int -> node
...@@ -567,6 +567,9 @@ let field (m: map) (r: node) (fd: fieldinfo) : node = ...@@ -567,6 +567,9 @@ let field (m: map) (r: node) (fd: fieldinfo) : node =
let index (m : map) (r: node) (ty:typ) : node = let index (m : map) (r: node) (ty:typ) : node =
move m r 0 (Cil.bitsSizeOf ty) move m r 0 (Cil.bitsSizeOf ty)
let sindex (m: map) (r: node) (size:int) : node =
move m r 0 size
let rec lval (m: map) (h,ofs) : node = let rec lval (m: map) (h,ofs) : node =
offset m (lhost m h) (Cil.typeOfLhost h) ofs offset m (lhost m h) (Cil.typeOfLhost h) ofs
......
...@@ -96,6 +96,7 @@ val merge_copy : map -> l:node -> r:node -> unit ...@@ -96,6 +96,7 @@ val merge_copy : map -> l:node -> r:node -> unit
val cvar : map -> varinfo -> node val cvar : map -> varinfo -> node
val field : map -> node -> fieldinfo -> node val field : map -> node -> fieldinfo -> node
val index : map -> node -> typ -> node val index : map -> node -> typ -> node
val sindex : map -> node -> int -> node
val lval : map -> lval -> node val lval : map -> lval -> node
val exp : map -> exp -> node option val exp : map -> exp -> node option
......
This diff is collapsed.
...@@ -36,15 +36,12 @@ val pp_kind : Format.formatter -> kind -> unit ...@@ -36,15 +36,12 @@ val pp_kind : Format.formatter -> kind -> unit
module type RegionProxy = module type RegionProxy =
sig sig
type region type region
val null : unit -> region module Type : Sigs.Type with type t = region
val hash : region -> int
val equal : region -> region -> bool
val compare : region -> region -> int
val pretty : Format.formatter -> region -> unit
val kind : region -> kind val kind : region -> kind
val null : unit -> region
val tau_of_region : region -> tau val tau_of_region : region -> tau
val points_to : region -> region option val points_to : region -> region option
...@@ -60,7 +57,7 @@ sig ...@@ -60,7 +57,7 @@ sig
val pointer_loc : unit -> region option val pointer_loc : unit -> region option
val loc_of_int : unit -> region option val loc_of_int : unit -> region option
val id_of_region : region -> int val id : region -> int
val region_of_id : int -> region option val region_of_id : int -> region option
end end
......
...@@ -35,19 +35,20 @@ let null () : region = ...@@ -35,19 +35,20 @@ let null () : region =
~effect:"Create null pointer value" "NULL" ; ~effect:"Create null pointer value" "NULL" ;
Wp_parameters.not_yet_implemented "[WP/RegionAnalysis.ml] null: cannot create null region" Wp_parameters.not_yet_implemented "[WP/RegionAnalysis.ml] null: cannot create null region"
let id_of_region region = Region.uid (get_map ()) region let id region = Region.uid (get_map ()) region
let region_of_id id = let region_of_id id =
try Some (Region.find (get_map ()) id) try Some (Region.find (get_map ()) id)
with Not_found -> None with Not_found -> None
let hash = Region.id module Type =
struct
let equal r1 r2 = (Region.id r1 = Region.id r2) type t = region
let hash = Region.id
let compare r1 r2 = Int.compare (Region.id r1) (Region.id r2) let equal r1 r2 = (Region.id r1 = Region.id r2)
let compare r1 r2 = Int.compare (Region.id r1) (Region.id r2)
let pretty fmt r = Format.fprintf fmt "R%03d" @@ Region.id r let pretty fmt r = Format.fprintf fmt "R%03d" @@ Region.id r
end
let types r = let types r =
let module Tset = Cil_datatype.Typ.Set in let module Tset = Cil_datatype.Typ.Set in
...@@ -60,13 +61,7 @@ let types r = ...@@ -60,13 +61,7 @@ let types r =
Tset.elements !pool Tset.elements !pool
(* Keeping track of the decision to apply which memory model to each region *) (* Keeping track of the decision to apply which memory model to each region *)
module Kind = WpContext.Generator module Kind = WpContext.Generator(Type)
(struct
(* Key : WPContext.Key *)
type t = region
let compare = compare
let pretty = pretty
end)
(struct (struct
(* Data : WpContext.Data with type key = Key.t *) (* Data : WpContext.Data with type key = Key.t *)
type key = region type key = region
...@@ -113,7 +108,7 @@ let field (region: region) (fd: fieldinfo) : region option = ...@@ -113,7 +108,7 @@ let field (region: region) (fd: fieldinfo) : region option =
~source:"RegionAnalysis.field" ~source:"RegionAnalysis.field"
~effect:"No region found for field" ~effect:"No region found for field"
"No region for field %a from region %a" "No region for field %a from region %a"
Printer.pp_field fd pretty region; Printer.pp_field fd Type.pretty region;
None None
let shift region ty offset = let shift region ty offset =
...@@ -123,7 +118,7 @@ let shift region ty offset = ...@@ -123,7 +118,7 @@ let shift region ty offset =
~source:"RegionAnalysis.shift" ~source:"RegionAnalysis.shift"
~effect:"No region found" ~effect:"No region found"
"No region for shift %a from region %a" "No region for shift %a from region %a"
QED.pretty offset pretty region; QED.pretty offset Type.pretty region;
None None
| typ :: rest -> | typ :: rest ->
try Some (Region.index (get_map ()) region typ) try Some (Region.index (get_map ()) region typ)
......
...@@ -129,6 +129,15 @@ type update = Mstore of s_lval * term ...@@ -129,6 +129,15 @@ type update = Mstore of s_lval * term
(** {1 Memory Models} *) (** {1 Memory Models} *)
(* -------------------------------------------------------------------------- *) (* -------------------------------------------------------------------------- *)
module type Type =
sig
type t
val hash : t -> int
val equal : t -> t -> bool
val compare : t -> t -> int
val pretty : Format.formatter -> t -> unit
end
(** Memory Chunks. (** Memory Chunks.
The concrete memory is partionned into a vector of abstract data. The concrete memory is partionned into a vector of abstract data.
...@@ -148,10 +157,7 @@ sig ...@@ -148,10 +157,7 @@ sig
val self : string val self : string
(** Chunk names, for pretty-printing. *) (** Chunk names, for pretty-printing. *)
val hash : t -> int include Type with type t := t
val equal : t -> t -> bool
val compare : t -> t -> int
val pretty : Format.formatter -> t -> unit
val tau_of_chunk : t -> tau val tau_of_chunk : t -> tau
(** The type of data hold in a chunk. *) (** The type of data hold in a chunk. *)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment