1
|
let base_types = ["integer"; "character"; "bit"; "real"; "natural"; "positive"; "std_logic"; "std_logic_vector" ]
|
2
|
|
3
|
type vhdl_type_t =
|
4
|
| Base of string
|
5
|
| Range of string option * int * int [@name "RANGE_WITH_DIRECTION"]
|
6
|
| Bit_vector of int * int
|
7
|
| Array of int * int * vhdl_type_t
|
8
|
| Enumerated of string list
|
9
|
| Void
|
10
|
[@@deriving yojson];;
|
11
|
|
12
|
(************************************************************************************)
|
13
|
(* Constants *)
|
14
|
(************************************************************************************)
|
15
|
|
16
|
(* Std_logic values :
|
17
|
'U': uninitialized. This signal hasn't been set yet.
|
18
|
'X': unknown. Impossible to determine this value/result.
|
19
|
'0': logic 0
|
20
|
'1': logic 1
|
21
|
'Z': High Impedance
|
22
|
'W': Weak signal, can't tell if it should be 0 or 1.
|
23
|
'L': Weak signal that should probably go to 0
|
24
|
'H': Weak signal that should probably go to 1
|
25
|
'-': Don't care. *)
|
26
|
let std_logic_cst = ["U"; "X"; "0"; "1"; "Z"; "W"; "L"; "H"; "-" ]
|
27
|
|
28
|
(* TODO: do we need more constructors ? *)
|
29
|
type cst_val_t = CstInt of int | CstStdLogic of string
|
30
|
[@@deriving yojson {strict = false}];;
|
31
|
|
32
|
type vhdl_subtype_indication_t =
|
33
|
{
|
34
|
name : string;
|
35
|
definition: vhdl_type_t option [@default Some (Void)];
|
36
|
}
|
37
|
[@@deriving yojson {strict = false}];;
|
38
|
|
39
|
(* TODO ? Shall we merge definition / declaration *)
|
40
|
type vhdl_definition_t =
|
41
|
| Type of {name : string ; definition: vhdl_type_t} [@name "TYPE_DECLARATION"]
|
42
|
| Subtype of {name : string ; typ : vhdl_subtype_indication_t} [@name "SUBTYPE_DECLARATION"]
|
43
|
[@@deriving yojson {strict = false}];;
|
44
|
|
45
|
type vhdl_declaration_t =
|
46
|
| VarDecl of { names : string list; typ : vhdl_subtype_indication_t; init_val : cst_val_t option [@default Some (CstInt (0))] } [@name "VARIABLE_DECLARATION"]
|
47
|
| CstDecl of { names : string list; typ : vhdl_subtype_indication_t; init_val : cst_val_t } [@name "CONSTANT_DECLARATION"]
|
48
|
| SigDecl of { names : string list; typ : vhdl_subtype_indication_t; init_val : cst_val_t option [@default Some (CstInt (0))] } [@name "SIGNAL_DECLARATION"]
|
49
|
[@@deriving yojson {strict = false}];;
|
50
|
|
51
|
(************************************************************************************)
|
52
|
(* Attributes for types, arrays, signals and strings *)
|
53
|
(************************************************************************************)
|
54
|
|
55
|
type 'basetype vhdl_type_attributes_t =
|
56
|
| TAttNoArg of { id: string }
|
57
|
| TAttIntArg of { id: string; arg: int }
|
58
|
| TAttValArg of { id: string; arg: 'basetype }
|
59
|
| TAttStringArg of { id: string; arg: string }
|
60
|
[@@deriving yojson {strict = false}];;
|
61
|
|
62
|
let typ_att_noarg = ["base"; "left"; "right"; "high"; "low"]
|
63
|
let typ_att_intarg = ["pos"; "val"; "succ"; "pred"; "leftof"; "rightof"]
|
64
|
let typ_att_valarg = ["image"]
|
65
|
let typ_att_stringarg = ["value"]
|
66
|
|
67
|
type vhdl_array_attributes_t = AAttInt of { id: string; arg: int; } | AAttAscending
|
68
|
[@@deriving yojson {strict = false}];;
|
69
|
|
70
|
let array_att_intarg = ["left"; "right"; "high"; "low"; "range"; "reverse_range"; "length"]
|
71
|
|
72
|
type vhdl_signal_attributes_t = SigAtt of string
|
73
|
[@@deriving yojson {strict = false}];;
|
74
|
|
75
|
type vhdl_string_attributes_t = StringAtt of string
|
76
|
[@@deriving yojson {strict = false}];;
|
77
|
|
78
|
(************************************************************************************)
|
79
|
(* Expressions / Statements *)
|
80
|
(************************************************************************************)
|
81
|
type suffix_selection_t = Idx of int | Range of int * int
|
82
|
[@@deriving yojson {strict = false}];;
|
83
|
|
84
|
(* TODO: call to functions? procedures? *)
|
85
|
type vhdl_expr_t =
|
86
|
| Var of string (* a signal or a variable *)
|
87
|
| Op of { id: string; args: vhdl_expr_t list } [@name "Expression"]
|
88
|
| IsNull
|
89
|
| Time of { value: int; phy_unit: string }
|
90
|
| Sig of { name: string; att: vhdl_signal_attributes_t option }
|
91
|
| SuffixMod of { expr : vhdl_expr_t; selection : suffix_selection_t }
|
92
|
[@@deriving yojson {strict = false}];;
|
93
|
|
94
|
let arith_funs = ["+";"-";"*";"/";"mod"; "rem";"abs";"**"]
|
95
|
let bool_funs = ["and"; "or"; "nand"; "nor"; "xor"; "not"]
|
96
|
let rel_funs = ["<";">";"<=";">=";"/=";"="]
|
97
|
|
98
|
type vhdl_if_case_t =
|
99
|
{
|
100
|
if_cond: vhdl_expr_t;
|
101
|
if_block: vhdl_sequential_stmt_t list;
|
102
|
}
|
103
|
and vhdl_sequential_stmt_t =
|
104
|
| VarAssign of { lhs: string; rhs: vhdl_expr_t }
|
105
|
| SigSeqAssign of { label: string option; lhs: string; rhs: vhdl_expr_t list} [@name "SIGNAL_ASSIGNMENT_STATEMENT"]
|
106
|
| If of { label: string option [@default Some ""]; if_cases: vhdl_if_case_t list;
|
107
|
default: (vhdl_sequential_stmt_t list) option; } [@name "IF_STATEMENT"]
|
108
|
| Case of { guard: vhdl_expr_t; branches: vhdl_case_item_t list }
|
109
|
| Exit of { label: string option [@default Some ""]; loop_label: string option [@default Some ""]; condition: vhdl_expr_t option [@default Some IsNull]} [@name "EXIT_STATEMENT"]
|
110
|
| Null of { label: string option [@default Some ""]} [@name "NULL_STATEMENT"]
|
111
|
and vhdl_case_item_t =
|
112
|
{
|
113
|
when_cond: vhdl_expr_t;
|
114
|
when_stmt: vhdl_sequential_stmt_t;
|
115
|
}
|
116
|
[@@deriving yojson {strict = false}];;
|
117
|
|
118
|
type signal_condition_t =
|
119
|
{
|
120
|
expr: vhdl_expr_t; (* when expression *)
|
121
|
else_case: vhdl_expr_t option; (* optional else case expression.
|
122
|
If None, could be a latch *)
|
123
|
}
|
124
|
[@@deriving yojson {strict = false}];;
|
125
|
|
126
|
type signal_selection_t =
|
127
|
{
|
128
|
sel_lhs: string [@default ""];
|
129
|
expr : vhdl_expr_t;
|
130
|
when_sel: vhdl_expr_t option;
|
131
|
}
|
132
|
[@@deriving yojson {strict = false}];;
|
133
|
|
134
|
type conditional_signal_t =
|
135
|
{
|
136
|
lhs: string [@default ""]; (* assigned signal = target*)
|
137
|
rhs: vhdl_expr_t; (* expression *)
|
138
|
cond: signal_condition_t option; (* conditional signal statement = waveform*)
|
139
|
}
|
140
|
[@@deriving yojson {strict = false}];;
|
141
|
|
142
|
type process_t =
|
143
|
{
|
144
|
id: string option [@default None];
|
145
|
declarations: vhdl_declaration_t list option [@key "PROCESS_DECLARATIVE_PART"] [@default Some []];
|
146
|
active_sigs: string list [@default []];
|
147
|
body: vhdl_sequential_stmt_t list [@key "PROCESS_STATEMENT_PART"] [@default []]
|
148
|
}
|
149
|
[@@deriving yojson {strict = false}];;
|
150
|
|
151
|
type selected_signal_t =
|
152
|
{
|
153
|
sel: vhdl_expr_t;
|
154
|
branches: signal_selection_t list [@default []];
|
155
|
}
|
156
|
[@@deriving yojson {strict = false}];;
|
157
|
|
158
|
type vhdl_concurrent_stmt_t =
|
159
|
| SigAssign of conditional_signal_t [@key "SIGNAL_ASSIGNMENT"]
|
160
|
| Process of process_t [@key "PROCESS_STATEMENT"]
|
161
|
| SelectedSig of selected_signal_t
|
162
|
[@@deriving yojson {strict = false}];;
|
163
|
(*
|
164
|
type vhdl_statement_t =
|
165
|
|
166
|
(* | DeclarationStmt of declaration_stmt_t *)
|
167
|
| ConcurrentStmt of vhdl_concurrent_stmt_t
|
168
|
| SequentialStmt of vhdl_sequential_stmt_t
|
169
|
*)
|
170
|
|
171
|
(************************************************************************************)
|
172
|
(* Entities *)
|
173
|
(************************************************************************************)
|
174
|
|
175
|
(* TODO? Seems to appear optionally in entities *)
|
176
|
type vhdl_generic_t = unit
|
177
|
[@@deriving yojson {strict = false}];;
|
178
|
|
179
|
type vhdl_port_kind_t =
|
180
|
InPort [@name "in"]
|
181
|
| OutPort [@name "out"]
|
182
|
| InoutPort [@name "inout"]
|
183
|
| BufferPort [@name "buffer"]
|
184
|
[@@deriving yojson];;
|
185
|
|
186
|
type vhdl_port_t =
|
187
|
{
|
188
|
names: string list [@default []];
|
189
|
kind: vhdl_port_kind_t;
|
190
|
typ : string;
|
191
|
(* typ: vhdl_type_t; *)
|
192
|
}
|
193
|
[@@deriving yojson {strict = false}];;
|
194
|
|
195
|
type vhdl_entity_t =
|
196
|
{
|
197
|
name: string [@default ""];
|
198
|
generics: vhdl_generic_t list option [@key "GENERIC_CLAUSE"] [@default Some []];
|
199
|
ports: vhdl_port_t list [@key "PORT_CLAUSE"] [@default []];
|
200
|
}
|
201
|
[@@deriving yojson {strict = false}];;
|
202
|
|
203
|
(************************************************************************************)
|
204
|
(* Packages / Library loading *)
|
205
|
(************************************************************************************)
|
206
|
|
207
|
(* Optional. Describes shared definitions *)
|
208
|
type vhdl_package_t =
|
209
|
{
|
210
|
name: string [@default ""];
|
211
|
shared_defs: vhdl_definition_t list [@default []];
|
212
|
}
|
213
|
[@@deriving yojson {strict = false}];;
|
214
|
|
215
|
type vhdl_load_t =
|
216
|
Library of string list [@name "LIBRARY_CLAUSE"] [@default ""]
|
217
|
| Use of string list [@name "USE_CLAUSE"] [@default []]
|
218
|
[@@deriving yojson];;
|
219
|
|
220
|
(************************************************************************************)
|
221
|
(* Architecture / VHDL Design *)
|
222
|
(************************************************************************************)
|
223
|
|
224
|
type vhdl_architecture_t =
|
225
|
{
|
226
|
name: string [@default ""];
|
227
|
entity: string [@default ""];
|
228
|
declarations: vhdl_declaration_t list option [@key "ARCHITECTURE_DECLARATIVE_PART"] [@default Some []];
|
229
|
body: vhdl_concurrent_stmt_t list option [@key "ARCHITECTURE_STATEMENT_PART"] [@default Some []];
|
230
|
}
|
231
|
[@@deriving yojson {strict = false}];;
|
232
|
|
233
|
(* TODO. Configuration is optional *)
|
234
|
type vhdl_configuration_t = unit
|
235
|
[@@deriving yojson {strict = false}];;
|
236
|
|
237
|
type vhdl_design_t =
|
238
|
{
|
239
|
packages: vhdl_package_t list [@key "PACKAGE_DECLARATION"] [@default []];
|
240
|
libraries: vhdl_load_t list option [@key "CONTEXT_CLAUSE"] [@default Some []];
|
241
|
entities: vhdl_entity_t list [@key "ENTITY_DECLARATION"] [@default []];
|
242
|
architectures: vhdl_architecture_t list [@key "ARCHITECTURE_BODY"] [@default []];
|
243
|
configuration: vhdl_configuration_t option [@key "CONFIGURATION_DECLARATION"] [@default Some ()];
|
244
|
}
|
245
|
[@@deriving yojson {strict = false}];;
|
246
|
|
247
|
type vhdl_design_file_t =
|
248
|
{
|
249
|
design_unit: vhdl_design_t list [@key "DESIGN_UNIT"] [@default []];
|
250
|
}
|
251
|
[@@deriving yojson {strict = false}];;
|
252
|
|
253
|
type vhdl_file_t =
|
254
|
{
|
255
|
design_file: vhdl_design_file_t [@key "DESIGN_FILE"];
|
256
|
}
|
257
|
[@@deriving yojson];;
|