package frama-c

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file mt_shared_vars_types.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
(**************************************************************************)
(*                                                                        *)
(*  This file is part of Frama-C.                                         *)
(*                                                                        *)
(*  Copyright (C) 2007-2025                                               *)
(*    CEA (Commissariat à l'énergie atomique et aux énergies              *)
(*         alternatives)                                                  *)
(*                                                                        *)
(*  you can redistribute it and/or modify it under the terms of the GNU   *)
(*  Lesser General Public License as published by the Free Software       *)
(*  Foundation, version 2.1.                                              *)
(*                                                                        *)
(*  It is distributed in the hope that it will be useful,                 *)
(*  but WITHOUT ANY WARRANTY; without even the implied warranty of        *)
(*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *)
(*  GNU Lesser General Public License for more details.                   *)
(*                                                                        *)
(*  See the GNU Lesser General Public License version 2.1                 *)
(*  for more details (enclosed in the file licenses/LGPLv2.1).            *)
(*                                                                        *)
(**************************************************************************)

open Mt_types



(* Sets of zone accesses (used in cfg nodes) *)
module SetZoneAccess = struct

  module P = Datatype.Pair(RW)(Locations.Zone)

  include Datatype.Set(Set.Make(P))(P)

  let to_two_zones (s: t) =
    let aux (rw, z) (r, w) =
      match rw with
      | Read -> (Locations.Zone.join r z, w)
      | Write _ -> (r, Locations.Zone.join w z)
      | ReadAloc _ -> (Locations.Zone.join r z, w)
      | WriteAloc _ -> (r, Locations.Zone.join w z)
    in
    fold aux s (Locations.Zone.bottom, Locations.Zone.bottom)


  let pretty_sep ~sep fmt s =
    let r, w = to_two_zones s in
    match Locations.Zone.(is_bottom r, is_bottom w) with
    | true, true -> ()
    | false, true -> Format.fprintf fmt "reads %a" Locations.Zone.pretty r
    | true, false -> Format.fprintf fmt "writes %a" Locations.Zone.pretty w
    | false, false ->
      Format.fprintf fmt "reads %a%(%)writes %a"
        Locations.Zone.pretty r sep Locations.Zone.pretty w

  let pretty = pretty_sep ~sep:",@,"
end



module StmtIdAccess = struct

  include Datatype.Triple_with_collections(RW)(Cil_datatype.Stmt)(Thread)

  let pretty fmt ((op, stmt, th) : t) =
    let loc = Cil_datatype.Stmt.loc stmt in
    match op with
    | Read | Write _ ->
      Format.fprintf fmt "%a@ by %a@ at %a"
        RW.pretty op Thread.pretty th Printer.pp_location loc
    | ReadAloc _ | WriteAloc _ ->
      Format.fprintf fmt "%a@ by %a@ at %a"
        RW.pretty_op op
        Thread.pretty th
        RW.pretty_loc op

end


module SetStmtIdAccess = struct
  include Abstract_interp.Make_Lattice_Set (StmtIdAccess) (StmtIdAccess.Set)

  let pretty = Pretty_utils.pp_iter ~pre:"@[<v>" ~sep:"@ " iter
      (fun fmt v -> Format.fprintf fmt "@[<hov 2>%a@]" StmtIdAccess.pretty v)
  ;;

  let pretty_aux _f = pretty

end

module AccessesByZone = struct
  include Lmap_bitwise.Make_bitwise(
    struct
      include SetStmtIdAccess
      let default = bottom
      let default_is_bottom = true
    end)

  let pretty_map fmt m =
    Format.fprintf fmt "@[<v>";
    fold_fuse_same
      (fun z s () ->
         if not (SetStmtIdAccess.(equal empty s)) then
           Format.fprintf fmt "@[<hov 2>%a:@ %a@]@ "
             Locations.Zone.pretty z (SetStmtIdAccess.pretty) s
      ) m ();
    Format.fprintf fmt "@]";
  ;;

  let pretty fmt = function
    | Top -> Format.pp_print_string fmt "TOP ACCESSES"
    | Bottom -> Format.pp_print_string fmt "BOTTOM ACCESSES"
    | Map m -> pretty_map fmt m

end