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
|
(* only expected to be 0, 1, 2; 2 represents undef *)
type vbit = int
type number = int64 (*Actually needs to be big_int_z but I forget the incantation for that right now*)
type value =
| Vvector of vbit array * int * bool
| VvectorR of value array * int * bool
| Vregister of vbit array * int * bool * (string * (int * int)) list
| Vundef (*For a few circumstances of undefined registers in VvectorRs built with sparse vectors*)
let to_bool = function
| 0 -> false
| 1 -> true
| _ -> assert false
let get_barray = function
| Vvector(a,_,_)
| Vregister(a,_,_,_) -> a
| _ -> assert false
let get_varray = function
| VvectorR(a,_,_) -> a
| _ -> assert false
let vector_access v n = match v with
| VvectorR(array,start,is_inc) ->
if is_inc
then array.(n-start)
else array.(start-n)
| _ -> assert false
let bit_vector_access v n = match v with
| Vvector(array,start,is_inc) | Vregister(array,start,is_inc,_) ->
if is_inc
then array.(n-start)
else array.(start-n)
| _ -> assert false
let vector_subrange v n m =
let builder array length offset default =
let new_array = Array.make length default in
begin
for x = 0 to length-1
do new_array.(x) <- array.(x+offset)
done;
new_array
end
in
match v with
| VvectorR(array,start,is_inc) ->
let (length,offset) = if is_inc then (m-n+1,n-start) else (n-m+1,start-n) in
VvectorR(builder array length offset (VvectorR([||], 0, true)),n,is_inc)
| Vvector(array,start,is_inc) ->
let (length,offset) = if is_inc then (m-n+1,n-start) else (n-m+1,start-n) in
Vvector(builder array length offset 0,n,is_inc)
| Vregister(array,start,is_inc,fields) ->
let (length,offset) = if is_inc then (m-n+1,n-start) else (n-m+1,start-n) in
Vvector(builder array length offset 0,n,is_inc)
| _ -> v
|