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
open Base
module type Std_logic = Logic_intf.Std_logic
module type Four_state = Logic_intf.Four_state
module Std_logic = struct
type t =
| U
| X
| L0
| L1
| Z
| W
| L
| H
| Don't_care
[@@deriving compare, enumerate, sexp, variants]
let optimise_muxs = false
let constant_only = true
let equal = [%compare.equal: t]
let to_char = function
| U -> 'U'
| X -> 'X'
| L0 -> '0'
| L1 -> '1'
| Z -> 'Z'
| W -> 'W'
| L -> 'L'
| H -> 'H'
| Don't_care -> '_'
;;
let of_char = function
| 'U' -> U
| 'X' -> X
| '0' -> L0
| '1' -> L1
| 'Z' -> Z
| 'W' -> W
| 'L' -> L
| 'H' -> H
| '_' -> Don't_care
| _ -> raise_s [%message "invalid char"]
;;
let sexp_of_t t = [%sexp (to_char t : char)]
let to_int = Variants.to_rank
let of_char_exn = function
| 'U' | 'u' -> U
| 'X' | 'x' -> X
| '0' -> L0
| '1' -> L1
| 'Z' | 'z' -> Z
| 'W' | 'w' -> W
| 'L' | 'l' -> L
| 'H' | 'h' -> H
| '_' -> Don't_care
| _ as char ->
raise_s [%message "[Std_logic.of_char_exn] got invalid char" (char : char)]
;;
let to_x : t -> Bits_list.X.t = function
| L0 -> F
| L1 -> T
| U | X | Z | W | L | H | Don't_care -> X
;;
let of_x : Bits_list.X.t -> t = function
| F -> L0
| T -> L1
| X -> X
;;
let gnd = L0
let vdd = L1
let as_x f a b = of_x (f (to_x a) (to_x b))
let ( &: ) = as_x Bits_list.X.( &: )
let ( |: ) = as_x Bits_list.X.( |: )
let ( ^: ) = as_x Bits_list.X.( ^: )
let ( ~: ) a = of_x (Bits_list.X.( ~: ) (to_x a))
end
module Four_state = struct
type t =
| X
| Z
| L0
| L1
[@@deriving compare, enumerate, sexp, variants]
let optimise_muxs = false
let constant_only = true
let equal = [%compare.equal: t]
let to_char = function
| X -> 'x'
| Z -> 'z'
| L0 -> '0'
| L1 -> '1'
;;
let of_char = function
| 'X' -> X
| 'Z' -> Z
| '0' -> L0
| '1' -> L1
| _ -> raise_s [%message "invalid char"]
;;
let sexp_of_t t = [%sexp (to_char t : char)]
let to_int = Variants.to_rank
let of_char_exn = function
| 'X' | 'x' -> X
| 'Z' | 'z' -> Z
| '0' -> L0
| '1' -> L1
| _ as char ->
raise_s [%message "[Std_logic.of_char_exn] got invalid char" (char : char)]
;;
let to_x : t -> Bits_list.X.t = function
| L0 -> F
| L1 -> T
| Z | X -> X
;;
let of_x : Bits_list.X.t -> t = function
| F -> L0
| T -> L1
| X -> X
;;
let gnd = L0
let vdd = L1
let as_x f a b = of_x (f (to_x a) (to_x b))
let ( &: ) = as_x Bits_list.X.( &: )
let ( |: ) = as_x Bits_list.X.( |: )
let ( ^: ) = as_x Bits_list.X.( ^: )
let ( ~: ) a = of_x (Bits_list.X.( ~: ) (to_x a))
end
module Std_logic_vector = Bits_list.Make (Std_logic)
module Bit_vector = Bits_list.Int_comb
module Four_state_vector = Bits_list.Make (Four_state)