Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

lustrec / src / tools / importer / vhdl_deriving_yojson.ml @ eb07b479

History | View | Annotate | Download (12.4 KB)

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
let literal_base = ["B"; "O"; "X"; "UB"; "UO"; "UX"; "SB"; "SO"; "SX"; "D"] (* Prefix of CstLiteral *)
28

    
29
(* TODO: do we need more constructors ? *)
30
type cst_val_t = 
31
    CstInt of int 
32
  | CstStdLogic of string
33
  | CstLiteral of string [@name "CST_LITERAL"]
34
[@@deriving yojson {strict = false}];;
35

    
36
type vhdl_subtype_indication_t =
37
  {
38
    name : string;
39
    definition: vhdl_type_t option [@default Some (Void)];
40
  }
41
[@@deriving yojson {strict = false}];;
42

    
43
(* TODO ? Shall we merge definition / declaration  *)
44
type vhdl_definition_t =
45
  | Type of {name : string ; definition: vhdl_type_t} [@name "TYPE_DECLARATION"]
46
  | Subtype of {name : string ; typ : vhdl_subtype_indication_t} [@name "SUBTYPE_DECLARATION"]
47
[@@deriving yojson {strict = false}];;
48

    
49
type vhdl_parameter_t =
50
  {
51
    names: string list;
52
    mode: string [@default ""];
53
    typ: vhdl_subtype_indication_t;
54
    init_val: cst_val_t option [@default Some (CstInt (0))];
55
  }
56
[@@deriving yojson {strict = false}];;
57

    
58
type vhdl_subprogram_spec_t =
59
  {
60
    name: string [@default ""];
61
    typeMark: string [@default ""];
62
    parameters: vhdl_parameter_t list;
63
    isPure: bool [@default false];
64
  }
65
[@@deriving yojson {strict = false}];;
66

    
67
(************************************************************************************)		   
68
(*            Attributes for types, arrays, signals and strings                     *)
69
(************************************************************************************)		   
70

    
71
type 'basetype vhdl_type_attributes_t =
72
  | TAttNoArg of { id: string }
73
  | TAttIntArg of { id: string; arg: int }
