package frama-c

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

Source file RegionAnalysis.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
(**************************************************************************)
(*                                                                        *)
(*  This file is part of WP plug-in of Frama-C.                           *)
(*                                                                        *)
(*  Copyright (C) 2007-2024                                               *)
(*    CEA (Commissariat a l'energie atomique et aux energies              *)
(*         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 Cil_types
module Wp = Wp_parameters
module Kf = Kernel_function

(* ---------------------------------------------------------------------- *)
(* --- Compute Analysis                                               --- *)
(* ---------------------------------------------------------------------- *)

let compute kf =
  let map = Region.create () in
  if Kf.is_definition kf then
    begin
      Wp.feedback ~ontty:`Transient "[region] Analyzing %a" Kf.pretty kf ;
      let def = Kf.get_definition kf in
      RegionAccess.cc_fundec map def ;
      Populate_spec.populate_funspec kf [`Assigns];
      let spec = Annotations.funspec kf in
      RegionAccess.cc_spec map spec ;
      List.iter
        (fun bhv ->
           let region_specs = RegionAnnot.of_behavior bhv in
           if region_specs <> [] then
             if Cil.is_default_behavior bhv then
               List.iter (RegionAccess.cc_region map) region_specs
             else
               Wp.warning ~once:true
                 "Region specifications in non-default behaviours are skipped."
        ) spec.spec_behavior ;
      if Wp.Region_fixpoint.get () then Region.fixpoint map ;
    end ;
  map

(* ---------------------------------------------------------------------- *)
(* --- Projectified Analysis Result                                   --- *)
(* ---------------------------------------------------------------------- *)

module REGION = Datatype.Make
    (struct
      type t = Region.map
      include Datatype.Undefined
      let reprs = [Region.create ()]
      let name = "Wp.RegionAnalysis.region"
      let mem_project = Datatype.never_any_project
    end)

module GLOBAL = State_builder.Ref
    (REGION)
    (struct
      let name = "Wp.RegionAnalysis.ref"
      let dependencies = [Ast.self]
      let default = Region.create
    end)

module REGISTRY = State_builder.Hashtbl
    (Kernel_function.Hashtbl)
    (REGION)
    (struct
      let name = "Wp.RegionAnalysis.registry"
      let dependencies = [Ast.self]
      let size = 32
    end)

let get = function
  | None -> GLOBAL.get ()
  | Some kf ->
    try REGISTRY.find kf
    with Not_found ->
      let map = compute kf in
      REGISTRY.add kf map ; map

(* ---------------------------------------------------------------------- *)
(* --- Command Line Registry                                          --- *)
(* ---------------------------------------------------------------------- *)

let main () =
  if Wp.Region.get () then
    begin
      Ast.compute () ;
      let dump =
        if Wp_parameters.Region_output_dot.is_set () then
          RegionDump.dump_in_file ~file:(Wp_parameters.Region_output_dot.get())
        else
          RegionDump.dump_in_dir ~dir:(Wp.get_output_dir "region")
      in
      Wp.iter_kf (fun kf ->
          let map = get (Some kf) in
          if not (Region.is_empty map) then
            dump (Kernel_function.get_name kf) map
        ) ;
    end

let () = Boot.Main.extend main

(* ---------------------------------------------------------------------- *)
OCaml

Innovation. Community. Security.