Project

General

Profile

Download (17.8 KB) Statistics
| Branch: | Tag: | Revision:
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
[@@deriving traverse_fold];;
27

    
28
(*
29
let pp_cst_val fmt c =
30
  match c with
31
  | CstInt i -> Format.fprintf fmt "%i" i
32
  | CstStdLogic s -> if List.mem s std_logic_cst then Format.fprintf fmt "%s" s else assert false
33
  | CstLiteral s -> Format.fprintf fmt "%s" s
34
*)
35

    
36
type vhdl_type_t =
37
  | Base of string
38
  | Range of string option * int * int
39
  | Bit_vector of int * int
40
  | Array of { indexes: vhdl_name_t list [@default []]; const: vhdl_constraint_t option [@default None]; definition: vhdl_subtype_indication_t } [@name "ARRAY_TYPE_DEFINITION"]
41
  | Record of vhdl_element_declaration_t list [@name "RECORD_TYPE_DEFINITION"]
42
  | Enumerated of vhdl_name_t list [@name "ENUMERATION_TYPE_DEFINITION"]
43
  | Void
44
and vhdl_element_declaration_t =
45
  { 
46
    names : vhdl_name_t list; 
47
    definition: vhdl_subtype_indication_t;
48
  }
49
and vhdl_subtype_indication_t =
50
  {
51
    name : vhdl_name_t [@default NoName];
52
    functionName : vhdl_name_t [@default NoName];
53
    const: vhdl_constraint_t [@default NoConstraint];
54
  }
55
and vhdl_discrete_range_t =
56
  | SubDiscreteRange of vhdl_subtype_indication_t [@name "SUB_DISCRETE_RANGE"]
57
  | NamedRange of vhdl_name_t [@name "NAMED_RANGE"]
58
  | DirectedRange of { direction: string; from: vhdl_expr_t; _to: vhdl_expr_t } [@name "RANGE_WITH_DIRECTION"]
59
and vhdl_constraint_t =
60
  | RefConstraint of { ref_name: vhdl_name_t; }
61
  | RangeConstraint of { range: vhdl_discrete_range_t } [@name "RANGE_CONSTRAINT"]
62
  | IndexConstraint of { ranges: vhdl_discrete_range_t list; } [@name "INDEX_CONSTRAINT"]
63
  | ArrayConstraint of { ranges: vhdl_discrete_range_t list; sub: vhdl_constraint_t } [@name "ARRAY_CONSTRAINT"]
64
  | RecordConstraint
65
  | NoConstraint
66
and vhdl_definition_t =
67
  | Type of {name : vhdl_name_t ; definition: vhdl_type_t} [@name "TYPE_DECLARATION"]
68
  | Subtype of {name : vhdl_name_t ; typ : vhdl_subtype_indication_t} [@name "SUBTYPE_DECLARATION"]
69
and vhdl_expr_t =
70
  | Call of vhdl_name_t [@name "CALL"]
71
  | Cst of { value: vhdl_cst_val_t; unit_name: vhdl_name_t option [@default None]} [@name "CONSTANT_VALUE"]
72
  | Op of { id: string [@default ""]; args: vhdl_expr_t list [@default []]} [@name "EXPRESSION"]
73
  | IsNull [@name "IsNull"]
74
  | Time of { value: int; phy_unit: string [@default ""]}
75
  | Sig of { name: vhdl_name_t; att: vhdl_signal_attributes_t option [@default None]}
76
  | SuffixMod of { expr : vhdl_expr_t; selection : vhdl_suffix_selection_t }
77
  | Aggregate of { elems : vhdl_element_assoc_t list [@default []]} [@name "AGGREGATE"]
78
  | QualifiedExpression of { type_mark : vhdl_name_t; aggregate : vhdl_element_assoc_t list [@default []]; expression : vhdl_expr_t option [@default None]} [@name "QUALIFIED_EXPRESSION"]
79
  | Others [@name "OTHERS"]
80
and vhdl_name_t = (* Add something like TOKEN_NAME for specific keywords (open, all, ...) ? *)
81
  | Simple of string [@name "SIMPLE_NAME"]
82
  | Identifier of string [@name "IDENTIFIER"]
83
  | Selected of vhdl_name_t list [@name "SELECTED_NAME"]
84
  | Index of { id: vhdl_name_t; exprs: vhdl_expr_t list } [@name "INDEXED_NAME"]
