Project

General

Profile

Download (16.5 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

    
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 }
75
  | SuffixMod of { expr : vhdl_expr_t; selection : vhdl_suffix_selection_t }
76
  | Aggregate of { elems : vhdl_element_assoc_t list } [@name "AGGREGATE"]
77
  | Others [@name "OTHERS"]
78
and vhdl_name_t = (* Add something like TOKEN_NAME for specific keywords (open, all, ...) ? *)
79
  | Simple of string [@name "SIMPLE_NAME"]
80
  | Identifier of string [@name "IDENTIFIER"]
81
  | Selected of vhdl_name_t list [@name "SELECTED_NAME"]
82
  | Index of { id: vhdl_name_t; exprs: vhdl_expr_t list } [@name "INDEXED_NAME"]
83
  | Slice of { id: vhdl_name_t; range: vhdl_discrete_range_t } [@name "SLICE_NAME"]
84
  | Attribute of { id: vhdl_name_t; designator: vhdl_name_t; expr: vhdl_expr_t [@default IsNull]} [@name "ATTRIBUTE_NAME"]
85
  | Function of { id: vhdl_name_t; assoc_list: vhdl_assoc_element_t list } [@name "FUNCTION_CALL"]
86
  | NoName
87
and vhdl_assoc_element_t =
88
  {
89
    formal_name: vhdl_name_t option [@default None];
90
    formal_arg: vhdl_name_t option [@default None];
91
    actual_name: vhdl_name_t option [@default None];
92
    actual_designator: vhdl_name_t option [@default None];
93
    actual_expr: vhdl_expr_t option [@default None];
94
  }
95
and vhdl_element_assoc_t =
96
  {
97
    choices: vhdl_expr_t list [@default []];
98
    expr: vhdl_expr_t;
99
  }
100
and vhdl_array_attributes_t = 
101
  | AAttInt of { id: string; arg: int; } 
102
  | AAttAscending
103
and vhdl_signal_attributes_t = SigAtt of string
104
and vhdl_string_attributes_t = StringAtt of string
105
and vhdl_suffix_selection_t = Idx of int | SuffixRange of int * int
106
[@@deriving show { with_path = false }, yojson {strict = false}];;
107

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

    
119
(************************************************************************************)		   
120
(*            Attributes for types, arrays, signals and strings                     *)
121
(************************************************************************************)		   
122

    
123
type 'basetype vhdl_type_attributes_t =
124
  | TAttNoArg of { id: string }
125
  | TAttIntArg of { id: string; arg: int }
