File: symbConstant.ml

package info (click to toggle)
herdtools7 7.58-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 19,732 kB
  • sloc: ml: 128,583; ansic: 3,827; makefile: 670; python: 407; sh: 212; awk: 14
file content (82 lines) | stat: -rw-r--r-- 2,946 bytes parent folder | download
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
(****************************************************************************)
(*                           the diy toolsuite                              *)
(*                                                                          *)
(* Jade Alglave, University College London, UK.                             *)
(* Luc Maranget, INRIA Paris-Rocquencourt, France.                          *)
(*                                                                          *)
(* Copyright 2010-present Institut National de Recherche en Informatique et *)
(* en Automatique, ARM Ltd and the authors. All rights reserved.            *)
(*                                                                          *)
(* This software is governed by the CeCILL-B license under French law and   *)
(* abiding by the rules of distribution of free software. You can use,      *)
(* modify and/ or redistribute the software under the terms of the CeCILL-B *)
(* license as circulated by CEA, CNRS and INRIA at the following URL        *)
(* "http://www.cecill.info". We also give a copy in LICENSE.txt.            *)
(****************************************************************************)

module Make
         (Scalar:Scalar.S)
         (PteVal:PteVal.S)
         (Instr:Instr.S) = struct

  module Scalar = Scalar
  module PteVal = PteVal
  module Instr = Instr

  type v = (Scalar.t,PteVal.t,Instr.t) Constant.t
  open Constant

  let tr c = Constant.map Scalar.of_string PteVal.tr Instr.tr c

  let intToV i = Concrete (Scalar.of_int i)
  and nameToV s = Constant.mk_sym s
  and stringToV s = Concrete (Scalar.of_string s)

  let bit_at k v = Scalar.bit_at k v

  let zero = Concrete Scalar.zero
  and one = Concrete Scalar.one
  and cst_true = Concrete Scalar.s_true
  and cst_false = Concrete Scalar.s_false

  let as_int = function
    | Concrete c ->
       begin
         try Some (Scalar.to_int c)
         with Invalid_argument _ -> None
       end
    | _ -> None

  let as_bool = function
    | Concrete c -> Scalar.as_bool c
    | _ -> None

  let pp_instr_cst i = Instr.pp i

  let pp hexa =
    Constant.pp (Scalar.pp hexa) (PteVal.pp hexa) pp_instr_cst
  and pp_unsigned hexa =
    Constant.pp (Scalar.pp_unsigned hexa) (PteVal.pp hexa) pp_instr_cst

  let pp_v = pp false
  let pp_v_old =
    Constant.pp_old (Scalar.pp false) (PteVal.pp false) pp_instr_cst

  let compare c1 c2 =
    Constant.compare Scalar.compare PteVal.compare Instr.compare c1 c2
  let eq c1 c2 = Constant.eq Scalar.equal PteVal.eq Instr.eq c1 c2

(* For building code symbols. *)
  let vToName = function
    | Symbolic s-> Constant.as_address s
    | Concrete _|ConcreteVector _|ConcreteRecord _| Label _|Tag _
    | PteVal _|Instruction _|Frozen _
        -> assert false

  let is_nop = function
    | Instruction i -> Instr.is_nop i
    | Symbolic _|Concrete _|ConcreteRecord _|ConcreteVector _ | Label _|Tag _|PteVal _
    | Frozen _
      -> false

end