]> matita.cs.unibo.it Git - pkg-cerco/acc.git/blob - src/common/intValue.mli
Package description and copyright added.
[pkg-cerco/acc.git] / src / common / intValue.mli
1
2 (** This module defines functions to manipulate bounded integers. They can be
3     used to represent sequences of bits. *)
4
5 (* Integers, whatever their size, will be represented using the Big_int
6    module. This allows immediate conversion, and allows the representation of
7    any integer (that fits into memory). *)
8
9 type int_repr 
10 val print_int_repr : int_repr -> string
11
12 (* The parameter module. Bounded integers are characterized by the number of
13    bits used to represent them. *)
14     
15 module type INTTYPE = 
16 sig
17   val size : int (* in bytes *)
18 end
19
20 (* The signature provided to manipulate bounded integers. *)
21
22 module type S = sig
23
24   type t
25   type repr
26
27   val compare   : t -> t -> int
28   val to_string : t -> string
29   val zero      : t
30   val one       : t
31
32   val to_signed_repr   : t -> repr
33   val to_unsigned_repr : t -> repr
34
35   val succ    : t -> t
36   val pred    : t -> t
37   val add     : t -> t -> t
38   (** [add_of i1 i2] returns [true] iff adding [i1] and [i2] overflows. *)
39   val add_of  : t -> t -> bool
40   val sub     : t -> t -> t
41   (** [sub_uf i1 i2] returns [true] iff substracting [i1] and [i2]
42       underflows. *)
43   val sub_uf  : t -> t -> bool
44   val mul     : t -> t -> t
45   val div     : t -> t -> t
46   val divu    : t -> t -> t
47   val modulo  : t -> t -> t
48   val modulou : t -> t -> t
49   val eq      : t -> t -> bool
50   val neq     : t -> t -> bool
51   val lt      : t -> t -> bool
52   val ltu     : t -> t -> bool
53   val le      : t -> t -> bool
54   val leu     : t -> t -> bool
55   val gt      : t -> t -> bool
56   val gtu     : t -> t -> bool
57   val ge      : t -> t -> bool
58   val geu     : t -> t -> bool
59   val neg     : t -> t
60   val lognot  : t -> t
61   val logand  : t -> t -> t
62   val logor   : t -> t -> t
63   val logxor  : t -> t -> t
64   val shl     : t -> t -> t
65   val shr     : t -> t -> t
66   val shrl    : t -> t -> t
67   val max     : t -> t -> t
68   val maxu    : t -> t -> t
69   val min     : t -> t -> t
70   val minu    : t -> t -> t
71   val cast    : repr -> t
72   val of_int  : int -> t
73   val to_int  : t -> int
74
75   (** [zero_ext n a] performs zero extension on [a] where [n] bits are
76       significant. *)
77   val zero_ext : int -> t -> t
78   (** [sign_ext n a] performs sign extension on [a] where [n] bits are
79       significant. *)
80   val sign_ext : int -> t -> t
81
82   (** [break i n] cuts [i] in [n] parts. In the resulting list, the first
83       element is the low bits, and the last is the high bits (little endian
84       representation). *)
85   val break : t -> int -> t list
86   (** [merge l] creates the integer where the first element of [l] is its low
87       bits, etc, and the last element of [l] is its high bits (little endian
88       representation). *)
89   val merge : t list -> t
90
91 end
92
93 module type SRepr = S with type t = int_repr and type repr = int_repr
94
95 (** The functor to create bounded integers from a size. *)
96
97 module Make: functor (IntType: INTTYPE) -> SRepr
98
99 module Int8  : SRepr
100 module Int16 : SRepr
101 module Int32 : SRepr
102
103 type int8  = Int8.t
104 type int16 = Int16.t
105 type int32 = Int32.t
106
107
108 (*
109 module Int8s   : S
110 module Int8u   : S
111 module Int16s  : S
112 module Int16u  : S
113 module Int32   : S
114
115 (** Unbounded integers. *)
116 module Integer : S
117
118 type int8s   = Int8s.t
119 type int8u   = Int8u.t
120 type int16s  = Int16s.t
121 type int16u  = Int16u.t
122 type int32   = Int32.t
123 type integer = Integer.t
124 *)