package codex

  1. Overview
  2. Docs
The Codex library for building static analysers based on abstract interpretation

Install

dune-project
 Dependency

Authors

Maintainers

Sources

1.0-rc4.tar.gz
md5=bc7266a140c6886add673ede90e335d3
sha512=8da42c0ff2c1098c5f9cb2b5b43b306faf7ac93b8f5ae00c176918cee761f249ff45b29309f31a05bbcf6312304f86a0d5a000eb3f1094d3d3c2b9b4c7f5c386

doc/src/codex.single_value_abstraction/sva_log.ml.html

Source file sva_log.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
(**************************************************************************)
(*  This file is part of the Codex semantics library.                     *)
(*                                                                        *)
(*  Copyright (C) 2013-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 LICENSE).                      *)
(*                                                                        *)
(**************************************************************************)

module Sig = Sva_sig

module No_Log_Numeric_Enum(Log:Tracelog.S)(Sub:Sig.NUMERIC_ENUM):Sig.NUMERIC_ENUM = Sub

module Log_Numeric_Enum(Log:Tracelog.S)(Sub:Sig.NUMERIC_ENUM):Sig.NUMERIC_ENUM = struct
  let name = Sub.name

  type boolean = Sub.boolean
  type bitvector = Sub.bitvector
  type integer = Sub.integer
  type enum = Sub.enum

  module Boolean_Lattice = Sub.Boolean_Lattice
  module Bitvector_Lattice = Sub.Bitvector_Lattice
  module Enum_Lattice = Sub.Enum_Lattice
  module Integer_Lattice = struct
    include Sub.Integer_Lattice
    let join a b =
      Log.trace (fun p -> p "join %a %a" pretty a pretty b) ~pp_ret:pretty (fun () -> join a b)

    let includes_or_widen ~previous next =
      Log.trace (fun p -> p "includes_or_widen %a %a" pretty previous pretty next) ~pp_ret:(fun fmt (p, b) ->
        Format.fprintf fmt "%b,%a" p pretty b)
        (fun () -> includes_or_widen ~previous next)
  end

  open Operator

  module Conversion = struct
    type boolean = Sub.boolean
    type integer = Sub.integer
    type enum = Sub.enum
    type bitvector = Sub.bitvector

    type 'a pp = Format.formatter -> 'a -> unit

    let bool_printer = Sub.Boolean_Lattice.pretty
    let enum_printer = Sub.Enum_Lattice.pretty
    let integer_printer = Sub.Integer_Lattice.pretty
    let bv_printer = Sub.Bitvector_Lattice.pretty
  end

  module Forward_Conversion = struct
    include Conversion
    module Arity = Forward_Arity

    let ar0 pp_ret pp f =
      Log.trace (fun p -> p "forward %t" pp) ~pp_ret @@ fun () -> f

    let ar1 ppa pp_ret pp f a =
      Log.trace (fun p -> p "forward %t %a" pp ppa a) ~pp_ret @@ fun () -> f a

    let ar2 ppa ppb pp_ret pp f a b =
      Log.trace (fun p -> p "forward %t %a %a" pp ppa a ppb b) ~pp_ret
      @@ fun () -> f a b
  end

  module Backward_Conversion = struct
    include Conversion
    module Arity = Backward_Arity

    let pp_option pp fmt = function
      | None -> Format.fprintf fmt "unchanged"
      | Some x -> pp fmt x

    let pp_option_pair ppa ppb fmt (a, b) =
      Format.fprintf fmt "(%a,%a)" (pp_option ppa) a (pp_option ppb) b

    let ar0 pp_ret pp f = assert false

    let ar1 ppa pp_ret pp f a r =
      Log.trace
        (fun p -> p "backward %t %a %a" pp ppa a pp_ret r)
        ~pp_ret:(pp_option ppa)
      @@ fun () -> f a r

    let ar2 ppa ppb pp_ret pp f a b r =
      Log.trace
        (fun p -> p "backward %t %a %a %a" pp ppa a ppb b pp_ret r)
        ~pp_ret:(pp_option_pair ppa ppb)
      @@ fun () -> f a b r
  end

  module Boolean_Forward = struct
    include Autolog.Log_Boolean_Backward(Forward_Conversion)(Sub.Boolean_Forward)
    let true_ = Sub.Boolean_Forward.true_
    let false_ = Sub.Boolean_Forward.false_
  end

  module Boolean_Backward =
    Autolog.Log_Boolean_Backward(Backward_Conversion)(Sub.Boolean_Backward)

  module Integer_Forward = struct
    include Autolog.Log_Integer_Backward(Forward_Conversion)(Sub.Integer_Forward)

    let zero = Sub.Integer_Forward.zero
    let one = Sub.Integer_Forward.one

    let iconst z =
      Forward_Conversion.ar0 Forward_Conversion.integer_printer
        (fun fmt -> Format.fprintf fmt "iconst %s" (Z.to_string z))
        (Sub.Integer_Forward.iconst z)
  end

  module Integer_Backward =
    Autolog.Log_Integer_Backward(Backward_Conversion) (Sub.Integer_Backward)



  module Bitvector_Forward =
    Autolog.Log_Bitvector_Forward_With_Bimul_add(Forward_Conversion)(Sub.Bitvector_Forward)

  module Bitvector_Backward =
    Autolog.Log_Bitvector_Forward_With_Bimul_add
      (Backward_Conversion)
      (struct
        include Sub.Bitvector_Backward
        let biconst ~size _ = assert false
      end)

  module Enum_Forward = Autolog.Log_Enum_Forward(Forward_Conversion)(Sub.Enum_Forward)

  module Enum_Backward =
    Autolog.Log_Enum_Forward
      (Backward_Conversion)
      (struct
        include Sub.Enum_Backward
        let enum_const ~case = assert false
      end)
end