74
  | TAttValArg of { id: string; arg: 'basetype }
75
  | TAttStringArg of { id: string; arg: string }
76
[@@deriving yojson {strict = false}];;
77

    
78
let typ_att_noarg = ["base"; "left"; "right"; "high"; "low"]
79
let typ_att_intarg = ["pos"; "val"; "succ"; "pred"; "leftof"; "rightof"]
80
let typ_att_valarg = ["image"]
81
let typ_att_stringarg = ["value"]
82
  
83
type vhdl_array_attributes_t = AAttInt of { id: string; arg: int; } | AAttAscending
84
[@@deriving yojson {strict = false}];;
85

    
86
let array_att_intarg = ["left"; "right"; "high"; "low"; "range"; "reverse_range"; "length"]  
87

    
88
type vhdl_signal_attributes_t = SigAtt of string
89
[@@deriving yojson {strict = false}];;
90

    
91
type vhdl_string_attributes_t = StringAtt of string
92
[@@deriving yojson {strict = false}];;
93

    
94
(************************************************************************************)		   
95
(*                        Expressions  / Statements                                 *)
96
(************************************************************************************)		   
97
type suffix_selection_t = Idx of int | Range of int * int
98
[@@deriving yojson {strict = false}];;
99

    
100
type vhdl_expr_t =
101
  | Call of vhdl_name_t [@name "CALL"]
102
  | Cst of cst_val_t [@name "CONSTANT_VALUE"]
103
  | Op of { id: string [@default ""]; args: vhdl_expr_t list [@default []]} [@name "EXPRESSION"]
104
  | IsNull [@name "IsNull"]
105
  | Time of { value: int; phy_unit: string [@default ""]}
106
  | Sig of { name: string; att: vhdl_signal_attributes_t option }
107
  | SuffixMod of { expr : vhdl_expr_t; selection : suffix_selection_t }
108
  | Aggregate of { elems : vhdl_element_assoc_t list } [@name "AGGREGATE"]
109
  | Others [@name "OTHERS"]
110
[@@deriving yojson {strict = false}]
111
and					     
112
vhdl_name_t =
113
  | Simple of string [@name "SIMPLE_NAME"]
114
  | Selected of vhdl_name_t list [@name "SELECTED_NAME"]
115
  | Index of { id: vhdl_name_t; exprs: vhdl_expr_t list } [@name "INDEXED_NAME"]
116
  | Slice of { id: vhdl_name_t; range: vhdl_type_t } [@name "SLICE_NAME"]
117
  | Attribute of { id: vhdl_name_t; designator: vhdl_name_t; expr: vhdl_expr_t [@default IsNull]} [@name "ATTRIBUTE_NAME"]
118
  | Function of { id: vhdl_name_t; assoc_list: vhdl_assoc_element_t list } [@name "FUNCTION_CALL"]
119
  | NoName
120
[@@deriving yojson {strict = false}]
121
and vhdl_assoc_element_t =
122
  {
123
    formal_name: vhdl_name_t option [@default Some NoName];
124
    formal_arg: vhdl_name_t option [@default Some NoName];
125
    actual_name: vhdl_name_t option [@default Some NoName];
126
    actual_designator: vhdl_name_t option [@default Some NoName];
127
    actual_expr: vhdl_expr_t option [@default Some IsNull];
128
  }
129
[@@deriving yojson {strict = false}]
130
and vhdl_element_assoc_t =
131
  {
132
    choices: vhdl_expr_t list;
133
    expr: vhdl_expr_t;
134
  }
135
[@@deriving yojson {strict = false}];;
136

    
137
let arith_funs = ["+";"-";"*";"/";"mod"; "rem";"abs";"**";"&"]
138
let bool_funs  = ["and"; "or"; "nand"; "nor"; "xor"; "not"]
139
let rel_funs   = ["<";">";"<=";">=";"/=";"=";"?=";"?/=";"?<";"?<=";"?>";"?>=";"??"]
140
let shift_funs = ["sll";"srl";"sla";"sra";"rol";"ror"]
141

    
142
type vhdl_sequential_stmt_t = 
143
  | VarAssign of { label: string [@default ""]; lhs: vhdl_name_t; rhs: vhdl_expr_t } [@name "VARIABLE_ASSIGNMENT_STATEMENT"]
144
  | SigSeqAssign of { label: string [@default ""]; lhs: vhdl_name_t; rhs: vhdl_expr_t list} [@name "SIGNAL_ASSIGNMENT_STATEMENT"]
145
  | If of { label: string [@default ""]; if_cases: vhdl_if_case_t list;
146
    default: vhdl_sequential_stmt_t list [@default []]; } [@name "IF_STATEMENT"]
147
  | Case of { guard: vhdl_expr_t; branches: vhdl_case_item_t list } [@name "CASE_STATEMENT_TREE"]
148
  | Exit of { label: string [@default ""]; loop_label: string option [@default Some ""]; condition: vhdl_expr_t option [@default Some IsNull]} [@name "EXIT_STATEMENT"]
149
  | Assert of { label: string [@default ""]; cond: vhdl_expr_t; report: vhdl_expr_t [@default IsNull]; severity: vhdl_expr_t [@default IsNull]} [@name "ASSERTION_STATEMENT"]
150
  | Wait [@name "WAIT_STATEMENT"]
151
  | Null of { label: string [@default ""]} [@name "NULL_STATEMENT"]
152
and vhdl_if_case_t = 
153
  {
154
    if_cond: vhdl_expr_t;
155
    if_block: vhdl_sequential_stmt_t list;
156
  }
157
and vhdl_case_item_t = 
158
  {
159
    when_cond: vhdl_expr_t list;
160
    when_stmt: vhdl_sequential_stmt_t list;
161
  }
162
[@@deriving yojson {strict = false}];;
163

    
164
type vhdl_declaration_t =
165
  | VarDecl of { names : string list; typ : vhdl_subtype_indication_t; init_val : cst_val_t option [@default Some (CstInt (0))] } [@name "VARIABLE_DECLARATION"]
166
  | CstDecl of { names : string list; typ : vhdl_subtype_indication_t; init_val : cst_val_t  } [@name "CONSTANT_DECLARATION"]
167
  | SigDecl of { names : string list; typ : vhdl_subtype_indication_t; init_val : cst_val_t option [@default Some (CstInt (0))] } [@name "SIGNAL_DECLARATION"]
168
  | Subprogram of {name: string; kind: string; spec: vhdl_subprogram_spec_t ; decl_part: vhdl_declaration_t list; stmts: vhdl_sequential_stmt_t list} [@name "SUBPROGRAM_BODY"]
169
[@@deriving yojson {strict = false}];;
170
		    
171
type signal_condition_t =
172
  {                            
173
    expr: vhdl_expr_t list;              (* when expression *)
174
    cond: vhdl_expr_t [@default IsNull];  (* optional else case expression. 
175
                                             If None, could be a latch  *)
176
  }
177
[@@deriving yojson {strict = false}];;
178

    
179
type signal_selection_t =
180
  {
181
    expr : vhdl_expr_t;
182
    when_sel: vhdl_expr_t list [@default []];
183
  }
184
[@@deriving yojson {strict = false}];;
185

    
186
type conditional_signal_t =
187
  {
188
    postponed: bool [@default false];
189
    label: string option [@default Some ""];
190
    lhs: vhdl_name_t;        (* assigned signal = target*)
191
    rhs: signal_condition_t list;                   (* expression *)
192
    cond: vhdl_expr_t [@default IsNull];
193
    delay: vhdl_expr_t [@default IsNull];
194
  }
195
[@@deriving yojson {strict = false}];;
196

    
197
type process_t =
198
  { 
199
    id: string option [@default Some ""];
200
    declarations: vhdl_declaration_t list option [@key "PROCESS_DECLARATIVE_PART"] [@default Some []];
201
    active_sigs: vhdl_name_t list [@default []];
202
    body: vhdl_sequential_stmt_t list [@key "PROCESS_STATEMENT_PART"] [@default []]
203
  }
204
[@@deriving yojson {strict = false}];;
205

    
206
type selected_signal_t = 
207
  { 
208
    postponed: bool [@default false];
209
    label: string option [@default Some ""];
210
    lhs: vhdl_name_t;      (* assigned signal = target *)
211
    sel: vhdl_expr_t;  
212
    branches: signal_selection_t list [@default []];
213
    delay: vhdl_expr_t option;
214
  }
215
[@@deriving yojson {strict = false}];;
216
			   
217
type vhdl_concurrent_stmt_t =
218
  | SigAssign of conditional_signal_t [@name "CONDITIONAL_SIGNAL_ASSIGNMENT"]
219
  | Process of process_t [@name "PROCESS_STATEMENT"]
220
  | SelectedSig of selected_signal_t [@name "SELECTED_SIGNAL_ASSIGNMENT"]
221
[@@deriving yojson {strict = false}];;
222
  (*
223
type vhdl_statement_t =
224
  
225
  (* | DeclarationStmt of declaration_stmt_t *)
226
  | ConcurrentStmt of vhdl_concurrent_stmt_t
227
  | SequentialStmt of vhdl_sequential_stmt_t
228
   *)
229
		     
230
(************************************************************************************)		   
231
(*                     Entities                                                     *)
232
(************************************************************************************)		   
233
			     
234
(* TODO? Seems to appear optionally in entities *)
235
type vhdl_generic_t = unit
236
[@@deriving yojson {strict = false}];;
237
			      
238
type vhdl_port_kind_t = 
239
    InPort     [@name "in"]
240
  | OutPort    [@name "out"]
241
  | InoutPort  [@name "inout"]
242
  | BufferPort [@name "buffer"]
243
[@@deriving yojson];;
244
	     
245
type vhdl_port_t =
246
  {
247
    names: string list [@default []];
248
    kind: vhdl_port_kind_t;
249
    typ : string;
250
(*    typ: vhdl_type_t; *)
251
  }
252
[@@deriving yojson {strict = false}];;
253

    
254
type vhdl_entity_t =
255
  {
256
    name: string [@default ""];
257
    generics: vhdl_generic_t list option [@key "GENERIC_CLAUSE"] [@default Some []];
258
    ports: vhdl_port_t list [@key "PORT_CLAUSE"] [@default []];
259
  }
260
[@@deriving yojson {strict = false}];;
261

    
262
(************************************************************************************)		   
263
(*                    Packages / Library loading                                    *)
264
(************************************************************************************)		   
265
				
266
(* Optional. Describes shared definitions *)
267
type vhdl_package_t =
268
  {
269
    name: string [@default ""];
270
    shared_defs: vhdl_definition_t list [@default []];
271
  }
272
[@@deriving yojson {strict = false}];;
273

    
274
type vhdl_load_t = 
275
    Library of string list [@name "LIBRARY_CLAUSE"] [@default ""]
276
  | Use of string list [@name "USE_CLAUSE"] [@default []]
277
[@@deriving yojson];;
278

    
279
(************************************************************************************)		   
280
(*                        Architecture / VHDL Design                                *)
281
(************************************************************************************)		   
282
				       
283
type vhdl_architecture_t =
284
  {
285
    name: string [@default ""];
286
    entity: string [@default ""];
287
    declarations: vhdl_declaration_t list option [@key "ARCHITECTURE_DECLARATIVE_PART"] [@default Some []];
288
    body: vhdl_concurrent_stmt_t list option [@key "ARCHITECTURE_STATEMENT_PART"] [@default Some []]; 
289
  }
290
[@@deriving yojson {strict = false}];;
291
    
292
(* TODO. Configuration is optional *)
293
type vhdl_configuration_t = unit
294
[@@deriving yojson {strict = false}];;
295

    
296
type vhdl_design_t =
297
  {
298
    packages: vhdl_package_t list [@key "PACKAGE_DECLARATION"] [@default []];
299
    libraries: vhdl_load_t list option [@key "CONTEXT_CLAUSE"] [@default Some []];
300
    entities: vhdl_entity_t list [@key "ENTITY_DECLARATION"] [@default []];
301
    architectures: vhdl_architecture_t list [@key "ARCHITECTURE_BODY"] [@default []];
302
    configuration: vhdl_configuration_t option [@key "CONFIGURATION_DECLARATION"] [@default Some ()];
303
  }
304
[@@deriving yojson {strict = false}];;
305

    
306
type vhdl_design_file_t =
307
  {
308
    design_unit: vhdl_design_t list [@key "DESIGN_UNIT"] [@default []];
309
  }
310
[@@deriving yojson {strict = false}];;
311

    
312
type vhdl_file_t = 
313
  {
314
    design_file: vhdl_design_file_t [@key "DESIGN_FILE"];
315
  }
316
[@@deriving yojson];;