85
  | Slice of { id: vhdl_name_t; range: vhdl_discrete_range_t } [@name "SLICE_NAME"]
86
  | Attribute of { id: vhdl_name_t; designator: vhdl_name_t; expr: vhdl_expr_t [@default IsNull]} [@name "ATTRIBUTE_NAME"]
87
  | Function of { id: vhdl_name_t; assoc_list: vhdl_assoc_element_t list } [@name "FUNCTION_CALL"]
88
  | Open [@name "OPEN"]
89
  | NoName
90
and vhdl_assoc_element_t =
91
  {
92
    formal_name: vhdl_name_t option [@default None];
93
    formal_arg: vhdl_name_t option [@default None];
94
    actual_name: vhdl_name_t option [@default None];
95
    actual_designator: vhdl_name_t option [@default None];
96
    actual_expr: vhdl_expr_t option [@default None];
97
  }
98
and vhdl_element_assoc_t =
99
  {
100
    choices: vhdl_expr_t list [@default []];
101
    expr: vhdl_expr_t;
102
  }
103
and vhdl_array_attributes_t = 
104
  | AAttInt of { id: string; arg: int; } 
105
  | AAttAscending
106
and vhdl_signal_attributes_t = SigAtt of string
107
and vhdl_string_attributes_t = StringAtt of string
108
and vhdl_suffix_selection_t = Idx of int | SuffixRange of int * int
109
(** [@@deriving show { with_path = false }, yojson {strict = false}];; **)
110
[@@deriving traverse_fold];;
111

    
112
(*
113
let rec pp_vhdl_type fmt t =
114
  match t with
115
  | Base s -> Format.fprintf fmt "%s" s 
116
  | 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
117
  | Bit_vector (n,m) -> Format.fprintf fmt "bit_vector(%i downto %i)" n m
118
  | Array (n, m, base) -> Format.fprintf fmt "array (%i to %i) of %a" n m pp_vhdl_type base
119
  | Enumerated sl -> Format.fprintf fmt "(%a)" (Utils.fprintf_list ~sep:", " Format.pp_print_string) sl
120
  | Void -> Format.fprintf fmt ""
121
*)
122

    
123
(************************************************************************************)		   
124
(*            Attributes for types, arrays, signals and strings                     *)
125
(************************************************************************************)		   
126

    
127
type 'basetype vhdl_type_attributes_t =
128
  | TAttNoArg of { id: string }
129
  | TAttIntArg of { id: string; arg: int }
