1
|
let base_types = ["integer"; "character"; "bit"; "real"; "natural"; "positive"; "std_logic"; "std_logic_vector" ]
|
2
|
|
3
|
(************************************************************************************)
|
4
|
(* Constants *)
|
5
|
(************************************************************************************)
|
6
|
|
7
|
(* Std_logic values :
|
8
|
'U': uninitialized. This signal hasn't been set yet.
|
9
|
'X': unknown. Impossible to determine this value/result.
|
10
|
'0': logic 0
|
11
|
'1': logic 1
|
12
|
'Z': High Impedance
|
13
|
'W': Weak signal, can't tell if it should be 0 or 1.
|
14
|
'L': Weak signal that should probably go to 0
|
15
|
'H': Weak signal that should probably go to 1
|
16
|
'-': Don't care. *)
|
17
|
let std_logic_cst = ["U"; "X"; "0"; "1"; "Z"; "W"; "L"; "H"; "-" ]
|
18
|
let literal_base = ["B"; "O"; "X"; "UB"; "UO"; "UX"; "SB"; "SO"; "SX"; "D"] (* Prefix of CstLiteral *)
|
19
|
|
20
|
(* TODO: do we need more constructors ? *)
|
21
|
type vhdl_cst_val_t =
|
22
|
CstInt of int
|
23
|
| CstStdLogic of string
|
24
|
| CstLiteral of string [@name "CST_LITERAL"]
|
25
|
[@@deriving show { with_path = false }, yojson {strict = false}];;
|
26
|
|
27
|
(*
|
28
|
let pp_cst_val fmt c =
|
29
|
match c with
|
30
|
| CstInt i -> Format.fprintf fmt "%i" i
|
31
|
| CstStdLogic s -> if List.mem s std_logic_cst then Format.fprintf fmt "%s" s else assert false
|
32
|
| CstLiteral s -> Format.fprintf fmt "%s" s
|
33
|
*)
|
34
|
|
35
|
type vhdl_type_t =
|
36
|
| Base of string
|
37
|
| Range of string option * int * int
|
38
|
| Bit_vector of int * int
|
39
|
| Array of { indexes: vhdl_name_t list [@default []]; const: vhdl_constraint_t option [@default None]; definition: vhdl_subtype_indication_t } [@name "ARRAY_TYPE_DEFINITION"]
|
40
|
| Record of vhdl_element_declaration_t list [@name "RECORD_TYPE_DEFINITION"]
|
41
|
| Enumerated of vhdl_name_t list [@name "ENUMERATION_TYPE_DEFINITION"]
|
42
|
| Void
|
43
|
and vhdl_element_declaration_t =
|
44
|
{
|
45
|
names : vhdl_name_t list;
|
46
|
definition: vhdl_subtype_indication_t;
|
47
|
}
|
48
|
and vhdl_subtype_indication_t =
|
49
|
{
|
50
|
name : vhdl_name_t [@default NoName];
|
51
|
functionName : vhdl_name_t [@default NoName];
|
52
|
const: vhdl_constraint_t [@default NoConstraint];
|
53
|
}
|
54
|
and vhdl_discrete_range_t =
|
55
|
| SubDiscreteRange of vhdl_subtype_indication_t [@name "SUB_DISCRETE_RANGE"]
|
56
|
| NamedRange of vhdl_name_t [@name "NAMED_RANGE"]
|
57
|
| DirectedRange of { direction: string; from: vhdl_expr_t; _to: vhdl_expr_t } [@name "RANGE_WITH_DIRECTION"]
|
58
|
and vhdl_constraint_t =
|
59
|
| RefConstraint of { ref_name: vhdl_name_t; }
|
60
|
| RangeConstraint of { range: vhdl_discrete_range_t } [@name "RANGE_CONSTRAINT"]
|
61
|
| IndexConstraint of { ranges: vhdl_discrete_range_t list; } [@name "INDEX_CONSTRAINT"]
|
62
|
| ArrayConstraint of { ranges: vhdl_discrete_range_t list; sub: vhdl_constraint_t } [@name "ARRAY_CONSTRAINT"]
|
63
|
| RecordConstraint
|
64
|
| NoConstraint
|
65
|
and vhdl_definition_t =
|
66
|
| Type of {name : vhdl_name_t ; definition: vhdl_type_t} [@name "TYPE_DECLARATION"]
|
67
|
| Subtype of {name : vhdl_name_t ; typ : vhdl_subtype_indication_t} [@name "SUBTYPE_DECLARATION"]
|
68
|
and vhdl_expr_t =
|
69
|
| Call of vhdl_name_t [@name "CALL"]
|
70
|
| Cst of { value: vhdl_cst_val_t; unit_name: vhdl_name_t option [@default None]} [@name "CONSTANT_VALUE"]
|
71
|
| Op of { id: string [@default ""]; args: vhdl_expr_t list [@default []]} [@name "EXPRESSION"]
|
72
|
| IsNull [@name "IsNull"]
|
73
|
| Time of { value: int; phy_unit: string [@default ""]}
|
74
|
| Sig of { name: vhdl_name_t; att: vhdl_signal_attributes_t option [@default None]}
|
75
|
| SuffixMod of { expr : vhdl_expr_t; selection : vhdl_suffix_selection_t }
|
76
|
| Aggregate of { elems : vhdl_element_assoc_t list [@default []]} [@name "AGGREGATE"]
|
77
|
| QualifiedExpression of { type_mark : vhdl_name_t; aggregate : vhdl_element_assoc_t list [@default []]; expression : vhdl_expr_t option [@default None]} [@name "QUALIFIED_EXPRESSION"]
|
78
|
| Others [@name "OTHERS"]
|
79
|
and vhdl_name_t = (* Add something like TOKEN_NAME for specific keywords (open, all, ...) ? *)
|
80
|
| Simple of string [@name "SIMPLE_NAME"]
|
81
|
| Identifier of string [@name "IDENTIFIER"]
|
82
|
| Selected of vhdl_name_t list [@name "SELECTED_NAME"]
|
83
|
| Index of { id: vhdl_name_t; exprs: vhdl_expr_t list } [@name "INDEXED_NAME"]
|
84
|
| Slice of { id: vhdl_name_t; range: vhdl_discrete_range_t } [@name "SLICE_NAME"]
|
85
|
| Attribute of { id: vhdl_name_t; designator: vhdl_name_t; expr: vhdl_expr_t [@default IsNull]} [@name "ATTRIBUTE_NAME"]
|
86
|
| Function of { id: vhdl_name_t; assoc_list: vhdl_assoc_element_t list } [@name "FUNCTION_CALL"]
|
87
|
| NoName
|
88
|
and vhdl_assoc_element_t =
|
89
|
{
|
90
|
formal_name: vhdl_name_t option [@default None];
|
91
|
formal_arg: vhdl_name_t option [@default None];
|
92
|
actual_name: vhdl_name_t option [@default None];
|
93
|
actual_designator: vhdl_name_t option [@default None];
|
94
|
actual_expr: vhdl_expr_t option [@default None];
|
95
|
}
|
96
|
and vhdl_element_assoc_t =
|
97
|
{
|
98
|
choices: vhdl_expr_t list [@default []];
|
99
|
expr: vhdl_expr_t;
|
100
|
}
|
101
|
and vhdl_array_attributes_t =
|
102
|
| AAttInt of { id: string; arg: int; }
|
103
|
| AAttAscending
|
104
|
and vhdl_signal_attributes_t = SigAtt of string
|
105
|
and vhdl_string_attributes_t = StringAtt of string
|
106
|
and vhdl_suffix_selection_t = Idx of int | SuffixRange of int * int
|
107
|
[@@deriving show { with_path = false }, yojson {strict = false}];;
|
108
|
|
109
|
(*
|
110
|
let rec pp_vhdl_type fmt t =
|
111
|
match t with
|
112
|
| Base s -> Format.fprintf fmt "%s" s
|
113
|
| Range(base, n, m) -> Format.fprintf fmt "%trange %i to %i" (fun fmt -> match base with Some s -> Format.fprintf fmt "%s " s | None -> ()) n m
|
114
|
| Bit_vector (n,m) -> Format.fprintf fmt "bit_vector(%i downto %i)" n m
|
115
|
| Array (n, m, base) -> Format.fprintf fmt "array (%i to %i) of %a" n m pp_vhdl_type base
|
116
|
| Enumerated sl -> Format.fprintf fmt "(%a)" (Utils.fprintf_list ~sep:", " Format.pp_print_string) sl
|
117
|
| Void -> Format.fprintf fmt ""
|
118
|
*)
|
119
|
|
120
|
(************************************************************************************)
|
121
|
(* Attributes for types, arrays, signals and strings *)
|
122
|
(************************************************************************************)
|
123
|
|
124
|
type 'basetype vhdl_type_attributes_t =
|
125
|
| TAttNoArg of { id: string }
|
126
|
| TAttIntArg of { id: string; arg: int }
|
127
|
| TAttValArg of { id: string; arg: 'basetype }
|
128
|
| TAttStringArg of { id: string; arg: string }
|
129
|
[@@deriving show { with_path = false }, yojson {strict = false}];;
|
130
|
|
131
|
let typ_att_noarg = ["base"; "left"; "right"; "high"; "low"]
|
132
|
let typ_att_intarg = ["pos"; "val"; "succ"; "pred"; "leftof"; "rightof"]
|
133
|
let typ_att_valarg = ["image"]
|
134
|
let typ_att_stringarg = ["value"]
|
135
|
|
136
|
let array_att_intarg = ["left"; "right"; "high"; "low"; "range"; "reverse_range"; "length"]
|
137
|
|
138
|
type vhdl_parameter_t =
|
139
|
{
|
140
|
names: vhdl_name_t list;
|
141
|
mode: string list [@default []];
|
142
|
typ: vhdl_subtype_indication_t;
|
143
|
init_val: vhdl_cst_val_t option [@default None];
|
144
|
}
|
145
|
[@@deriving show { with_path = false }, yojson {strict = false}];;
|
146
|
|
147
|
type vhdl_subprogram_spec_t =
|
148
|
{
|
149
|
name: string [@default ""];
|
150
|
subprogram_type: string [@default ""];
|
151
|
typeMark: vhdl_name_t [@default NoName];
|
152
|
parameters: vhdl_parameter_t list [@default []];
|
153
|
isPure: bool [@default false];
|
154
|
}
|
155
|
[@@deriving show { with_path = false }, yojson {strict = false}];;
|
156
|
|
157
|
(************************************************************************************)
|
158
|
(* Expressions / Statements *)
|
159
|
(************************************************************************************)
|
160
|
|
161
|
let arith_funs = ["+";"-";"*";"/";"mod"; "rem";"abs";"**";"&"]
|
162
|
let bool_funs = ["and"; "or"; "nand"; "nor"; "xor"; "not"]
|
163
|
let rel_funs = ["<";">";"<=";">=";"/=";"=";"?=";"?/=";"?<";"?<=";"?>";"?>=";"??"]
|
164
|
let shift_funs = ["sll";"srl";"sla";"sra";"rol";"ror"]
|
165
|
|
166
|
type vhdl_waveform_element_t =
|
167
|
{
|
168
|
value: vhdl_expr_t option [@default None];
|
169
|
delay: vhdl_expr_t option [@default None];
|
170
|
}
|
171
|
[@@deriving show { with_path = false }, yojson {strict = false}];;
|
172
|
|
173
|
type vhdl_sequential_stmt_t =
|
174
|
| VarAssign of { label: vhdl_name_t [@default NoName]; lhs: vhdl_name_t; rhs: vhdl_expr_t } [@name "VARIABLE_ASSIGNMENT_STATEMENT"]
|
175
|
| SigSeqAssign of { label: vhdl_name_t [@default NoName]; lhs: vhdl_name_t; rhs: vhdl_waveform_element_t list} [@name "SIGNAL_ASSIGNMENT_STATEMENT"]
|
176
|
| If of { label: vhdl_name_t [@default NoName]; if_cases: vhdl_if_case_t list;
|
177
|
default: vhdl_sequential_stmt_t list [@default []]; } [@name "IF_STATEMENT"]
|
178
|
| Case of { label: vhdl_name_t [@default NoName]; guard: vhdl_expr_t; branches: vhdl_case_item_t list } [@name "CASE_STATEMENT_TREE"]
|
179
|
| Exit of { label: vhdl_name_t [@default NoName]; loop_label: string option [@default Some ""]; condition: vhdl_expr_t option [@default Some IsNull]} [@name "EXIT_STATEMENT"]
|
180
|
| Assert of { label: vhdl_name_t [@default NoName]; cond: vhdl_expr_t; report: vhdl_expr_t [@default IsNull]; severity: vhdl_expr_t [@default IsNull]} [@name "ASSERTION_STATEMENT"]
|
181
|
| ProcedureCall of { label: vhdl_name_t [@default NoName]; name: vhdl_name_t; assocs: vhdl_assoc_element_t list [@default []] } [@name "PROCEDURE_CALL_STATEMENT"]
|
182
|
| Wait [@name "WAIT_STATEMENT"]
|
183
|
| Null of { label: vhdl_name_t [@default NoName]} [@name "NULL_STATEMENT"]
|
184
|
| Return of { label: vhdl_name_t option [@default None]; expr: vhdl_expr_t option [@default None]} [@name "RETURN_STATEMENT"]
|
185
|
and vhdl_if_case_t =
|
186
|
{
|
187
|
if_cond: vhdl_expr_t;
|
188
|
if_block: vhdl_sequential_stmt_t list;
|
189
|
}
|
190
|
and vhdl_case_item_t =
|
191
|
{
|
192
|
when_cond: vhdl_expr_t list;
|
193
|
when_stmt: vhdl_sequential_stmt_t list;
|
194
|
}
|
195
|
[@@deriving show { with_path = false }, yojson {strict = false}];;
|
196
|
|
197
|
type vhdl_port_mode_t =
|
198
|
InPort [@name "in"]
|
199
|
| OutPort [@name "out"]
|
200
|
| InoutPort [@name "inout"]
|
201
|
| BufferPort [@name "buffer"]
|
202
|
[@@deriving show { with_path = false }, yojson];;
|
203
|
|
204
|
type vhdl_port_t =
|
205
|
{
|
206
|
names: vhdl_name_t list [@default []];
|
207
|
mode: vhdl_port_mode_t [@default InPort];
|
208
|
typ: vhdl_subtype_indication_t;
|
209
|
expr: vhdl_expr_t [@default IsNull];
|
210
|
}
|
211
|
[@@deriving show { with_path = false }, yojson {strict = false}];;
|
212
|
|
213
|
type vhdl_declaration_t =
|
214
|
| VarDecl of {
|
215
|
names : vhdl_name_t list;
|
216
|
typ : vhdl_subtype_indication_t;
|
217
|
init_val : vhdl_expr_t [@default IsNull]
|
218
|
} [@name "VARIABLE_DECLARATION"]
|
219
|
| CstDecl of {
|
220
|
names : vhdl_name_t list;
|
221
|
typ : vhdl_subtype_indication_t;
|
222
|
init_val : vhdl_expr_t
|
223
|
} [@name "CONSTANT_DECLARATION"]
|
224
|
| SigDecl of {
|
225
|
names : vhdl_name_t list;
|
226
|
typ : vhdl_subtype_indication_t;
|
227
|
init_val : vhdl_expr_t [@default IsNull]
|
228
|
} [@name "SIGNAL_DECLARATION"]
|
229
|
| ComponentDecl of {
|
230
|
name: vhdl_name_t [@default NoName];
|
231
|
generics: vhdl_port_t list [@default []];
|
232
|
ports: vhdl_port_t list [@default []];
|
233
|
} [@name "COMPONENT_DECLARATION"]
|
234
|
| Subprogram of {
|
235
|
spec: vhdl_subprogram_spec_t;
|
236
|
decl_part: vhdl_declaration_t list [@default []];
|
237
|
stmts: vhdl_sequential_stmt_t list [@default []]
|
238
|
} [@name "SUBPROGRAM_BODY"]
|
239
|
[@@deriving show { with_path = false }, yojson {strict = false}];;
|
240
|
|
241
|
type vhdl_load_t =
|
242
|
Library of vhdl_name_t list [@name "LIBRARY_CLAUSE"] [@default []]
|
243
|
| Use of vhdl_name_t list [@name "USE_CLAUSE"] [@default []]
|
244
|
[@@deriving show { with_path = false }, yojson];;
|
245
|
|
246
|
type vhdl_declarative_item_t =
|
247
|
{
|
248
|
use_clause: vhdl_load_t option [@default None];
|
249
|
declaration: vhdl_declaration_t option [@default None];
|
250
|
definition: vhdl_definition_t option [@default None];
|
251
|
}
|
252
|
[@@deriving show { with_path = false }, yojson {strict = false}];;
|
253
|
|
254
|
type vhdl_signal_condition_t =
|
255
|
{
|
256
|
expr: vhdl_waveform_element_t list [@default []]; (* when expression *)
|
257
|
cond: vhdl_expr_t option [@default None]; (* optional else case expression.
|
258
|
If None, could be a latch *)
|
259
|
}
|
260
|
[@@deriving show { with_path = false }, yojson {strict = false}];;
|
261
|
|
262
|
type vhdl_signal_selection_t =
|
263
|
{
|
264
|
expr : vhdl_waveform_element_t list [@default []];
|
265
|
when_sel: vhdl_expr_t list [@default []];
|
266
|
}
|
267
|
[@@deriving show { with_path = false }, yojson {strict = false}];;
|
268
|
|
269
|
type vhdl_conditional_signal_t =
|
270
|
{
|
271
|
postponed: bool [@default false];
|
272
|
label: vhdl_name_t [@default NoName];
|
273
|
lhs: vhdl_name_t; (* assigned signal = target*)
|
274
|
rhs: vhdl_signal_condition_t list; (* expression *)
|
275
|
delay: vhdl_expr_t [@default IsNull];
|
276
|
}
|
277
|
[@@deriving show { with_path = false }, yojson {strict = false}];;
|
278
|
|
279
|
type vhdl_process_t =
|
280
|
{
|
281
|
id: vhdl_name_t [@default NoName];
|
282
|
declarations: vhdl_declarative_item_t list [@key "PROCESS_DECLARATIVE_PART"] [@default []];
|
283
|
active_sigs: vhdl_name_t list [@default []];
|
284
|
body: vhdl_sequential_stmt_t list [@key "PROCESS_STATEMENT_PART"] [@default []]
|
285
|
}
|
286
|
[@@deriving show { with_path = false }, yojson {strict = false}];;
|
287
|
|
288
|
type vhdl_selected_signal_t =
|
289
|
{
|
290
|
postponed: bool [@default false];
|
291
|
label: vhdl_name_t [@default NoName];
|
292
|
lhs: vhdl_name_t; (* assigned signal = target *)
|
293
|
sel: vhdl_expr_t;
|
294
|
branches: vhdl_signal_selection_t list [@default []];
|
295
|
delay: vhdl_expr_t option [@default None];
|
296
|
}
|
297
|
[@@deriving show { with_path = false }, yojson {strict = false}];;
|
298
|
|
299
|
type vhdl_component_instantiation_t =
|
300
|
{
|
301
|
name: vhdl_name_t;
|
302
|
inst_unit: vhdl_name_t;
|
303
|
inst_unit_type : string [@default ""];
|
304
|
archi_name: vhdl_name_t option [@default None];
|
305
|
generic_map: vhdl_assoc_element_t list [@default []];
|
306
|
port_map: vhdl_assoc_element_t list [@default []];
|
307
|
}
|
308
|
[@@deriving show { with_path = false }, yojson {strict = false}];;
|
309
|
|
310
|
type vhdl_concurrent_stmt_t =
|
311
|
| SigAssign of vhdl_conditional_signal_t [@name "CONDITIONAL_SIGNAL_ASSIGNMENT"]
|
312
|
| Process of vhdl_process_t [@name "PROCESS_STATEMENT"]
|
313
|
| SelectedSig of vhdl_selected_signal_t [@name "SELECTED_SIGNAL_ASSIGNMENT"]
|
314
|
| ComponentInst of vhdl_component_instantiation_t [@name "COMPONENT_INSTANTIATION_STATEMENT"]
|
315
|
[@@deriving show { with_path = false }, yojson {strict = false}];;
|
316
|
(*
|
317
|
type vhdl_statement_t =
|
318
|
|
319
|
(* | DeclarationStmt of declaration_stmt_t *)
|
320
|
| ConcurrentStmt of vhdl_concurrent_stmt_t
|
321
|
| SequentialStmt of vhdl_sequential_stmt_t
|
322
|
*)
|
323
|
|
324
|
(************************************************************************************)
|
325
|
(* Entities *)
|
326
|
(************************************************************************************)
|
327
|
|
328
|
type vhdl_entity_t =
|
329
|
{
|
330
|
name: vhdl_name_t [@default NoName];
|
331
|
generics: vhdl_port_t list [@default []];
|
332
|
ports: vhdl_port_t list [@default []];
|
333
|
declaration: vhdl_declarative_item_t list [@key "ENTITY_DECLARATIVE_PART"] [@default []];
|
334
|
stmts: vhdl_concurrent_stmt_t list [@key "ENTITY_STATEMENT_PART"] [@default []];
|
335
|
}
|
336
|
[@@deriving show { with_path = false }, yojson {strict = false}];;
|
337
|
|
338
|
(************************************************************************************)
|
339
|
(* Packages / Library loading *)
|
340
|
(************************************************************************************)
|
341
|
|
342
|
(* Optional. Describes shared definitions *)
|
343
|
type vhdl_package_t =
|
344
|
{
|
345
|
name: vhdl_name_t [@default NoName];
|
346
|
shared_defs: vhdl_definition_t list [@default []];
|
347
|
shared_decls: vhdl_declaration_t list [@default []];
|
348
|
shared_uses: vhdl_load_t list [@default []];
|
349
|
}
|
350
|
[@@deriving show { with_path = false }, yojson {strict = false}];;
|
351
|
|
352
|
(************************************************************************************)
|
353
|
(* Architecture / VHDL Design *)
|
354
|
(************************************************************************************)
|
355
|
|
356
|
type vhdl_architecture_t =
|
357
|
{
|
358
|
name: vhdl_name_t [@default NoName];
|
359
|
entity: vhdl_name_t [@default NoName];
|
360
|
declarations: vhdl_declarative_item_t list [@key "ARCHITECTURE_DECLARATIVE_PART"] [@default []];
|
361
|
body: vhdl_concurrent_stmt_t list [@key "ARCHITECTURE_STATEMENT_PART"] [@default []];
|
362
|
}
|
363
|
[@@deriving show { with_path = false }, yojson {strict = false}];;
|
364
|
|
365
|
(* TODO. Configuration is optional *)
|
366
|
type vhdl_configuration_t = unit
|
367
|
[@@deriving show { with_path = false }, yojson {strict = false}];;
|
368
|
|
369
|
type vhdl_library_unit_t = (* TODO: PACKAGE_BODY *)
|
370
|
Package of vhdl_package_t [@name "PACKAGE_DECLARATION"]
|
371
|
| Entities of vhdl_entity_t [@name "ENTITY_DECLARATION"]
|
372
|
| Architecture of vhdl_architecture_t [@name "ARCHITECTURE_BODY"]
|
373
|
| Configuration of vhdl_configuration_t [@name "CONFIGURATION_DECLARATION"]
|
374
|
[@@deriving show { with_path = false }, yojson {strict = false}];;
|
375
|
|
376
|
type vhdl_design_unit_t =
|
377
|
{
|
378
|
contexts: vhdl_load_t list [@default []];
|
379
|
library: vhdl_library_unit_t;
|
380
|
}
|
381
|
[@@deriving show { with_path = false }, yojson {strict = false}];;
|
382
|
|
383
|
type vhdl_design_file_t =
|
384
|
{
|
385
|
design_units: vhdl_design_unit_t list [@default []];
|
386
|
}
|
387
|
[@@deriving show { with_path = false }, yojson {strict = false}];;
|
388
|
|
389
|
type vhdl_file_t =
|
390
|
{
|
391
|
design_file: vhdl_design_file_t [@default {design_units=[]}] [@key "DESIGN_FILE"];
|
392
|
}
|
393
|
[@@deriving show { with_path = false }, yojson];;
|