126
  | TAttValArg of { id: string; arg: 'basetype }
127
  | TAttStringArg of { id: string; arg: string }
128
[@@deriving show { with_path = false }, yojson {strict = false}];;
129

    
130
let typ_att_noarg = ["base"; "left"; "right"; "high"; "low"]
131
let typ_att_intarg = ["pos"; "val"; "succ"; "pred"; "leftof"; "rightof"]
132
let typ_att_valarg = ["image"]
133
let typ_att_stringarg = ["value"]
134
  
135
let array_att_intarg = ["left"; "right"; "high"; "low"; "range"; "reverse_range"; "length"]  
136

    
137
type vhdl_parameter_t =
138
  {
139
    names: vhdl_name_t list;
140
    mode: string list [@default []];
141
    typ: vhdl_subtype_indication_t;
142
    init_val: vhdl_cst_val_t option [@default None];
143
  }
144
[@@deriving show { with_path = false }, yojson {strict = false}];;
145

    
146
type vhdl_subprogram_spec_t =
147
  {
148
    name: string [@default ""];
149
    subprogram_type: string [@default ""];
150
    typeMark: vhdl_name_t [@default NoName];
151
    parameters: vhdl_parameter_t list [@default []];
152
    isPure: bool [@default false];
153
  }
154
[@@deriving show { with_path = false }, yojson {strict = false}];;
155

    
156
(************************************************************************************)		   
157
(*                        Expressions  / Statements                                 *)
158
(************************************************************************************)		   
159

    
160
let arith_funs = ["+";"-";"*";"/";"mod"; "rem";"abs";"**";"&"]
161
let bool_funs  = ["and"; "or"; "nand"; "nor"; "xor"; "not"]
162
let rel_funs   = ["<";">";"<=";">=";"/=";"=";"?=";"?/=";"?<";"?<=";"?>";"?>=";"??"]
163
let shift_funs = ["sll";"srl";"sla";"sra";"rol";"ror"]
164

    
165
type vhdl_waveform_element_t =
166
  {
167
    value: vhdl_expr_t option [@default None];
168
    delay: vhdl_expr_t option [@default None];
169
  }
170
[@@deriving show { with_path = false }, yojson {strict = false}];;
171

    
172
type vhdl_sequential_stmt_t = 
173
  | VarAssign of { label: vhdl_name_t [@default NoName]; lhs: vhdl_name_t; rhs: vhdl_expr_t } [@name "VARIABLE_ASSIGNMENT_STATEMENT"]
174
  | SigSeqAssign of { label: vhdl_name_t [@default NoName]; lhs: vhdl_name_t; rhs: vhdl_waveform_element_t list} [@name "SIGNAL_ASSIGNMENT_STATEMENT"]
175
  | If of { label: vhdl_name_t [@default NoName]; if_cases: vhdl_if_case_t list;
176
    default: vhdl_sequential_stmt_t list [@default []]; } [@name "IF_STATEMENT"]
177
  | Case of { label: vhdl_name_t [@default NoName]; guard: vhdl_expr_t; branches: vhdl_case_item_t list } [@name "CASE_STATEMENT_TREE"]
178
  | 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"]
179
  | 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"]
180
  | ProcedureCall of { label: vhdl_name_t [@default NoName]; name: vhdl_name_t; assocs: vhdl_assoc_element_t list [@default []] } [@name "PROCEDURE_CALL_STATEMENT"]
181
  | Wait [@name "WAIT_STATEMENT"]
182
  | Null of { label: vhdl_name_t [@default NoName]} [@name "NULL_STATEMENT"]
183
  | Return of { label: vhdl_name_t [@default NoName]} [@name "RETURN_STATEMENT"]
184
and vhdl_if_case_t = 
185
  {
186
    if_cond: vhdl_expr_t;
187
    if_block: vhdl_sequential_stmt_t list;
188
  }
189
and vhdl_case_item_t = 
190
  {
191
    when_cond: vhdl_expr_t list;
192
    when_stmt: vhdl_sequential_stmt_t list;
193
  }
194
[@@deriving show { with_path = false }, yojson {strict = false}];;
195

    
196
type vhdl_port_mode_t = 
197
    InPort     [@name "in"]
198
  | OutPort    [@name "out"]
199
  | InoutPort  [@name "inout"]
200
  | BufferPort [@name "buffer"]
201
[@@deriving show { with_path = false }, yojson];;
202
	     
203
type vhdl_port_t =
204
  {
205
    names: vhdl_name_t list [@default []];
206
    mode: vhdl_port_mode_t [@default InPort];
207
    typ: vhdl_subtype_indication_t;
208
    expr: vhdl_expr_t [@default IsNull];
209
  }
210
[@@deriving show { with_path = false }, yojson {strict = false}];;
211

    
212
type vhdl_declaration_t =
213
  | VarDecl of {
214
      names : vhdl_name_t list; 
215
      typ : vhdl_subtype_indication_t; 
216
      init_val : vhdl_expr_t [@default IsNull] 
217
    } [@name "VARIABLE_DECLARATION"]
218
  | CstDecl of { 
219
      names : vhdl_name_t list; 
220
      typ : vhdl_subtype_indication_t; 
221
      init_val : vhdl_expr_t
222
    } [@name "CONSTANT_DECLARATION"]
223
  | SigDecl of { 
224
      names : vhdl_name_t list; 
225
      typ : vhdl_subtype_indication_t; 
226
      init_val : vhdl_expr_t [@default IsNull]
227
    } [@name "SIGNAL_DECLARATION"]
228
  | ComponentDecl of {
229
      name: vhdl_name_t [@default NoName];
230
      generics: vhdl_port_t list [@default []];
231
      ports: vhdl_port_t list [@default []];
232
    } [@name "COMPONENT_DECLARATION"]
233
  | Subprogram of {
234
      spec: vhdl_subprogram_spec_t; 
235
      decl_part: vhdl_declaration_t list [@default []]; 
236
      stmts: vhdl_sequential_stmt_t list [@default []]
237
    } [@name "SUBPROGRAM_BODY"]
238
[@@deriving show { with_path = false }, yojson {strict = false}];;
239

    
240
type vhdl_load_t = 
241
    Library of vhdl_name_t list [@name "LIBRARY_CLAUSE"] [@default []]
242
  | Use of vhdl_name_t list [@name "USE_CLAUSE"] [@default []]
243
[@@deriving show { with_path = false }, yojson];;
244

    
245
type vhdl_declarative_item_t =
246
  {
247
    use_clause: vhdl_load_t option [@default None];
248
    declaration: vhdl_declaration_t option [@default None];
249
    definition: vhdl_definition_t option [@default None];
250
  }
251
[@@deriving show { with_path = false }, yojson {strict = false}];;
252

    
253
type vhdl_signal_condition_t =
254
  {                            
255
    expr: vhdl_waveform_element_t list [@default []];              (* when expression *)
256
    cond: vhdl_expr_t [@default IsNull];  (* optional else case expression. 
257
                                             If None, could be a latch  *)
258
  }
259
[@@deriving show { with_path = false }, yojson {strict = false}];;
260

    
261
type vhdl_signal_selection_t =
262
  {
263
    expr : vhdl_waveform_element_t list [@default []];
264
    when_sel: vhdl_expr_t list [@default []];
265
  }
266
[@@deriving show { with_path = false }, yojson {strict = false}];;
267

    
268
type vhdl_conditional_signal_t =
269
  {
270
    postponed: bool [@default false];
271
    label: vhdl_name_t [@default NoName];
272
    lhs: vhdl_name_t;        (* assigned signal = target*)
273
    rhs: vhdl_signal_condition_t list;                   (* expression *)
274
    cond: vhdl_expr_t [@default IsNull];
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
    archi_name: vhdl_name_t option [@default None];
304
    generic_map: vhdl_assoc_element_t list [@default []];
305
    port_map: vhdl_assoc_element_t list [@default []];
306
  }
307
[@@deriving show { with_path = false }, yojson {strict = false}];;
308

    
309
type vhdl_concurrent_stmt_t =
310
  | SigAssign of vhdl_conditional_signal_t [@name "CONDITIONAL_SIGNAL_ASSIGNMENT"]
311
  | Process of vhdl_process_t [@name "PROCESS_STATEMENT"]
312
  | SelectedSig of vhdl_selected_signal_t [@name "SELECTED_SIGNAL_ASSIGNMENT"]
313
  | ComponentInst of vhdl_component_instantiation_t [@name "COMPONENT_INSTANTIATION_STATEMENT"]
314
[@@deriving show { with_path = false }, yojson {strict = false}];;
315
  (*
316
type vhdl_statement_t =
317
  
318
  (* | DeclarationStmt of declaration_stmt_t *)
319
  | ConcurrentStmt of vhdl_concurrent_stmt_t
320
  | SequentialStmt of vhdl_sequential_stmt_t
321
   *)
322
		     
323
(************************************************************************************)		   
324
(*                     Entities                                                     *)
325
(************************************************************************************)
326

    
327
type vhdl_entity_t =
328
  {
329
    name: vhdl_name_t [@default NoName];
330
    generics: vhdl_port_t list [@default []];
331
    ports: vhdl_port_t list [@default []];
332
    declaration: vhdl_declarative_item_t list [@key "ENTITY_DECLARATIVE_PART"] [@default []];
333
    stmts: vhdl_concurrent_stmt_t list [@key "ENTITY_STATEMENT_PART"] [@default []]; 
334
  }
335
[@@deriving show { with_path = false }, yojson {strict = false}];;
336

    
337
(************************************************************************************)		   
338
(*                    Packages / Library loading                                    *)
339
(************************************************************************************)		   
340
				
341
(* Optional. Describes shared definitions *)
342
type vhdl_package_t =
343
  {
344
    name: vhdl_name_t [@default NoName];
345
    shared_defs: vhdl_definition_t list [@default []];
346
    shared_decls: vhdl_declaration_t list [@default []];
347
    shared_uses: vhdl_load_t list [@default []];
348
  }
349
[@@deriving show { with_path = false }, yojson {strict = false}];;
350

    
351
(************************************************************************************)		   
352
(*                        Architecture / VHDL Design                                *)
353
(************************************************************************************)		   
354
				       
355
type vhdl_architecture_t =
356
  {
357
    name: vhdl_name_t [@default NoName];
358
    entity: vhdl_name_t [@default NoName];
359
    declarations: vhdl_declarative_item_t list [@key "ARCHITECTURE_DECLARATIVE_PART"] [@default []];
360
    body: vhdl_concurrent_stmt_t list [@key "ARCHITECTURE_STATEMENT_PART"] [@default []]; 
361
  }
362
[@@deriving show { with_path = false }, yojson {strict = false}];;
363
    
364
(* TODO. Configuration is optional *)
365
type vhdl_configuration_t = unit
366
[@@deriving show { with_path = false }, yojson {strict = false}];;
367

    
368
type vhdl_library_unit_t = (* TODO: PACKAGE_BODY *)
369
    Package of vhdl_package_t [@name "PACKAGE_DECLARATION"]
370
  | Entities of vhdl_entity_t [@name "ENTITY_DECLARATION"]
371
  | Architecture of vhdl_architecture_t [@name "ARCHITECTURE_BODY"]
372
  | Configuration of vhdl_configuration_t [@name "CONFIGURATION_DECLARATION"]
373
[@@deriving show { with_path = false }, yojson {strict = false}];;
374

    
375
type vhdl_design_unit_t =
376
  {
377
    contexts: vhdl_load_t list [@default []];
378
    library: vhdl_library_unit_t;
379
  }
380
[@@deriving show { with_path = false }, yojson {strict = false}];;
381

    
382
type vhdl_design_file_t =
383
  {
384
    design_units: vhdl_design_unit_t list [@default []];
385
  }
386
[@@deriving show { with_path = false }, yojson {strict = false}];;
387

    
388
type vhdl_file_t = 
389
  {
390
    design_file: vhdl_design_file_t [@default {design_units=[]}] [@key "DESIGN_FILE"];
391
  }
392
[@@deriving show { with_path = false }, yojson];;
(1-1/6)