130
  | TAttValArg of { id: string; arg: 'basetype }
131
  | TAttStringArg of { id: string; arg: string }
132
(** [@@deriving show { with_path = false }, yojson {strict = false}];; **)
133
[@@deriving traverse_fold];;
134

    
135
let typ_att_noarg = ["base"; "left"; "right"; "high"; "low"]
136
let typ_att_intarg = ["pos"; "val"; "succ"; "pred"; "leftof"; "rightof"]
137
let typ_att_valarg = ["image"]
138
let typ_att_stringarg = ["value"]
139
  
140
let array_att_intarg = ["left"; "right"; "high"; "low"; "range"; "reverse_range"; "length"]  
141

    
142
type vhdl_parameter_t =
143
  {
144
    names: vhdl_name_t list;
145
    mode: string list [@default []];
146
    typ: vhdl_subtype_indication_t;
147
    init_val: vhdl_cst_val_t option [@default None];
148
  }
149
(** [@@deriving show { with_path = false }, yojson {strict = false}];; **)
150
[@@deriving traverse_fold];;
151

    
152
type vhdl_subprogram_spec_t =
153
  {
154
    name: string [@default ""];
155
    subprogram_type: string [@default ""];
156
    typeMark: vhdl_name_t [@default NoName];
157
    parameters: vhdl_parameter_t list [@default []];
158
    isPure: bool [@default false];
159
  }
160
(** [@@deriving show { with_path = false }, yojson {strict = false}];; **)
161
[@@deriving traverse_fold];;
162

    
163
(************************************************************************************)		   
164
(*                        Expressions  / Statements                                 *)
165
(************************************************************************************)		   
166

    
167
let arith_funs = ["+";"-";"*";"/";"mod"; "rem";"abs";"**";"&"]
168
let bool_funs  = ["and"; "or"; "nand"; "nor"; "xor"; "not"]
169
let rel_funs   = ["<";">";"<=";">=";"/=";"=";"?=";"?/=";"?<";"?<=";"?>";"?>=";"??"]
170
let shift_funs = ["sll";"srl";"sla";"sra";"rol";"ror"]
171

    
172
type vhdl_waveform_element_t =
173
  {
174
    value: vhdl_expr_t option [@default None];
175
    delay: vhdl_expr_t option [@default None];
176
  }
177
(** [@@deriving show { with_path = false }, yojson {strict = false}];; **)
178
[@@deriving traverse_fold];;
179

    
180
type vhdl_sequential_stmt_t = 
181
  | VarAssign of { label: vhdl_name_t [@default NoName]; lhs: vhdl_name_t; rhs: vhdl_expr_t } [@name "VARIABLE_ASSIGNMENT_STATEMENT"]
182
  | SigSeqAssign of { label: vhdl_name_t [@default NoName]; lhs: vhdl_name_t; rhs: vhdl_waveform_element_t list} [@name "SIGNAL_ASSIGNMENT_STATEMENT"]
183
  | If of { label: vhdl_name_t [@default NoName]; if_cases: vhdl_if_case_t list;
184
    default: vhdl_sequential_stmt_t list [@default []]; } [@name "IF_STATEMENT"]
185
  | Case of { label: vhdl_name_t [@default NoName]; guard: vhdl_expr_t; branches: vhdl_case_item_t list } [@name "CASE_STATEMENT_TREE"]
186
  | 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"]
187
  | 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"]
188
  | ProcedureCall of { label: vhdl_name_t [@default NoName]; name: vhdl_name_t; assocs: vhdl_assoc_element_t list [@default []] } [@name "PROCEDURE_CALL_STATEMENT"]
189
  | Wait [@name "WAIT_STATEMENT"]
190
  | Null of { label: vhdl_name_t [@default NoName]} [@name "NULL_STATEMENT"]
191
  | Return of { label: vhdl_name_t option [@default None]; expr: vhdl_expr_t option [@default None]} [@name "RETURN_STATEMENT"]
192
and vhdl_if_case_t = 
193
  {
194
    if_cond: vhdl_expr_t;
195
    if_block: vhdl_sequential_stmt_t list;
196
  }
197
and vhdl_case_item_t = 
198
  {
199
    when_cond: vhdl_expr_t list;
200
    when_stmt: vhdl_sequential_stmt_t list;
201
  }
202
(** [@@deriving show { with_path = false }, yojson {strict = false}];; **)
203
[@@deriving traverse_fold];;
204

    
205
type vhdl_port_mode_t = 
206
    InPort     [@name "in"]
207
  | OutPort    [@name "out"]
208
  | InoutPort  [@name "inout"]
209
  | BufferPort [@name "buffer"]
210
(** [@@deriving show { with_path = false }, yojson];; **)
211
[@@deriving traverse_fold];;
212
	     
213
type vhdl_port_t =
214
  {
215
    names: vhdl_name_t list [@default []];
216
    mode: vhdl_port_mode_t [@default InPort];
217
    typ: vhdl_subtype_indication_t;
218
    expr: vhdl_expr_t [@default IsNull];
219
  }
220
(** [@@deriving show { with_path = false }, yojson {strict = false}];; **)
221
[@@deriving traverse_fold];;
222

    
223
type vhdl_declaration_t =
224
  | VarDecl of {
225
      names : vhdl_name_t list; 
226
      typ : vhdl_subtype_indication_t; 
227
      init_val : vhdl_expr_t [@default IsNull] 
228
    } [@name "VARIABLE_DECLARATION"]
229
  | CstDecl of { 
230
      names : vhdl_name_t list; 
231
      typ : vhdl_subtype_indication_t; 
232
      init_val : vhdl_expr_t
233
    } [@name "CONSTANT_DECLARATION"]
234
  | SigDecl of { 
235
      names : vhdl_name_t list; 
236
      typ : vhdl_subtype_indication_t; 
237
      init_val : vhdl_expr_t [@default IsNull]
238
    } [@name "SIGNAL_DECLARATION"]
239
  | ComponentDecl of {
240
      name: vhdl_name_t [@default NoName];
241
      generics: vhdl_port_t list [@default []];
242
      ports: vhdl_port_t list [@default []];
243
    } [@name "COMPONENT_DECLARATION"]
244
  | Subprogram of {
245
      spec: vhdl_subprogram_spec_t; 
246
      decl_part: vhdl_declaration_t list [@default []]; 
247
      stmts: vhdl_sequential_stmt_t list [@default []]
248
    } [@name "SUBPROGRAM_BODY"]
249
(** [@@deriving show { with_path = false }, yojson {strict = false}];; **)
250
[@@deriving traverse_fold];;
251

    
252
type vhdl_load_t = 
253
    Library of vhdl_name_t list [@name "LIBRARY_CLAUSE"] [@default []]
254
  | Use of vhdl_name_t list [@name "USE_CLAUSE"] [@default []]
255
(** [@@deriving show { with_path = false }, yojson];; **)
256
[@@deriving traverse_fold];;
257

    
258
type vhdl_declarative_item_t =
259
  {
260
    use_clause: vhdl_load_t option [@default None];
261
    declaration: vhdl_declaration_t option [@default None];
262
    definition: vhdl_definition_t option [@default None];
263
  }
264
(** [@@deriving show { with_path = false }, yojson {strict = false}];; **)
265
[@@deriving traverse_fold];;
266

    
267
type vhdl_signal_condition_t =
268
  {                            
269
    expr: vhdl_waveform_element_t list [@default []];              (* when expression *)
270
    cond: vhdl_expr_t option [@default None];  (* optional else case expression. 
271
                                             If None, could be a latch  *)
272
  }
273
(** [@@deriving show { with_path = false }, yojson {strict = false}];; **)
274
[@@deriving traverse_fold];;
275

    
276
type vhdl_signal_selection_t =
277
  {
278
    expr : vhdl_waveform_element_t list [@default []];
279
    when_sel: vhdl_expr_t list [@default []];
280
  }
281
(** [@@deriving show { with_path = false }, yojson {strict = false}];; **)
282
[@@deriving traverse_fold];;
283

    
284
type vhdl_conditional_signal_t =
285
  {
286
    postponed: bool [@default false];
287
    label: vhdl_name_t [@default NoName];
288
    lhs: vhdl_name_t;        (* assigned signal = target*)
289
    rhs: vhdl_signal_condition_t list;                   (* expression *)
290
    delay: vhdl_expr_t [@default IsNull];
291
  }
292
(** [@@deriving show { with_path = false }, yojson {strict = false}];; **)
293
[@@deriving traverse_fold];;
294

    
295
type vhdl_process_t =
296
  { 
297
    id: vhdl_name_t [@default NoName];
298
    declarations: vhdl_declarative_item_t list [@key "PROCESS_DECLARATIVE_PART"] [@default []];
299
    active_sigs: vhdl_name_t list [@default []];
300
    body: vhdl_sequential_stmt_t list [@key "PROCESS_STATEMENT_PART"] [@default []]
301
  }
302
(** [@@deriving show { with_path = false }, yojson {strict = false}];; **)
303
[@@deriving traverse_fold];;
304

    
305
type vhdl_selected_signal_t = 
306
  { 
307
    postponed: bool [@default false];
308
    label: vhdl_name_t [@default NoName];
309
    lhs: vhdl_name_t;      (* assigned signal = target *)
310
    sel: vhdl_expr_t;
311
    branches: vhdl_signal_selection_t list [@default []];
312
    delay: vhdl_expr_t option [@default None];
313
  }
314
(** [@@deriving show { with_path = false }, yojson {strict = false}];; **)
315
[@@deriving traverse_fold];;
316

    
317
type vhdl_component_instantiation_t =
318
  {
319
    name: vhdl_name_t;
320
    inst_unit: vhdl_name_t;
321
    inst_unit_type : string [@default ""];
322
    archi_name: vhdl_name_t option [@default None];
323
    generic_map: vhdl_assoc_element_t list [@default []];
324
    port_map: vhdl_assoc_element_t list [@default []];
325
  }
326
(** [@@deriving show { with_path = false }, yojson {strict = false}];; **)
327
[@@deriving traverse_fold];;
328

    
329
type vhdl_concurrent_stmt_t =
330
  | SigAssign of vhdl_conditional_signal_t [@name "CONDITIONAL_SIGNAL_ASSIGNMENT"]
331
  | Process of vhdl_process_t [@name "PROCESS_STATEMENT"]
332
  | SelectedSig of vhdl_selected_signal_t [@name "SELECTED_SIGNAL_ASSIGNMENT"]
333
  | ComponentInst of vhdl_component_instantiation_t [@name "COMPONENT_INSTANTIATION_STATEMENT"]
334
(** [@@deriving show { with_path = false }, yojson {strict = false}];; **)
335
[@@deriving traverse_fold];;
336
  (*
337
type vhdl_statement_t =
338
  
339
  (* | DeclarationStmt of declaration_stmt_t *)
340
  | ConcurrentStmt of vhdl_concurrent_stmt_t
341
  | SequentialStmt of vhdl_sequential_stmt_t
342
   *)
343
		     
344
(************************************************************************************)		   
345
(*                     Entities                                                     *)
346
(************************************************************************************)
347

    
348
type vhdl_entity_t =
349
  {
350
    name: vhdl_name_t [@default NoName];
351
    generics: vhdl_port_t list [@default []];
352
    ports: vhdl_port_t list [@default []];
353
    declaration: vhdl_declarative_item_t list [@key "ENTITY_DECLARATIVE_PART"] [@default []];
354
    stmts: vhdl_concurrent_stmt_t list [@key "ENTITY_STATEMENT_PART"] [@default []]; 
355
  }
356
(** [@@deriving show { with_path = false }, yojson {strict = false}];; **)
357
[@@deriving traverse_fold];;
358

    
359
(************************************************************************************)		   
360
(*                    Packages / Library loading                                    *)
361
(************************************************************************************)		   
362
				
363
(* Optional. Describes shared definitions *)
364
type vhdl_package_t =
365
  {
366
    name: vhdl_name_t [@default NoName];
367
    shared_defs: vhdl_definition_t list [@default []];
368
    shared_decls: vhdl_declaration_t list [@default []];
369
    shared_uses: vhdl_load_t list [@default []];
370
  }
371
(** [@@deriving show { with_path = false }, yojson {strict = false}];; **)
372
[@@deriving traverse_fold];;
373

    
374
(************************************************************************************)		   
375
(*                        Architecture / VHDL Design                                *)
376
(************************************************************************************)		   
377
				       
378
type vhdl_architecture_t =
379
  {
380
    name: vhdl_name_t [@default NoName];
381
    entity: vhdl_name_t [@default NoName];
382
    declarations: vhdl_declarative_item_t list [@key "ARCHITECTURE_DECLARATIVE_PART"] [@default []];
383
    body: vhdl_concurrent_stmt_t list [@key "ARCHITECTURE_STATEMENT_PART"] [@default []]; 
384
  }
385
(** [@@deriving show { with_path = false }, yojson {strict = false}];; **)
386
[@@deriving traverse_fold];;
387
    
388
(* TODO. Configuration is optional *)
389
type vhdl_configuration_t = unit
390
(** [@@deriving show { with_path = false }, yojson {strict = false}];; **)
391
[@@deriving traverse_fold];;
392

    
393
type vhdl_library_unit_t = (* TODO: PACKAGE_BODY *)
394
    Package of vhdl_package_t [@name "PACKAGE_DECLARATION"]
395
  | Entities of vhdl_entity_t [@name "ENTITY_DECLARATION"]
396
  | Architecture of vhdl_architecture_t [@name "ARCHITECTURE_BODY"]
397
  | Configuration of vhdl_configuration_t [@name "CONFIGURATION_DECLARATION"]
398
(** [@@deriving show { with_path = false }, yojson {strict = false}];; **)
399
[@@deriving traverse_fold];;
400

    
401
type vhdl_design_unit_t =
402
  {
403
    contexts: vhdl_load_t list [@default []];
404
    library: vhdl_library_unit_t;
405
  }
406
(** [@@deriving show { with_path = false }, yojson {strict = false}];; **)
407
[@@deriving traverse_fold];;
408

    
409
type vhdl_design_file_t =
410
  {
411
    design_units: vhdl_design_unit_t list [@default []];
412
  }
413
(** [@@deriving show { with_path = false }, yojson {strict = false}];; **)
414
[@@deriving traverse_fold];;
415

    
416
type vhdl_file_t = 
417
  {
418
    design_file: vhdl_design_file_t [@default {design_units=[]}] [@key "DESIGN_FILE"];
419
  }
420
(** [@@deriving show { with_path = false }, yojson];; **)
421
[@@deriving traverse_fold];;
422

    
(5-5/12)