Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

lustrec / src / backends / VHDL / vhdl_ast_deriving.ml @ 1f15a1b9

History | View | Annotate | Download (233 KB)

1 40364f53 Arnaud Dieumegard
let base_types =
2
  ["integer";
3
  "character";
4
  "bit";
5
  "real";
6
  "natural";
7
  "positive";
8
  "std_logic";
9
  "std_logic_vector"] 
10
let std_logic_cst = ["U"; "X"; "0"; "1"; "Z"; "W"; "L"; "H"; "-"] 
11
let literal_base = ["B"; "O"; "X"; "UB"; "UO"; "UX"; "SB"; "SO"; "SX"; "D"] 
12
type vhdl_cst_val_t =
13
  | CstInt of int 
14
  | CstStdLogic of string 
15
  | CstLiteral of string [@name "CST_LITERAL"]
16
17
let rec (pp_vhdl_cst_val_t :
18
          Format.formatter -> vhdl_cst_val_t -> Ppx_deriving_runtime.unit)
19
  =
20
  ((let open! Ppx_deriving_runtime in
21
      fun fmt  ->
22
        function
23
        | CstInt a0 ->
24
             (Format.fprintf fmt "%d") a0;
25
        | CstStdLogic a0 ->
26
             (Format.fprintf fmt "%S") a0;
27
        | CstLiteral a0 ->
28 f779d524 Arnaud Dieumegard
             (Format.fprintf fmt "%s") a0;)
29 40364f53 Arnaud Dieumegard
  [@ocaml.warning "-A"])
30
31
and show_vhdl_cst_val_t : vhdl_cst_val_t -> Ppx_deriving_runtime.string =
32
  fun x  -> Format.asprintf "%a" pp_vhdl_cst_val_t x
33
34
let rec (vhdl_cst_val_t_to_yojson : vhdl_cst_val_t -> Yojson.Safe.json) =
35
  ((let open! Ppx_deriving_yojson_runtime in
36
      function
37
      | CstInt arg0 ->
38
          `List
39
            [`String "CstInt";
40
            ((fun (x : Ppx_deriving_runtime.int)  -> `Int x)) arg0]
41
      | CstStdLogic arg0 ->
42
          `List
43
            [`String "CstStdLogic";
44
            ((fun (x : Ppx_deriving_runtime.string)  -> `String x)) arg0]
45
      | CstLiteral arg0 ->
46
          `List
47
            [`String "CST_LITERAL";
48
            ((fun (x : Ppx_deriving_runtime.string)  -> `String x)) arg0])
49
  [@ocaml.warning "-A"])
50
51
and (vhdl_cst_val_t_of_yojson :
52
      Yojson.Safe.json -> vhdl_cst_val_t Ppx_deriving_yojson_runtime.error_or)
53
  =
54
  ((let open! Ppx_deriving_yojson_runtime in
55
      function
56
      | `List ((`String "CstInt")::arg0::[]) ->
57
          ((function
58
            | `Int x -> Result.Ok x
59
            | _ -> Result.Error "Vhdl_ast.vhdl_cst_val_t") arg0) >>=
60
            ((fun arg0  -> Result.Ok (CstInt arg0)))
61
      | `List ((`String "CstStdLogic")::arg0::[]) ->
62
          ((function
63
            | `String x -> Result.Ok x
64
            | _ -> Result.Error "Vhdl_ast.vhdl_cst_val_t") arg0) >>=
65
            ((fun arg0  -> Result.Ok (CstStdLogic arg0)))
66
      | `List ((`String "CST_LITERAL")::arg0::[]) ->
67
          ((function
68
            | `String x -> Result.Ok x
69
            | _ -> Result.Error "Vhdl_ast.vhdl_cst_val_t") arg0) >>=
70
            ((fun arg0  -> Result.Ok (CstLiteral arg0)))
71
      | _ -> Result.Error "Vhdl_ast.vhdl_cst_val_t")
72
  [@ocaml.warning "-A"])
73
74
type vhdl_type_t =
75
  | Base of string 
76
  | Range of string option * int * int 
77
  | Bit_vector of int * int 
78 248eb65e Arnaud Dieumegard
  | Array of
79
  {
80
  indexes: vhdl_name_t list ;
81
  const: vhdl_constraint_t option [@default None];
82
  definition: vhdl_subtype_indication_t } [@name "ARRAY_TYPE_DEFINITION"]
83
  | Record of vhdl_element_declaration_t list
84
  [@name "RECORD_TYPE_DEFINITION"]
85
  | Enumerated of vhdl_name_t list [@name "ENUMERATION_TYPE_DEFINITION"]
86 40364f53 Arnaud Dieumegard
  | Void 
87 248eb65e Arnaud Dieumegard
and vhdl_element_declaration_t =
88
  {
89
  names: vhdl_name_t list ;
90
  definition: vhdl_subtype_indication_t }
91 40364f53 Arnaud Dieumegard
and vhdl_subtype_indication_t =
92
  {
93
  name: vhdl_name_t [@default NoName];
94
  functionName: vhdl_name_t [@default NoName];
95
  const: vhdl_constraint_t [@default NoConstraint]}
96
and vhdl_discrete_range_t =
97
  | SubDiscreteRange of vhdl_subtype_indication_t
98
  [@name "SUB_DISCRETE_RANGE"]
99
  | NamedRange of vhdl_name_t [@name "NAMED_RANGE"]
100
  | DirectedRange of
101
  {
102
  direction: string ;
103
  from: vhdl_expr_t ;
104
  _to: vhdl_expr_t } [@name "RANGE_WITH_DIRECTION"]
105
and vhdl_constraint_t =
106
  | RefConstraint of {
107
  ref_name: vhdl_name_t } 
108
  | RangeConstraint of {
109
  range: vhdl_discrete_range_t } [@name "RANGE_CONSTRAINT"]
110
  | IndexConstraint of {
111
  ranges: vhdl_discrete_range_t list } [@name "INDEX_CONSTRAINT"]
112
  | ArrayConstraint of
113
  {
114
  ranges: vhdl_discrete_range_t list ;
115
  sub: vhdl_constraint_t } [@name "ARRAY_CONSTRAINT"]
116
  | RecordConstraint 
117
  | NoConstraint 
118
and vhdl_definition_t =
119
  | Type of {
120
  name: vhdl_name_t ;
121
  definition: vhdl_type_t } [@name "TYPE_DECLARATION"]
122
  | Subtype of {
123
  name: vhdl_name_t ;
124
  typ: vhdl_subtype_indication_t } [@name "SUBTYPE_DECLARATION"]
125
and vhdl_expr_t =
126
  | Call of vhdl_name_t [@name "CALL"]
127 ab6312e7 Arnaud Dieumegard
  | Cst of
128
  {
129
  value: vhdl_cst_val_t ;
130
  unit_name: vhdl_name_t option [@default None]} [@name "CONSTANT_VALUE"]
131 40364f53 Arnaud Dieumegard
  | Op of {
132
  id: string [@default ""];
133
  args: vhdl_expr_t list [@default []]} [@name "EXPRESSION"]
134
  | IsNull [@name "IsNull"]
135
  | Time of {
136
  value: int ;
137
  phy_unit: string [@default ""]} 
138
  | Sig of {
139
  name: vhdl_name_t ;
140
  att: vhdl_signal_attributes_t option } 
141
  | SuffixMod of {
142
  expr: vhdl_expr_t ;
143
  selection: vhdl_suffix_selection_t } 
144
  | Aggregate of {
145
  elems: vhdl_element_assoc_t list } [@name "AGGREGATE"]
146
  | Others [@name "OTHERS"]
147
and vhdl_name_t =
148
  | Simple of string [@name "SIMPLE_NAME"]
149
  | Identifier of string [@name "IDENTIFIER"]
150
  | Selected of vhdl_name_t list [@name "SELECTED_NAME"]
151
  | Index of {
152
  id: vhdl_name_t ;
153
  exprs: vhdl_expr_t list } [@name "INDEXED_NAME"]
154
  | Slice of {
155
  id: vhdl_name_t ;
156
  range: vhdl_discrete_range_t } [@name "SLICE_NAME"]
157
  | Attribute of
158
  {
159
  id: vhdl_name_t ;
160
  designator: vhdl_name_t ;
161
  expr: vhdl_expr_t [@default IsNull]} [@name "ATTRIBUTE_NAME"]
162
  | Function of {
163
  id: vhdl_name_t ;
164
  assoc_list: vhdl_assoc_element_t list } [@name "FUNCTION_CALL"]
165
  | NoName 
166
and vhdl_assoc_element_t =
167
  {
168 00970bbf Arnaud Dieumegard
  formal_name: vhdl_name_t option [@default None];
169
  formal_arg: vhdl_name_t option [@default None];
170
  actual_name: vhdl_name_t option [@default None];
171
  actual_designator: vhdl_name_t option [@default None];
172
  actual_expr: vhdl_expr_t option [@default None]}
173 40364f53 Arnaud Dieumegard
and vhdl_element_assoc_t = {
174
  choices: vhdl_expr_t list ;
175
  expr: vhdl_expr_t }
176
and vhdl_array_attributes_t =
177
  | AAttInt of {
178
  id: string ;
179
  arg: int } 
180
  | AAttAscending 
181
and vhdl_signal_attributes_t =
182
  | SigAtt of string 
183
and vhdl_string_attributes_t =
184
  | StringAtt of string 
185
and vhdl_suffix_selection_t =
186
  | Idx of int 
187
  | SuffixRange of int * int
188
189
let rec pp_vhdl_type_t :
190
  Format.formatter -> vhdl_type_t -> Ppx_deriving_runtime.unit =
191 248eb65e Arnaud Dieumegard
  let __4 () = pp_vhdl_name_t
192
  
193
  and __3 () = pp_vhdl_element_declaration_t
194
  
195
  and __2 () = pp_vhdl_subtype_indication_t
196
  
197
  and __1 () = pp_vhdl_constraint_t
198
  
199
  and __0 () = pp_vhdl_name_t
200
in
201 40364f53 Arnaud Dieumegard
  ((let open! Ppx_deriving_runtime in
202
      fun fmt  ->
203
        function
204
        | Base a0 ->
205 f779d524 Arnaud Dieumegard
             (Format.fprintf fmt "%s") a0;
206 40364f53 Arnaud Dieumegard
        | Range (a0,a1,a2) ->
207 f779d524 Arnaud Dieumegard
             ((
208
               (Format.fprintf fmt "%d") a1);
209
               ((function
210 389493d3 Arnaud Dieumegard
                 | None  -> Format.pp_print_string fmt ""
211 40364f53 Arnaud Dieumegard
                 | Some x ->
212 389493d3 Arnaud Dieumegard
                      (Format.fprintf fmt "%s") x;
213 f779d524 Arnaud Dieumegard
                      )) a0;
214 40364f53 Arnaud Dieumegard
              (Format.fprintf fmt "%d") a2);
215
        | Bit_vector (a0,a1) ->
216 389493d3 Arnaud Dieumegard
             (Format.fprintf fmt "array (%d,%d) of bit") a0 a1;
217 248eb65e Arnaud Dieumegard
        | Array
218
            { indexes = aindexes; const = aconst; definition = adefinition }
219
            ->
220
            Format.fprintf fmt "array";
221
            (match aindexes with
222
            | [] -> Format.fprintf fmt "";
223
            | _ ->
224
              ((fun x  ->
225
                ignore
226
                (List.fold_left
227
                  (fun sep  ->
228
                    fun x  ->
229
                      if sep then Format.fprintf fmt ",@ ";
230
                      ((__0 ()) fmt) x;
231
                      true) false x)) aindexes));
232
            (function
233
              | None  -> Format.pp_print_string fmt ""
234
              | Some x ->
235
                ((__1 ()) fmt) x) aconst;
236
            Format.fprintf fmt " of ";
237
            ((__2 ()) fmt) adefinition;
238
        | Record a0 ->
239
            Format.fprintf fmt "@[<v 2>record@;";
240
            (fun x  ->
241
              ignore
242
                (List.fold_left
243
                  (fun sep  ->
244
                    fun x  ->
245
                      if sep then Format.fprintf fmt ";@;";
246
                        ((__3 ()) fmt) x;
247
                        true) false x);
248
              Format.fprintf fmt "@]@;end record") a0;
249 40364f53 Arnaud Dieumegard
        | Enumerated a0 ->
250 248eb65e Arnaud Dieumegard
            (Format.fprintf fmt "(";
251
            ((fun x  ->
252
              ignore
253
              (List.fold_left
254
                (fun sep  ->
255
                  fun x  ->
256
                    if sep then Format.fprintf fmt ",@ ";
257
                      ((__4 ()) fmt) x;
258
                    true) false x))) a0;
259
             Format.fprintf fmt ")");
260 389493d3 Arnaud Dieumegard
        | Void  -> Format.pp_print_string fmt "")
261 40364f53 Arnaud Dieumegard
    [@ocaml.warning "-A"])
262
263
and show_vhdl_type_t : vhdl_type_t -> Ppx_deriving_runtime.string =
264
  fun x  -> Format.asprintf "%a" pp_vhdl_type_t x
265
266 248eb65e Arnaud Dieumegard
and pp_vhdl_element_declaration_t :
267
  Format.formatter -> vhdl_element_declaration_t -> Ppx_deriving_runtime.unit
268
  =
269
  let __1 () = pp_vhdl_subtype_indication_t
270
  
271
  and __0 () = pp_vhdl_name_t
272
   in
273
  ((let open! Ppx_deriving_runtime in
274
      fun fmt  ->
275
        fun x  ->
276
            (fun x  ->
277
                ignore
278
                  (List.fold_left
279
                     (fun sep  ->
280
                        fun x  ->
281
                          if sep then Format.fprintf fmt ",@ ";
282
                          ((__0 ()) fmt) x;
283
                          true) false x)) x.names;
284
           Format.fprintf fmt ":@ ";
285
           ((__1 ()) fmt) x.definition)
286
    [@ocaml.warning "-A"])
287
288
and show_vhdl_element_declaration_t :
289
  vhdl_element_declaration_t -> Ppx_deriving_runtime.string =
290
  fun x  -> Format.asprintf "%a" pp_vhdl_element_declaration_t x
291
292 40364f53 Arnaud Dieumegard
and pp_vhdl_subtype_indication_t :
293
  Format.formatter -> vhdl_subtype_indication_t -> Ppx_deriving_runtime.unit
294
  =
295
  let __2 () = pp_vhdl_constraint_t
296
  
297
  and __1 () = pp_vhdl_name_t
298
  
299
  and __0 () = pp_vhdl_name_t
300
   in
301
  ((let open! Ppx_deriving_runtime in
302
      fun fmt  ->
303
        fun x  ->
304 f779d524 Arnaud Dieumegard
          ((__0 ()) fmt) x.name;
305
          ((__1 ()) fmt) x.functionName;
306 d4175560 Arnaud Dieumegard
          (match x.const with
307
            | NoConstraint -> Format.fprintf fmt "";
308
            | _ -> Format.fprintf fmt " ";
309
                   ((__2 ()) fmt) x.const))
310 40364f53 Arnaud Dieumegard
    [@ocaml.warning "-A"])
311
312
and show_vhdl_subtype_indication_t :
313
  vhdl_subtype_indication_t -> Ppx_deriving_runtime.string =
314
  fun x  -> Format.asprintf "%a" pp_vhdl_subtype_indication_t x
315
316
and pp_vhdl_discrete_range_t :
317
  Format.formatter -> vhdl_discrete_range_t -> Ppx_deriving_runtime.unit =
318
  let __3 () = pp_vhdl_expr_t
319
  
320
  and __2 () = pp_vhdl_expr_t
321
  
322
  and __1 () = pp_vhdl_name_t
323
  
324
  and __0 () = pp_vhdl_subtype_indication_t
325
   in
326
  ((let open! Ppx_deriving_runtime in
327
      fun fmt  ->
328
        function
329
        | SubDiscreteRange a0 ->
330
             ((__0 ()) fmt) a0;
331
        | NamedRange a0 ->
332
             ((__1 ()) fmt) a0;
333
        | DirectedRange { direction = adirection; from = afrom; _to = a_to }
334
            ->
335
               ((__2 ()) fmt) afrom;
336 f779d524 Arnaud Dieumegard
               (Format.fprintf fmt " %s ") adirection;
337
               ((__3 ()) fmt) a_to;
338
    )
339 40364f53 Arnaud Dieumegard
    [@ocaml.warning "-A"])
340
341
and show_vhdl_discrete_range_t :
342
  vhdl_discrete_range_t -> Ppx_deriving_runtime.string =
343
  fun x  -> Format.asprintf "%a" pp_vhdl_discrete_range_t x
344
345 3bc26d43 Arnaud Dieumegard
(* TODO Adapt for: ArrayConstraint, RecordConstraint *)
346 40364f53 Arnaud Dieumegard
and pp_vhdl_constraint_t :
347
  Format.formatter -> vhdl_constraint_t -> Ppx_deriving_runtime.unit =
348
  let __4 () = pp_vhdl_constraint_t
349
  
350
  and __3 () = pp_vhdl_discrete_range_t
351
  
352
  and __2 () = pp_vhdl_discrete_range_t
353
  
354
  and __1 () = pp_vhdl_discrete_range_t
355
  
356
  and __0 () = pp_vhdl_name_t
357
   in
358
  ((let open! Ppx_deriving_runtime in
359
      fun fmt  ->
360
        function
361
        | RefConstraint { ref_name = aref_name } ->
362 f779d524 Arnaud Dieumegard
             (Format.fprintf fmt "(";
363 40364f53 Arnaud Dieumegard
              ((__0 ()) fmt) aref_name;
364 f779d524 Arnaud Dieumegard
              Format.fprintf fmt ")");
365 40364f53 Arnaud Dieumegard
        | RangeConstraint { range = arange } ->
366 f779d524 Arnaud Dieumegard
             (Format.fprintf fmt "(";
367 40364f53 Arnaud Dieumegard
              ((__1 ()) fmt) arange;
368 f779d524 Arnaud Dieumegard
              Format.fprintf fmt ")");
369 40364f53 Arnaud Dieumegard
        | IndexConstraint { ranges = aranges } ->
370 f779d524 Arnaud Dieumegard
            Format.fprintf fmt "(";
371
            ((fun x  ->
372
                ignore
373
                  (List.fold_left
374
                     (fun sep  ->
375
                        fun x  ->
376
                          if sep then Format.fprintf fmt ", ";
377
                          ((__2 ()) fmt) x;
378
                          true) false x))) aranges;
379
            Format.fprintf fmt ")";
380 40364f53 Arnaud Dieumegard
        | ArrayConstraint { ranges = aranges; sub = asub } ->
381
            (Format.fprintf fmt "@[<2>ArrayConstraint {@,";
382
             ((Format.fprintf fmt "@[%s =@ " "ranges";
383
               ((fun x  ->
384
                   Format.fprintf fmt "@[<2>[";
385
                   ignore
386
                     (List.fold_left
387
                        (fun sep  ->
388
                           fun x  ->
389
                             if sep then Format.fprintf fmt ";@ ";
390
                             ((__3 ()) fmt) x;
391
                             true) false x);
392
                   Format.fprintf fmt "@,]@]")) aranges;
393
               Format.fprintf fmt "@]");
394
              Format.fprintf fmt ";@ ";
395
              Format.fprintf fmt "@[%s =@ " "sub";
396
              ((__4 ()) fmt) asub;
397
              Format.fprintf fmt "@]");
398
             Format.fprintf fmt "@]}")
399 f779d524 Arnaud Dieumegard
        | RecordConstraint  -> Format.pp_print_string fmt ""
400
        | NoConstraint  -> Format.pp_print_string fmt "")
401 40364f53 Arnaud Dieumegard
    [@ocaml.warning "-A"])
402
403
and show_vhdl_constraint_t : vhdl_constraint_t -> Ppx_deriving_runtime.string
404
  = fun x  -> Format.asprintf "%a" pp_vhdl_constraint_t x
405
406
and pp_vhdl_definition_t :
407
  Format.formatter -> vhdl_definition_t -> Ppx_deriving_runtime.unit =
408
  let __3 () = pp_vhdl_subtype_indication_t
409
  
410
  and __2 () = pp_vhdl_name_t
411
  
412
  and __1 () = pp_vhdl_type_t
413
  
414
  and __0 () = pp_vhdl_name_t
415
   in
416
  ((let open! Ppx_deriving_runtime in
417
      fun fmt  ->
418
        function
419
        | Type { name = aname; definition = adefinition } ->
420 3bc26d43 Arnaud Dieumegard
            Format.fprintf fmt "type ";
421 f779d524 Arnaud Dieumegard
            ((__0 ()) fmt) aname;
422
            Format.fprintf fmt " is ";
423
            ((__1 ()) fmt) adefinition;
424 40364f53 Arnaud Dieumegard
        | Subtype { name = aname; typ = atyp } ->
425 3bc26d43 Arnaud Dieumegard
            Format.fprintf fmt "subtype ";
426 f779d524 Arnaud Dieumegard
            ((__2 ()) fmt) aname;
427
            Format.fprintf fmt " is ";
428
            ((__3 ()) fmt) atyp;
429
   )
430 40364f53 Arnaud Dieumegard
    [@ocaml.warning "-A"])
431
432
and show_vhdl_definition_t : vhdl_definition_t -> Ppx_deriving_runtime.string
433
  = fun x  -> Format.asprintf "%a" pp_vhdl_definition_t x
434
435 389493d3 Arnaud Dieumegard
(* TODO adapt for Op, Time, Sig, suffixMod, Aggregate *)
436 40364f53 Arnaud Dieumegard
and pp_vhdl_expr_t :
437
  Format.formatter -> vhdl_expr_t -> Ppx_deriving_runtime.unit =
438 ab6312e7 Arnaud Dieumegard
  let __8 () = pp_vhdl_element_assoc_t
439 40364f53 Arnaud Dieumegard
  
440 ab6312e7 Arnaud Dieumegard
  and __7 () = pp_vhdl_suffix_selection_t
441 40364f53 Arnaud Dieumegard
  
442 ab6312e7 Arnaud Dieumegard
  and __6 () = pp_vhdl_expr_t
443 40364f53 Arnaud Dieumegard
  
444 ab6312e7 Arnaud Dieumegard
  and __5 () = pp_vhdl_signal_attributes_t
445 40364f53 Arnaud Dieumegard
  
446 ab6312e7 Arnaud Dieumegard
  and __4 () = pp_vhdl_name_t
447 40364f53 Arnaud Dieumegard
  
448 ab6312e7 Arnaud Dieumegard
  and __3 () = pp_vhdl_expr_t
449
  
450
  and __2 () = pp_vhdl_name_t
451 40364f53 Arnaud Dieumegard
  
452
  and __1 () = pp_vhdl_cst_val_t
453
  
454
  and __0 () = pp_vhdl_name_t
455
   in
456
  ((let open! Ppx_deriving_runtime in
457
      fun fmt  ->
458
        function
459
        | Call a0 ->
460
             ((__0 ()) fmt) a0;
461 ab6312e7 Arnaud Dieumegard
        | Cst { value = avalue; unit_name = aunit_name } ->
462
             ((__1 ()) fmt) avalue;
463 1f15a1b9 Arnaud Dieumegard
             (function
464 ab6312e7 Arnaud Dieumegard
                | None  -> Format.pp_print_string fmt ""
465
                | Some x ->
466 1f15a1b9 Arnaud Dieumegard
                    Format.fprintf fmt " ";
467
                    ((__2 ()) fmt) x) aunit_name;
468 40364f53 Arnaud Dieumegard
        | Op { id = aid; args = aargs } ->
469 f779d524 Arnaud Dieumegard
            (match aargs with
470
            | [] -> (Format.fprintf fmt "%s") aid;
471
            | hd::[] ->
472
               (Format.fprintf fmt "%s") aid;
473 ab6312e7 Arnaud Dieumegard
               ((__3 ()) fmt) hd
474 f779d524 Arnaud Dieumegard
            | hd::(hd2::[]) -> 
475 ab6312e7 Arnaud Dieumegard
               ((__3 ()) fmt) hd;
476 f779d524 Arnaud Dieumegard
               (Format.fprintf fmt " %s ") aid;
477 ab6312e7 Arnaud Dieumegard
               ((__3 ()) fmt) hd2
478 f779d524 Arnaud Dieumegard
            | _ ->
479 40364f53 Arnaud Dieumegard
            (Format.fprintf fmt "@[<2>Op {@,";
480
             ((Format.fprintf fmt "@[%s =@ " "id";
481
               (Format.fprintf fmt "%S") aid;
482
               Format.fprintf fmt "@]");
483
              Format.fprintf fmt ";@ ";
484
              Format.fprintf fmt "@[%s =@ " "args";
485
              ((fun x  ->
486
                  Format.fprintf fmt "@[<2>[";
487
                  ignore
488
                    (List.fold_left
489
                       (fun sep  ->
490
                          fun x  ->
491
                            if sep then Format.fprintf fmt ";@ ";
492 ab6312e7 Arnaud Dieumegard
                            ((__3 ()) fmt) x;
493 40364f53 Arnaud Dieumegard
                            true) false x);
494
                  Format.fprintf fmt "@,]@]")) aargs;
495
              Format.fprintf fmt "@]");
496 f779d524 Arnaud Dieumegard
             Format.fprintf fmt "@]}"))
497
        | IsNull  -> Format.pp_print_string fmt ""
498 40364f53 Arnaud Dieumegard
        | Time { value = avalue; phy_unit = aphy_unit } ->
499
            (Format.fprintf fmt "@[<2>Time {@,";
500
             ((Format.fprintf fmt "@[%s =@ " "value";
501
               (Format.fprintf fmt "%d") avalue;
502
               Format.fprintf fmt "@]");
503
              Format.fprintf fmt ";@ ";
504
              Format.fprintf fmt "@[%s =@ " "phy_unit";
505
              (Format.fprintf fmt "%S") aphy_unit;
506
              Format.fprintf fmt "@]");
507
             Format.fprintf fmt "@]}")
508
        | Sig { name = aname; att = aatt } ->
509 389493d3 Arnaud Dieumegard
            (Format.fprintf fmt "--@[<2>Sig {@,";
510 40364f53 Arnaud Dieumegard
             ((Format.fprintf fmt "@[%s =@ " "name";
511 ab6312e7 Arnaud Dieumegard
               ((__4 ()) fmt) aname;
512 40364f53 Arnaud Dieumegard
               Format.fprintf fmt "@]");
513
              Format.fprintf fmt ";@ ";
514
              Format.fprintf fmt "@[%s =@ " "att";
515
              ((function
516
                | None  -> Format.pp_print_string fmt "None"
517
                | Some x ->
518
                    (Format.pp_print_string fmt "(Some ";
519 ab6312e7 Arnaud Dieumegard
                     ((__5 ()) fmt) x;
520 40364f53 Arnaud Dieumegard
                     Format.pp_print_string fmt ")"))) aatt;
521
              Format.fprintf fmt "@]");
522
             Format.fprintf fmt "@]}")
523
        | SuffixMod { expr = aexpr; selection = aselection } ->
524 389493d3 Arnaud Dieumegard
            (Format.fprintf fmt "--@[<2>SuffixMod {@,";
525 40364f53 Arnaud Dieumegard
             ((Format.fprintf fmt "@[%s =@ " "expr";
526 ab6312e7 Arnaud Dieumegard
               ((__6 ()) fmt) aexpr;
527 40364f53 Arnaud Dieumegard
               Format.fprintf fmt "@]");
528
              Format.fprintf fmt ";@ ";
529
              Format.fprintf fmt "@[%s =@ " "selection";
530 ab6312e7 Arnaud Dieumegard
              ((__7 ()) fmt) aselection;
531 40364f53 Arnaud Dieumegard
              Format.fprintf fmt "@]");
532
             Format.fprintf fmt "@]}")
533
        | Aggregate { elems = aelems } ->
534 389493d3 Arnaud Dieumegard
            (Format.fprintf fmt "--@[<2>Aggregate {@,";
535 40364f53 Arnaud Dieumegard
             (Format.fprintf fmt "@[%s =@ " "elems";
536
              ((fun x  ->
537
                  Format.fprintf fmt "@[<2>[";
538
                  ignore
539
                    (List.fold_left
540
                       (fun sep  ->
541
                          fun x  ->
542
                            if sep then Format.fprintf fmt ";@ ";
543 ab6312e7 Arnaud Dieumegard
                            ((__8 ()) fmt) x;
544 40364f53 Arnaud Dieumegard
                            true) false x);
545
                  Format.fprintf fmt "@,]@]")) aelems;
546
              Format.fprintf fmt "@]");
547
             Format.fprintf fmt "@]}")
548 f779d524 Arnaud Dieumegard
        | Others  -> Format.pp_print_string fmt "others")
549 40364f53 Arnaud Dieumegard
    [@ocaml.warning "-A"])
550
551
and show_vhdl_expr_t : vhdl_expr_t -> Ppx_deriving_runtime.string =
552
  fun x  -> Format.asprintf "%a" pp_vhdl_expr_t x
553
554
and pp_vhdl_name_t :
555
  Format.formatter -> vhdl_name_t -> Ppx_deriving_runtime.unit =
556
  let __9 () = pp_vhdl_assoc_element_t
557
  
558
  and __8 () = pp_vhdl_name_t
559
  
560
  and __7 () = pp_vhdl_expr_t
561
  
562
  and __6 () = pp_vhdl_name_t
563
  
564
  and __5 () = pp_vhdl_name_t
565
  
566
  and __4 () = pp_vhdl_discrete_range_t
567
  
568
  and __3 () = pp_vhdl_name_t
569
  
570
  and __2 () = pp_vhdl_expr_t
571
  
572
  and __1 () = pp_vhdl_name_t
573
  
574
  and __0 () = pp_vhdl_name_t
575
   in
576
  ((let open! Ppx_deriving_runtime in
577
      fun fmt  ->
578
        function
579
        | Simple a0 ->
580 f779d524 Arnaud Dieumegard
             (Format.fprintf fmt "%s") a0;
581 40364f53 Arnaud Dieumegard
        | Identifier a0 ->
582 f779d524 Arnaud Dieumegard
             (Format.fprintf fmt "%s") a0;
583 40364f53 Arnaud Dieumegard
        | Selected a0 ->
584
             ((fun x  ->
585
                 ignore
586
                   (List.fold_left
587
                      (fun sep  ->
588
                         fun x  ->
589 f779d524 Arnaud Dieumegard
                           if sep then Format.fprintf fmt ".";
590 40364f53 Arnaud Dieumegard
                           ((__0 ()) fmt) x;
591 f779d524 Arnaud Dieumegard
                           true) false x);) a0;)
592 40364f53 Arnaud Dieumegard
        | Index { id = aid; exprs = aexprs } ->
593 f779d524 Arnaud Dieumegard
            ((__1 ()) fmt) aid;
594
            Format.fprintf fmt "(";
595
            (fun x  ->
596
                ignore
597
                (List.fold_left
598
                  (fun sep  ->
599
                    fun x  ->
600
                      if sep then Format.fprintf fmt ",@ ";
601
                                  ((__2 ()) fmt) x;
602
                                  true
603
                  ) false x);
604
            ) aexprs;
605
            Format.fprintf fmt ")";
606 40364f53 Arnaud Dieumegard
        | Slice { id = aid; range = arange } ->
607 f779d524 Arnaud Dieumegard
              ((__3 ()) fmt) aid;
608
              Format.fprintf fmt "(";
609 40364f53 Arnaud Dieumegard
              ((__4 ()) fmt) arange;
610 f779d524 Arnaud Dieumegard
              Format.fprintf fmt ")";
611 40364f53 Arnaud Dieumegard
        | Attribute { id = aid; designator = adesignator; expr = aexpr } ->
612 f779d524 Arnaud Dieumegard
              ((__5 ()) fmt) aid;
613
              Format.fprintf fmt "\'";
614
              ((__6 ()) fmt) adesignator;
615
              (match aexpr with
616
              | IsNull -> Format.fprintf fmt "";
617
              | _ ->
618
                Format.fprintf fmt "(";
619
                ((__7 ()) fmt) aexpr;
620
                Format.fprintf fmt ")")
621 40364f53 Arnaud Dieumegard
        | Function { id = aid; assoc_list = aassoc_list } ->
622 00970bbf Arnaud Dieumegard
            (((__8 ()) fmt) aid;
623
            Format.fprintf fmt "(";
624
            ((fun x  ->
625
              Format.fprintf fmt "@[";
626
              ignore
627
                (List.fold_left
628
                   (fun sep  ->
629
                      fun x  ->
630
                        if sep then Format.fprintf fmt ";@ ";
631
                        ((__9 ()) fmt) x;
632
                        true) false x);
633
            Format.fprintf fmt "@]")) aassoc_list;
634
            Format.fprintf fmt ")";)
635 f779d524 Arnaud Dieumegard
        | NoName  -> Format.pp_print_string fmt "")
636 40364f53 Arnaud Dieumegard
    [@ocaml.warning "-A"])
637
638
and show_vhdl_name_t : vhdl_name_t -> Ppx_deriving_runtime.string =
639
  fun x  -> Format.asprintf "%a" pp_vhdl_name_t x
640
641
and pp_vhdl_assoc_element_t :
642
  Format.formatter -> vhdl_assoc_element_t -> Ppx_deriving_runtime.unit =
643
  let __4 () = pp_vhdl_expr_t
644
  
645
  and __3 () = pp_vhdl_name_t
646
  
647
  and __2 () = pp_vhdl_name_t
648
  
649
  and __1 () = pp_vhdl_name_t
650
  
651
  and __0 () = pp_vhdl_name_t
652
   in
653
  ((let open! Ppx_deriving_runtime in
654
      fun fmt  ->
655
        fun x  ->
656 00970bbf Arnaud Dieumegard
          (match x.formal_name with
657
          | None -> Format.pp_print_string fmt ""
658
          | Some NoName -> Format.pp_print_string fmt ""
659
          | Some a -> 
660
              (((__0 ()) fmt) a;
661
              (match x.formal_arg with
662
              | None -> ()
663
              | Some b -> Format.fprintf fmt "(";
664
                          ((__1 ()) fmt) b;
665
                          Format.fprintf fmt ")");
666
              Format.fprintf fmt " => "));
667
          (match x.actual_name with
668
          | None -> Format.pp_print_string fmt ""
669
          | Some a -> 
670
              (((__2 ()) fmt) a;
671
              (match x.actual_designator with
672
              | None -> ()
673
              | Some NoName -> Format.pp_print_string fmt ""
674
              | Some b -> (Format.fprintf fmt "(";
675
                          ((__3 ()) fmt) b;
676
                          Format.fprintf fmt ")"));
677
              (match x.actual_expr with
678
              | None -> ()
679
              | Some IsNull -> Format.pp_print_string fmt ""
680
              | Some c -> (Format.fprintf fmt "(";
681
                          ((__4 ()) fmt) c;
682
                          Format.fprintf fmt ")"))));)
683 40364f53 Arnaud Dieumegard
    [@ocaml.warning "-A"])
684
685
and show_vhdl_assoc_element_t :
686
  vhdl_assoc_element_t -> Ppx_deriving_runtime.string =
687
  fun x  -> Format.asprintf "%a" pp_vhdl_assoc_element_t x
688
689
and pp_vhdl_element_assoc_t :
690
  Format.formatter -> vhdl_element_assoc_t -> Ppx_deriving_runtime.unit =
691
  let __1 () = pp_vhdl_expr_t
692
  
693
  and __0 () = pp_vhdl_expr_t
694
   in
695
  ((let open! Ppx_deriving_runtime in
696
      fun fmt  ->
697
        fun x  ->
698 389493d3 Arnaud Dieumegard
            (match x.choices with
699
            | [] -> Format.fprintf fmt "";
700
            | _ -> 
701
              (((fun x  ->
702 40364f53 Arnaud Dieumegard
                Format.fprintf fmt "@[<2>[";
703
                ignore
704
                  (List.fold_left
705
                     (fun sep  ->
706
                        fun x  ->
707 389493d3 Arnaud Dieumegard
                          if sep then Format.fprintf fmt "|@ ";
708 40364f53 Arnaud Dieumegard
                          ((__0 ()) fmt) x;
709 389493d3 Arnaud Dieumegard
                          true) false x))) x.choices;
710
              Format.fprintf fmt " => ";));
711
           ((__1 ()) fmt) x.expr)
712 40364f53 Arnaud Dieumegard
    [@ocaml.warning "-A"])
713
714
and show_vhdl_element_assoc_t :
715
  vhdl_element_assoc_t -> Ppx_deriving_runtime.string =
716
  fun x  -> Format.asprintf "%a" pp_vhdl_element_assoc_t x
717
718 389493d3 Arnaud Dieumegard
(* TODO *)
719 40364f53 Arnaud Dieumegard
and (pp_vhdl_array_attributes_t :
720
      Format.formatter ->
721
        vhdl_array_attributes_t -> Ppx_deriving_runtime.unit)
722
  =
723
  ((let open! Ppx_deriving_runtime in
724
      fun fmt  ->
725
        function
726
        | AAttInt { id = aid; arg = aarg } ->
727
            (Format.fprintf fmt "@[<2>AAttInt {@,";
728
             ((Format.fprintf fmt "@[%s =@ " "id";
729
               (Format.fprintf fmt "%S") aid;
730
               Format.fprintf fmt "@]");
731
              Format.fprintf fmt ";@ ";
732
              Format.fprintf fmt "@[%s =@ " "arg";
733
              (Format.fprintf fmt "%d") aarg;
734
              Format.fprintf fmt "@]");
735
             Format.fprintf fmt "@]}")
736
        | AAttAscending  -> Format.pp_print_string fmt "AAttAscending")
737
  [@ocaml.warning "-A"])
738
739
and show_vhdl_array_attributes_t :
740
  vhdl_array_attributes_t -> Ppx_deriving_runtime.string =
741
  fun x  -> Format.asprintf "%a" pp_vhdl_array_attributes_t x
742
743 389493d3 Arnaud Dieumegard
(* TODO *)
744 40364f53 Arnaud Dieumegard
and (pp_vhdl_signal_attributes_t :
745
      Format.formatter ->
746
        vhdl_signal_attributes_t -> Ppx_deriving_runtime.unit)
747
  =
748
  ((let open! Ppx_deriving_runtime in
749
      fun fmt  ->
750
        function
751
        | SigAtt a0 ->
752
            (Format.fprintf fmt "(@[<2>SigAtt@ ";
753
             (Format.fprintf fmt "%S") a0;
754
             Format.fprintf fmt "@])"))
755
  [@ocaml.warning "-A"])
756
757
and show_vhdl_signal_attributes_t :
758
  vhdl_signal_attributes_t -> Ppx_deriving_runtime.string =
759
  fun x  -> Format.asprintf "%a" pp_vhdl_signal_attributes_t x
760
761 389493d3 Arnaud Dieumegard
(* TODO *)
762 40364f53 Arnaud Dieumegard
and (pp_vhdl_string_attributes_t :
763
      Format.formatter ->
764
        vhdl_string_attributes_t -> Ppx_deriving_runtime.unit)
765
  =
766
  ((let open! Ppx_deriving_runtime in
767
      fun fmt  ->
768
        function
769
        | StringAtt a0 ->
770
            (Format.fprintf fmt "(@[<2>StringAtt@ ";
771
             (Format.fprintf fmt "%S") a0;
772
             Format.fprintf fmt "@])"))
773
  [@ocaml.warning "-A"])
774
775
and show_vhdl_string_attributes_t :
776
  vhdl_string_attributes_t -> Ppx_deriving_runtime.string =
777
  fun x  -> Format.asprintf "%a" pp_vhdl_string_attributes_t x
778
779 389493d3 Arnaud Dieumegard
(* TODO *)
780 40364f53 Arnaud Dieumegard
and (pp_vhdl_suffix_selection_t :
781
      Format.formatter ->
782
        vhdl_suffix_selection_t -> Ppx_deriving_runtime.unit)
783
  =
784
  ((let open! Ppx_deriving_runtime in
785
      fun fmt  ->
786
        function
787
        | Idx a0 ->
788
            (Format.fprintf fmt "(@[<2>Idx@ ";
789
             (Format.fprintf fmt "%d") a0;
790
             Format.fprintf fmt "@])")
791
        | SuffixRange (a0,a1) ->
792
            (Format.fprintf fmt "(@[<2>SuffixRange (@,";
793
             ((Format.fprintf fmt "%d") a0;
794
              Format.fprintf fmt ",@ ";
795
              (Format.fprintf fmt "%d") a1);
796
             Format.fprintf fmt "@,))@]"))
797
  [@ocaml.warning "-A"])
798
799
and show_vhdl_suffix_selection_t :
800
  vhdl_suffix_selection_t -> Ppx_deriving_runtime.string =
801
  fun x  -> Format.asprintf "%a" pp_vhdl_suffix_selection_t x
802
803
let rec (vhdl_type_t_to_yojson : vhdl_type_t -> Yojson.Safe.json) =
804
  ((let open! Ppx_deriving_yojson_runtime in
805
      function
806
      | Base arg0 ->
807
          `List
808
            [`String "Base";
809
            ((fun (x : Ppx_deriving_runtime.string)  -> `String x)) arg0]
810
      | Range (arg0,arg1,arg2) ->
811
          `List
812
            [`String "Range";
813
            ((function
814
              | None  -> `Null
815
              | Some x ->
816
                  ((fun (x : Ppx_deriving_runtime.string)  -> `String x)) x))
817
              arg0;
818
            ((fun (x : Ppx_deriving_runtime.int)  -> `Int x)) arg1;
819
            ((fun (x : Ppx_deriving_runtime.int)  -> `Int x)) arg2]
820
      | Bit_vector (arg0,arg1) ->
821
          `List
822
            [`String "Bit_vector";
823
            ((fun (x : Ppx_deriving_runtime.int)  -> `Int x)) arg0;
824
            ((fun (x : Ppx_deriving_runtime.int)  -> `Int x)) arg1]
825 248eb65e Arnaud Dieumegard
      | Array arg0 ->
826 40364f53 Arnaud Dieumegard
          `List
827 248eb65e Arnaud Dieumegard
            [`String "ARRAY_TYPE_DEFINITION";
828
            (let fields = []  in
829
             let fields =
830
               ("definition",
831
                 ((fun x  -> vhdl_subtype_indication_t_to_yojson x)
832
                    arg0.definition))
833
               :: fields  in
834
             let fields =
835
               if arg0.const = None
836
               then fields
837
               else
838
                 ("const",
839
                   (((function
840
                      | None  -> `Null
841
                      | Some x ->
842
                          ((fun x  -> vhdl_constraint_t_to_yojson x)) x))
843
                      arg0.const))
844
                 :: fields
845
                in
846
             let fields =
847
               ("indexes",
848
                 ((fun x  ->
849
                     `List (List.map (fun x  -> vhdl_name_t_to_yojson x) x))
850
                    arg0.indexes))
851
               :: fields  in
852
             `Assoc fields)]
853
      | Record arg0 ->
854 40364f53 Arnaud Dieumegard
          `List
855 248eb65e Arnaud Dieumegard
            [`String "RECORD_TYPE_DEFINITION";
856 40364f53 Arnaud Dieumegard
            ((fun x  ->
857
                `List
858
                  (List.map
859 248eb65e Arnaud Dieumegard
                     (fun x  -> vhdl_element_declaration_t_to_yojson x) x)))
860 40364f53 Arnaud Dieumegard
              arg0]
861 248eb65e Arnaud Dieumegard
      | Enumerated arg0 ->
862
          `List
863
            [`String "ENUMERATION_TYPE_DEFINITION";
864
            ((fun x  ->
865
                `List (List.map (fun x  -> vhdl_name_t_to_yojson x) x))) arg0]
866 40364f53 Arnaud Dieumegard
      | Void  -> `List [`String "Void"])
867
  [@ocaml.warning "-A"])
868
869
and (vhdl_type_t_of_yojson :
870
      Yojson.Safe.json -> vhdl_type_t Ppx_deriving_yojson_runtime.error_or)
871
  =
872
  ((let open! Ppx_deriving_yojson_runtime in
873
      function
874
      | `List ((`String "Base")::arg0::[]) ->
875
          ((function
876
            | `String x -> Result.Ok x
877
            | _ -> Result.Error "Vhdl_ast.vhdl_type_t") arg0) >>=
878
            ((fun arg0  -> Result.Ok (Base arg0)))
879
      | `List ((`String "Range")::arg0::arg1::arg2::[]) ->
880
          ((function
881
            | `Int x -> Result.Ok x
882
            | _ -> Result.Error "Vhdl_ast.vhdl_type_t") arg2) >>=
883
            ((fun arg2  ->
884
                ((function
885
                  | `Int x -> Result.Ok x
886
                  | _ -> Result.Error "Vhdl_ast.vhdl_type_t") arg1) >>=
887
                  (fun arg1  ->
888
                     ((function
889
                       | `Null -> Result.Ok None
890
                       | x ->
891
                           ((function
892
                             | `String x -> Result.Ok x
893
                             | _ -> Result.Error "Vhdl_ast.vhdl_type_t") x)
894
                             >>= ((fun x  -> Result.Ok (Some x)))) arg0)
895
                       >>=
896
                       (fun arg0  -> Result.Ok (Range (arg0, arg1, arg2))))))
897
      | `List ((`String "Bit_vector")::arg0::arg1::[]) ->
898
          ((function
899
            | `Int x -> Result.Ok x
900
            | _ -> Result.Error "Vhdl_ast.vhdl_type_t") arg1) >>=
901
            ((fun arg1  ->
902
                ((function
903
                  | `Int x -> Result.Ok x
904
                  | _ -> Result.Error "Vhdl_ast.vhdl_type_t") arg0) >>=
905
                  (fun arg0  -> Result.Ok (Bit_vector (arg0, arg1)))))
906 248eb65e Arnaud Dieumegard
      | `List ((`String "ARRAY_TYPE_DEFINITION")::arg0::[]) ->
907
          ((function
908
            | `Assoc xs ->
909
                let rec loop xs ((arg0,arg1,arg2) as _state) =
910
                  match xs with
911
                  | ("indexes",x)::xs ->
912
                      loop xs
913
                        (((function
914
                           | `List xs ->
915
                               map_bind (fun x  -> vhdl_name_t_of_yojson x)
916
                                 [] xs
917
                           | _ -> Result.Error "Vhdl_ast.vhdl_type_t.indexes")
918
                            x), arg1, arg2)
919
                  | ("const",x)::xs ->
920
                      loop xs
921
                        (arg0,
922
                          ((function
923
                            | `Null -> Result.Ok None
924
                            | x ->
925
                                ((fun x  -> vhdl_constraint_t_of_yojson x) x)
926
                                  >>= ((fun x  -> Result.Ok (Some x)))) x),
927
                          arg2)
928
                  | ("definition",x)::xs ->
929
                      loop xs
930
                        (arg0, arg1,
931
                          ((fun x  -> vhdl_subtype_indication_t_of_yojson x)
932
                             x))
933
                  | [] ->
934
                      arg2 >>=
935
                        ((fun arg2  ->
936
                            arg1 >>=
937
                              (fun arg1  ->
938
                                 arg0 >>=
939
                                   (fun arg0  ->
940
                                      Result.Ok
941
                                        (Array
942
                                           {
943
                                             indexes = arg0;
944
                                             const = arg1;
945
                                             definition = arg2
946
                                           })))))
947
                  | _::xs -> loop xs _state  in
948
                loop xs
949
                  ((Result.Error "Vhdl_ast.vhdl_type_t.indexes"),
950
                    (Result.Ok None),
951
                    (Result.Error "Vhdl_ast.vhdl_type_t.definition"))
952
            | _ -> Result.Error "Vhdl_ast.vhdl_type_t")) arg0
953
      | `List ((`String "RECORD_TYPE_DEFINITION")::arg0::[]) ->
954 40364f53 Arnaud Dieumegard
          ((function
955
            | `List xs ->
956 248eb65e Arnaud Dieumegard
                map_bind (fun x  -> vhdl_element_declaration_t_of_yojson x)
957
                  [] xs
958
            | _ -> Result.Error "Vhdl_ast.vhdl_type_t") arg0) >>=
959
            ((fun arg0  -> Result.Ok (Record arg0)))
960
      | `List ((`String "ENUMERATION_TYPE_DEFINITION")::arg0::[]) ->
961
          ((function
962
            | `List xs -> map_bind (fun x  -> vhdl_name_t_of_yojson x) [] xs
963 40364f53 Arnaud Dieumegard
            | _ -> Result.Error "Vhdl_ast.vhdl_type_t") arg0) >>=
964
            ((fun arg0  -> Result.Ok (Enumerated arg0)))
965
      | `List ((`String "Void")::[]) -> Result.Ok Void
966
      | _ -> Result.Error "Vhdl_ast.vhdl_type_t")
967
  [@ocaml.warning "-A"])
968
969 248eb65e Arnaud Dieumegard
and (vhdl_element_declaration_t_to_yojson :
970
      vhdl_element_declaration_t -> Yojson.Safe.json)
971
  =
972
  ((let open! Ppx_deriving_yojson_runtime in
973
      fun x  ->
974
        let fields = []  in
975
        let fields =
976
          ("definition",
977
            ((fun x  -> vhdl_subtype_indication_t_to_yojson x) x.definition))
978
          :: fields  in
979
        let fields =
980
          ("names",
981
            ((fun x  ->
982
                `List (List.map (fun x  -> vhdl_name_t_to_yojson x) x))
983
               x.names))
984
          :: fields  in
985
        `Assoc fields)
986
  [@ocaml.warning "-A"])
987
988
and (vhdl_element_declaration_t_of_yojson :
989
      Yojson.Safe.json ->
990
        vhdl_element_declaration_t Ppx_deriving_yojson_runtime.error_or)
991
  =
992
  ((let open! Ppx_deriving_yojson_runtime in
993
      function
994
      | `Assoc xs ->
995
          let rec loop xs ((arg0,arg1) as _state) =
996
            match xs with
997
            | ("names",x)::xs ->
998
                loop xs
999
                  (((function
1000
                     | `List xs ->
1001
                         map_bind (fun x  -> vhdl_name_t_of_yojson x) [] xs
1002
                     | _ ->
1003
                         Result.Error
1004
                           "Vhdl_ast.vhdl_element_declaration_t.names") x),
1005
                    arg1)
1006
            | ("definition",x)::xs ->
1007
                loop xs
1008
                  (arg0,
1009
                    ((fun x  -> vhdl_subtype_indication_t_of_yojson x) x))
1010
            | [] ->
1011
                arg1 >>=
1012
                  ((fun arg1  ->
1013
                      arg0 >>=
1014
                        (fun arg0  ->
1015
                           Result.Ok { names = arg0; definition = arg1 })))
1016
            | _::xs -> loop xs _state  in
1017
          loop xs
1018
            ((Result.Error "Vhdl_ast.vhdl_element_declaration_t.names"),
1019
              (Result.Error "Vhdl_ast.vhdl_element_declaration_t.definition"))
1020
      | _ -> Result.Error "Vhdl_ast.vhdl_element_declaration_t")
1021
  [@ocaml.warning "-A"])
1022
1023 40364f53 Arnaud Dieumegard
and (vhdl_subtype_indication_t_to_yojson :
1024
      vhdl_subtype_indication_t -> Yojson.Safe.json)
1025
  =
1026
  ((let open! Ppx_deriving_yojson_runtime in
1027
      fun x  ->
1028
        let fields = []  in
1029
        let fields =
1030
          if x.const = NoConstraint
1031
          then fields
1032
          else
1033
            ("const", (((fun x  -> vhdl_constraint_t_to_yojson x)) x.const))
1034
            :: fields
1035
           in
1036
        let fields =
1037
          if x.functionName = NoName
1038
          then fields
1039
          else
1040
            ("functionName",
1041
              (((fun x  -> vhdl_name_t_to_yojson x)) x.functionName))
1042
            :: fields
1043
           in
1044
        let fields =
1045
          if x.name = NoName
1046
          then fields
1047
          else ("name", (((fun x  -> vhdl_name_t_to_yojson x)) x.name)) ::
1048
            fields
1049
           in
1050
        `Assoc fields)
1051
  [@ocaml.warning "-A"])
1052
1053
and (vhdl_subtype_indication_t_of_yojson :
1054
      Yojson.Safe.json ->
1055
        vhdl_subtype_indication_t Ppx_deriving_yojson_runtime.error_or)
1056
  =
1057
  ((let open! Ppx_deriving_yojson_runtime in
1058
      function
1059
      | `Assoc xs ->
1060
          let rec loop xs ((arg0,arg1,arg2) as _state) =
1061
            match xs with
1062
            | ("name",x)::xs ->
1063
                loop xs (((fun x  -> vhdl_name_t_of_yojson x) x), arg1, arg2)
1064
            | ("functionName",x)::xs ->
1065
                loop xs (arg0, ((fun x  -> vhdl_name_t_of_yojson x) x), arg2)
1066
            | ("const",x)::xs ->
1067
                loop xs
1068
                  (arg0, arg1, ((fun x  -> vhdl_constraint_t_of_yojson x) x))
1069
            | [] ->
1070
                arg2 >>=
1071
                  ((fun arg2  ->
1072
                      arg1 >>=
1073
                        (fun arg1  ->
1074
                           arg0 >>=
1075
                             (fun arg0  ->
1076
                                Result.Ok
1077
                                  {
1078
                                    name = arg0;
1079
                                    functionName = arg1;
1080
                                    const = arg2
1081
                                  }))))
1082
            | _::xs -> loop xs _state  in
1083
          loop xs
1084
            ((Result.Ok NoName), (Result.Ok NoName),
1085
              (Result.Ok NoConstraint))
1086
      | _ -> Result.Error "Vhdl_ast.vhdl_subtype_indication_t")
1087
  [@ocaml.warning "-A"])
1088
1089
and (vhdl_discrete_range_t_to_yojson :
1090
      vhdl_discrete_range_t -> Yojson.Safe.json)
1091
  =
1092
  ((let open! Ppx_deriving_yojson_runtime in
1093
      function
1094
      | SubDiscreteRange arg0 ->
1095
          `List
1096
            [`String "SUB_DISCRETE_RANGE";
1097
            ((fun x  -> vhdl_subtype_indication_t_to_yojson x)) arg0]
1098
      | NamedRange arg0 ->
1099
          `List
1100
            [`String "NAMED_RANGE";
1101
            ((fun x  -> vhdl_name_t_to_yojson x)) arg0]
1102
      | DirectedRange arg0 ->
1103
          `List
1104
            [`String "RANGE_WITH_DIRECTION";
1105
            (let fields = []  in
1106
             let fields =
1107
               ("_to", ((fun x  -> vhdl_expr_t_to_yojson x) arg0._to)) ::
1108
               fields  in
1109
             let fields =
1110
               ("from", ((fun x  -> vhdl_expr_t_to_yojson x) arg0.from)) ::
1111
               fields  in
1112
             let fields =
1113
               ("direction",
1114
                 ((fun (x : Ppx_deriving_runtime.string)  -> `String x)
1115
                    arg0.direction))
1116
               :: fields  in
1117
             `Assoc fields)])
1118
  [@ocaml.warning "-A"])
1119
1120
and (vhdl_discrete_range_t_of_yojson :
1121
      Yojson.Safe.json ->
1122
        vhdl_discrete_range_t Ppx_deriving_yojson_runtime.error_or)
1123
  =
1124
  ((let open! Ppx_deriving_yojson_runtime in
1125
      function
1126
      | `List ((`String "SUB_DISCRETE_RANGE")::arg0::[]) ->
1127
          ((fun x  -> vhdl_subtype_indication_t_of_yojson x) arg0) >>=
1128
            ((fun arg0  -> Result.Ok (SubDiscreteRange arg0)))
1129
      | `List ((`String "NAMED_RANGE")::arg0::[]) ->
1130
          ((fun x  -> vhdl_name_t_of_yojson x) arg0) >>=
1131
            ((fun arg0  -> Result.Ok (NamedRange arg0)))
1132
      | `List ((`String "RANGE_WITH_DIRECTION")::arg0::[]) ->
1133
          ((function
1134
            | `Assoc xs ->
1135
                let rec loop xs ((arg0,arg1,arg2) as _state) =
1136
                  match xs with
1137
                  | ("direction",x)::xs ->
1138
                      loop xs
1139
                        (((function
1140
                           | `String x -> Result.Ok x
1141
                           | _ ->
1142
                               Result.Error
1143
                                 "Vhdl_ast.vhdl_discrete_range_t.direction")
1144
                            x), arg1, arg2)
1145
                  | ("from",x)::xs ->
1146
                      loop xs
1147
                        (arg0, ((fun x  -> vhdl_expr_t_of_yojson x) x), arg2)
1148
                  | ("_to",x)::xs ->
1149
                      loop xs
1150
                        (arg0, arg1, ((fun x  -> vhdl_expr_t_of_yojson x) x))
1151
                  | [] ->
1152
                      arg2 >>=
1153
                        ((fun arg2  ->
1154
                            arg1 >>=
1155
                              (fun arg1  ->
1156
                                 arg0 >>=
1157
                                   (fun arg0  ->
1158
                                      Result.Ok
1159
                                        (DirectedRange
1160
                                           {
1161
                                             direction = arg0;
1162
                                             from = arg1;
1163
                                             _to = arg2
1164
                                           })))))
1165
                  | _::xs -> loop xs _state  in
1166
                loop xs
1167
                  ((Result.Error "Vhdl_ast.vhdl_discrete_range_t.direction"),
1168
                    (Result.Error "Vhdl_ast.vhdl_discrete_range_t.from"),
1169
                    (Result.Error "Vhdl_ast.vhdl_discrete_range_t._to"))
1170
            | _ -> Result.Error "Vhdl_ast.vhdl_discrete_range_t")) arg0
1171
      | _ -> Result.Error "Vhdl_ast.vhdl_discrete_range_t")
1172
  [@ocaml.warning "-A"])
1173
1174
and (vhdl_constraint_t_to_yojson : vhdl_constraint_t -> Yojson.Safe.json) =
1175
  ((let open! Ppx_deriving_yojson_runtime in
1176
      function
1177
      | RefConstraint arg0 ->
1178
          `List
1179
            [`String "RefConstraint";
1180
            (let fields = []  in
1181
             let fields =
1182
               ("ref_name",
1183
                 ((fun x  -> vhdl_name_t_to_yojson x) arg0.ref_name))
1184
               :: fields  in
1185
             `Assoc fields)]
1186
      | RangeConstraint arg0 ->
1187
          `List
1188
            [`String "RANGE_CONSTRAINT";
1189
            (let fields = []  in
1190
             let fields =
1191
               ("range",
1192
                 ((fun x  -> vhdl_discrete_range_t_to_yojson x) arg0.range))
1193
               :: fields  in
1194
             `Assoc fields)]
1195
      | IndexConstraint arg0 ->
1196
          `List
1197
            [`String "INDEX_CONSTRAINT";
1198
            (let fields = []  in
1199
             let fields =
1200
               ("ranges",
1201
                 ((fun x  ->
1202
                     `List
1203
                       (List.map
1204
                          (fun x  -> vhdl_discrete_range_t_to_yojson x) x))
1205
                    arg0.ranges))
1206
               :: fields  in
1207
             `Assoc fields)]
1208
      | ArrayConstraint arg0 ->
1209
          `List
1210
            [`String "ARRAY_CONSTRAINT";
1211
            (let fields = []  in
1212
             let fields =
1213
               ("sub", ((fun x  -> vhdl_constraint_t_to_yojson x) arg0.sub))
1214
               :: fields  in
1215
             let fields =
1216
               ("ranges",
1217
                 ((fun x  ->
1218
                     `List
1219
                       (List.map
1220
                          (fun x  -> vhdl_discrete_range_t_to_yojson x) x))
1221
                    arg0.ranges))
1222
               :: fields  in
1223
             `Assoc fields)]
1224
      | RecordConstraint  -> `List [`String "RecordConstraint"]
1225
      | NoConstraint  -> `List [`String "NoConstraint"])
1226
  [@ocaml.warning "-A"])
1227
1228
and (vhdl_constraint_t_of_yojson :
1229
      Yojson.Safe.json ->
1230
        vhdl_constraint_t Ppx_deriving_yojson_runtime.error_or)
1231
  =
1232
  ((let open! Ppx_deriving_yojson_runtime in
1233
      function
1234
      | `List ((`String "RefConstraint")::arg0::[]) ->
1235
          ((function
1236
            | `Assoc xs ->
1237
                let rec loop xs (arg0 as _state) =
1238
                  match xs with
1239
                  | ("ref_name",x)::xs ->
1240
                      loop xs ((fun x  -> vhdl_name_t_of_yojson x) x)
1241
                  | [] ->
1242
                      arg0 >>=
1243
                        ((fun arg0  ->
1244
                            Result.Ok (RefConstraint { ref_name = arg0 })))
1245
                  | _::xs -> loop xs _state  in
1246
                loop xs (Result.Error "Vhdl_ast.vhdl_constraint_t.ref_name")
1247
            | _ -> Result.Error "Vhdl_ast.vhdl_constraint_t")) arg0
1248
      | `List ((`String "RANGE_CONSTRAINT")::arg0::[]) ->
1249
          ((function
1250
            | `Assoc xs ->
1251
                let rec loop xs (arg0 as _state) =
1252
                  match xs with
1253
                  | ("range",x)::xs ->
1254
                      loop xs
1255
                        ((fun x  -> vhdl_discrete_range_t_of_yojson x) x)
1256
                  | [] ->
1257
                      arg0 >>=
1258
                        ((fun arg0  ->
1259
                            Result.Ok (RangeConstraint { range = arg0 })))
1260
                  | _::xs -> loop xs _state  in
1261
                loop xs (Result.Error "Vhdl_ast.vhdl_constraint_t.range")
1262
            | _ -> Result.Error "Vhdl_ast.vhdl_constraint_t")) arg0
1263
      | `List ((`String "INDEX_CONSTRAINT")::arg0::[]) ->
1264
          ((function
1265
            | `Assoc xs ->
1266
                let rec loop xs (arg0 as _state) =
1267
                  match xs with
1268
                  | ("ranges",x)::xs ->
1269
                      loop xs
1270
                        ((function
1271
                          | `List xs ->
1272
                              map_bind
1273
                                (fun x  -> vhdl_discrete_range_t_of_yojson x)
1274
                                [] xs
1275
                          | _ ->
1276
                              Result.Error
1277
                                "Vhdl_ast.vhdl_constraint_t.ranges") x)
1278
                  | [] ->
1279
                      arg0 >>=
1280
                        ((fun arg0  ->
1281
                            Result.Ok (IndexConstraint { ranges = arg0 })))
1282
                  | _::xs -> loop xs _state  in
1283
                loop xs (Result.Error "Vhdl_ast.vhdl_constraint_t.ranges")
1284
            | _ -> Result.Error "Vhdl_ast.vhdl_constraint_t")) arg0
1285
      | `List ((`String "ARRAY_CONSTRAINT")::arg0::[]) ->
1286
          ((function
1287
            | `Assoc xs ->
1288
                let rec loop xs ((arg0,arg1) as _state) =
1289
                  match xs with
1290
                  | ("ranges",x)::xs ->
1291
                      loop xs
1292
                        (((function
1293
                           | `List xs ->
1294
                               map_bind
1295
                                 (fun x  -> vhdl_discrete_range_t_of_yojson x)
1296
                                 [] xs
1297
                           | _ ->
1298
                               Result.Error
1299
                                 "Vhdl_ast.vhdl_constraint_t.ranges") x),
1300
                          arg1)
1301
                  | ("sub",x)::xs ->
1302
                      loop xs
1303
                        (arg0, ((fun x  -> vhdl_constraint_t_of_yojson x) x))
1304
                  | [] ->
1305
                      arg1 >>=
1306
                        ((fun arg1  ->
1307
                            arg0 >>=
1308
                              (fun arg0  ->
1309
                                 Result.Ok
1310
                                   (ArrayConstraint
1311
                                      { ranges = arg0; sub = arg1 }))))
1312
                  | _::xs -> loop xs _state  in
1313
                loop xs
1314
                  ((Result.Error "Vhdl_ast.vhdl_constraint_t.ranges"),
1315
                    (Result.Error "Vhdl_ast.vhdl_constraint_t.sub"))
1316
            | _ -> Result.Error "Vhdl_ast.vhdl_constraint_t")) arg0
1317
      | `List ((`String "RecordConstraint")::[]) ->
1318
          Result.Ok RecordConstraint
1319
      | `List ((`String "NoConstraint")::[]) -> Result.Ok NoConstraint
1320
      | _ -> Result.Error "Vhdl_ast.vhdl_constraint_t")
1321
  [@ocaml.warning "-A"])
1322
1323
and (vhdl_definition_t_to_yojson : vhdl_definition_t -> Yojson.Safe.json) =
1324
  ((let open! Ppx_deriving_yojson_runtime in
1325
      function
1326
      | Type arg0 ->
1327
          `List
1328
            [`String "TYPE_DECLARATION";
1329
            (let fields = []  in
1330
             let fields =
1331
               ("definition",
1332
                 ((fun x  -> vhdl_type_t_to_yojson x) arg0.definition))
1333
               :: fields  in
1334
             let fields =
1335
               ("name", ((fun x  -> vhdl_name_t_to_yojson x) arg0.name)) ::
1336
               fields  in
1337
             `Assoc fields)]
1338
      | Subtype arg0 ->
1339
          `List
1340
            [`String "SUBTYPE_DECLARATION";
1341
            (let fields = []  in
1342
             let fields =
1343
               ("typ",
1344
                 ((fun x  -> vhdl_subtype_indication_t_to_yojson x) arg0.typ))
1345
               :: fields  in
1346
             let fields =
1347
               ("name", ((fun x  -> vhdl_name_t_to_yojson x) arg0.name)) ::
1348
               fields  in
1349
             `Assoc fields)])
1350
  [@ocaml.warning "-A"])
1351
1352
and (vhdl_definition_t_of_yojson :
1353
      Yojson.Safe.json ->
1354
        vhdl_definition_t Ppx_deriving_yojson_runtime.error_or)
1355
  =
1356
  ((let open! Ppx_deriving_yojson_runtime in
1357
      function
1358
      | `List ((`String "TYPE_DECLARATION")::arg0::[]) ->
1359
          ((function
1360
            | `Assoc xs ->
1361
                let rec loop xs ((arg0,arg1) as _state) =
1362
                  match xs with
1363
                  | ("name",x)::xs ->
1364
                      loop xs (((fun x  -> vhdl_name_t_of_yojson x) x), arg1)
1365
                  | ("definition",x)::xs ->
1366
                      loop xs (arg0, ((fun x  -> vhdl_type_t_of_yojson x) x))
1367
                  | [] ->
1368
                      arg1 >>=
1369
                        ((fun arg1  ->
1370
                            arg0 >>=
1371
                              (fun arg0  ->
1372
                                 Result.Ok
1373
                                   (Type { name = arg0; definition = arg1 }))))
1374
                  | _::xs -> loop xs _state  in
1375
                loop xs
1376
                  ((Result.Error "Vhdl_ast.vhdl_definition_t.name"),
1377
                    (Result.Error "Vhdl_ast.vhdl_definition_t.definition"))
1378
            | _ -> Result.Error "Vhdl_ast.vhdl_definition_t")) arg0
1379
      | `List ((`String "SUBTYPE_DECLARATION")::arg0::[]) ->
1380
          ((function
1381
            | `Assoc xs ->
1382
                let rec loop xs ((arg0,arg1) as _state) =
1383
                  match xs with
1384
                  | ("name",x)::xs ->
1385
                      loop xs (((fun x  -> vhdl_name_t_of_yojson x) x), arg1)
1386
                  | ("typ",x)::xs ->
1387
                      loop xs
1388
                        (arg0,
1389
                          ((fun x  -> vhdl_subtype_indication_t_of_yojson x)
1390
                             x))
1391
                  | [] ->
1392
                      arg1 >>=
1393
                        ((fun arg1  ->
1394
                            arg0 >>=
1395
                              (fun arg0  ->
1396
                                 Result.Ok
1397
                                   (Subtype { name = arg0; typ = arg1 }))))
1398
                  | _::xs -> loop xs _state  in
1399
                loop xs
1400
                  ((Result.Error "Vhdl_ast.vhdl_definition_t.name"),
1401
                    (Result.Error "Vhdl_ast.vhdl_definition_t.typ"))
1402
            | _ -> Result.Error "Vhdl_ast.vhdl_definition_t")) arg0
1403
      | _ -> Result.Error "Vhdl_ast.vhdl_definition_t")
1404
  [@ocaml.warning "-A"])
1405
1406
and (vhdl_expr_t_to_yojson : vhdl_expr_t -> Yojson.Safe.json) =
1407
  ((let open! Ppx_deriving_yojson_runtime in
1408
      function
1409
      | Call arg0 ->
1410
          `List [`String "CALL"; ((fun x  -> vhdl_name_t_to_yojson x)) arg0]
1411
      | Cst arg0 ->
1412
          `List
1413
            [`String "CONSTANT_VALUE";
1414 ab6312e7 Arnaud Dieumegard
            (let fields = []  in
1415
             let fields =
1416
               if arg0.unit_name = None
1417
               then fields
1418
               else
1419
                 ("unit_name",
1420
                   (((function
1421
                      | None  -> `Null
1422
                      | Some x -> ((fun x  -> vhdl_name_t_to_yojson x)) x))
1423
                      arg0.unit_name))
1424
                 :: fields
1425
                in
1426
             let fields =
1427
               ("value", ((fun x  -> vhdl_cst_val_t_to_yojson x) arg0.value))
1428
               :: fields  in
1429
             `Assoc fields)]
1430 40364f53 Arnaud Dieumegard
      | Op arg0 ->
1431
          `List
1432
            [`String "EXPRESSION";
1433
            (let fields = []  in
1434
             let fields =
1435
               if arg0.args = []
1436
               then fields
1437
               else
1438
                 ("args",
1439
                   (((fun x  ->
1440
                        `List
1441
                          (List.map (fun x  -> vhdl_expr_t_to_yojson x) x)))
1442
                      arg0.args))
1443
                 :: fields
1444
                in
1445
             let fields =
1446
               if arg0.id = ""
1447
               then fields
1448
               else
1449
                 ("id",
1450
                   (((fun (x : Ppx_deriving_runtime.string)  -> `String x))
1451
                      arg0.id))
1452
                 :: fields
1453
                in
1454
             `Assoc fields)]
1455
      | IsNull  -> `List [`String "IsNull"]
1456
      | Time arg0 ->
1457
          `List
1458
            [`String "Time";
1459
            (let fields = []  in
1460
             let fields =
1461
               if arg0.phy_unit = ""
1462
               then fields
1463
               else
1464
                 ("phy_unit",
1465
                   (((fun (x : Ppx_deriving_runtime.string)  -> `String x))
1466
                      arg0.phy_unit))
1467
                 :: fields
1468
                in
1469
             let fields =
1470
               ("value",
1471
                 ((fun (x : Ppx_deriving_runtime.int)  -> `Int x) arg0.value))
1472
               :: fields  in
1473
             `Assoc fields)]
1474
      | Sig arg0 ->
1475
          `List
1476
            [`String "Sig";
1477
            (let fields = []  in
1478
             let fields =
1479
               ("att",
1480
                 ((function
1481
                   | None  -> `Null
1482
                   | Some x ->
1483
                       ((fun x  -> vhdl_signal_attributes_t_to_yojson x)) x)
1484
                    arg0.att))
1485
               :: fields  in
1486
             let fields =
1487
               ("name", ((fun x  -> vhdl_name_t_to_yojson x) arg0.name)) ::
1488
               fields  in
1489
             `Assoc fields)]
1490
      | SuffixMod arg0 ->
1491
          `List
1492
            [`String "SuffixMod";
1493
            (let fields = []  in
1494
             let fields =
1495
               ("selection",
1496
                 ((fun x  -> vhdl_suffix_selection_t_to_yojson x)
1497
                    arg0.selection))
1498
               :: fields  in
1499
             let fields =
1500
               ("expr", ((fun x  -> vhdl_expr_t_to_yojson x) arg0.expr)) ::
1501
               fields  in
1502
             `Assoc fields)]
1503
      | Aggregate arg0 ->
1504
          `List
1505
            [`String "AGGREGATE";
1506
            (let fields = []  in
1507
             let fields =
1508
               ("elems",
1509
                 ((fun x  ->
1510
                     `List
1511
                       (List.map (fun x  -> vhdl_element_assoc_t_to_yojson x)
1512
                          x)) arg0.elems))
1513
               :: fields  in
1514
             `Assoc fields)]
1515
      | Others  -> `List [`String "OTHERS"])
1516
  [@ocaml.warning "-A"])
1517
1518
and (vhdl_expr_t_of_yojson :
1519
      Yojson.Safe.json -> vhdl_expr_t Ppx_deriving_yojson_runtime.error_or)
1520
  =
1521
  ((let open! Ppx_deriving_yojson_runtime in
1522
      function
1523
      | `List ((`String "CALL")::arg0::[]) ->
1524
          ((fun x  -> vhdl_name_t_of_yojson x) arg0) >>=
1525
            ((fun arg0  -> Result.Ok (Call arg0)))
1526
      | `List ((`String "CONSTANT_VALUE")::arg0::[]) ->
1527 ab6312e7 Arnaud Dieumegard
          ((function
1528
            | `Assoc xs ->
1529
                let rec loop xs ((arg0,arg1) as _state) =
1530
                  match xs with
1531
                  | ("value",x)::xs ->
1532
                      loop xs
1533
                        (((fun x  -> vhdl_cst_val_t_of_yojson x) x), arg1)
1534
                  | ("unit_name",x)::xs ->
1535
                      loop xs
1536
                        (arg0,
1537
                          ((function
1538
                            | `Null -> Result.Ok None
1539
                            | x ->
1540
                                ((fun x  -> vhdl_name_t_of_yojson x) x) >>=
1541
                                  ((fun x  -> Result.Ok (Some x)))) x))
1542
                  | [] ->
1543
                      arg1 >>=
1544
                        ((fun arg1  ->
1545
                            arg0 >>=
1546
                              (fun arg0  ->
1547
                                 Result.Ok
1548
                                   (Cst { value = arg0; unit_name = arg1 }))))
1549
                  | _::xs -> loop xs _state  in
1550
                loop xs
1551
                  ((Result.Error "Vhdl_ast.vhdl_expr_t.value"),
1552
                    (Result.Ok None))
1553
            | _ -> Result.Error "Vhdl_ast.vhdl_expr_t")) arg0
1554 40364f53 Arnaud Dieumegard
      | `List ((`String "EXPRESSION")::arg0::[]) ->
1555
          ((function
1556
            | `Assoc xs ->
1557
                let rec loop xs ((arg0,arg1) as _state) =
1558
                  match xs with
1559
                  | ("id",x)::xs ->
1560
                      loop xs
1561
                        (((function
1562
                           | `String x -> Result.Ok x
1563
                           | _ -> Result.Error "Vhdl_ast.vhdl_expr_t.id") x),
1564
                          arg1)
1565
                  | ("args",x)::xs ->
1566
                      loop xs
1567
                        (arg0,
1568
                          ((function
1569
                            | `List xs ->
1570
                                map_bind (fun x  -> vhdl_expr_t_of_yojson x)
1571
                                  [] xs
1572
                            | _ -> Result.Error "Vhdl_ast.vhdl_expr_t.args")
1573
                             x))
1574
                  | [] ->
1575
                      arg1 >>=
1576
                        ((fun arg1  ->
1577
                            arg0 >>=
1578
                              (fun arg0  ->
1579
                                 Result.Ok (Op { id = arg0; args = arg1 }))))
1580
                  | _::xs -> loop xs _state  in
1581
                loop xs ((Result.Ok ""), (Result.Ok []))
1582
            | _ -> Result.Error "Vhdl_ast.vhdl_expr_t")) arg0
1583
      | `List ((`String "IsNull")::[]) -> Result.Ok IsNull
1584
      | `List ((`String "Time")::arg0::[]) ->
1585
          ((function
1586
            | `Assoc xs ->
1587
                let rec loop xs ((arg0,arg1) as _state) =
1588
                  match xs with
1589
                  | ("value",x)::xs ->
1590
                      loop xs
1591
                        (((function
1592
                           | `Int x -> Result.Ok x
1593
                           | _ -> Result.Error "Vhdl_ast.vhdl_expr_t.value")
1594
                            x), arg1)
1595
                  | ("phy_unit",x)::xs ->
1596
                      loop xs
1597
                        (arg0,
1598
                          ((function
1599
                            | `String x -> Result.Ok x
1600
                            | _ ->
1601
                                Result.Error "Vhdl_ast.vhdl_expr_t.phy_unit")
1602
                             x))
1603
                  | [] ->
1604
                      arg1 >>=
1605
                        ((fun arg1  ->
1606
                            arg0 >>=
1607
                              (fun arg0  ->
1608
                                 Result.Ok
1609
                                   (Time { value = arg0; phy_unit = arg1 }))))
1610
                  | _::xs -> loop xs _state  in
1611
                loop xs
1612
                  ((Result.Error "Vhdl_ast.vhdl_expr_t.value"),
1613
                    (Result.Ok ""))
1614
            | _ -> Result.Error "Vhdl_ast.vhdl_expr_t")) arg0
1615
      | `List ((`String "Sig")::arg0::[]) ->
1616
          ((function
1617
            | `Assoc xs ->
1618
                let rec loop xs ((arg0,arg1) as _state) =
1619
                  match xs with
1620
                  | ("name",x)::xs ->
1621
                      loop xs (((fun x  -> vhdl_name_t_of_yojson x) x), arg1)
1622
                  | ("att",x)::xs ->
1623
                      loop xs
1624
                        (arg0,
1625
                          ((function
1626
                            | `Null -> Result.Ok None
1627
                            | x ->
1628
                                ((fun x  ->
1629
                                    vhdl_signal_attributes_t_of_yojson x) x)
1630
                                  >>= ((fun x  -> Result.Ok (Some x)))) x))
1631
                  | [] ->
1632
                      arg1 >>=
1633
                        ((fun arg1  ->
1634
                            arg0 >>=
1635
                              (fun arg0  ->
1636
                                 Result.Ok (Sig { name = arg0; att = arg1 }))))
1637
                  | _::xs -> loop xs _state  in
1638
                loop xs
1639
                  ((Result.Error "Vhdl_ast.vhdl_expr_t.name"),
1640
                    (Result.Error "Vhdl_ast.vhdl_expr_t.att"))
1641
            | _ -> Result.Error "Vhdl_ast.vhdl_expr_t")) arg0
1642
      | `List ((`String "SuffixMod")::arg0::[]) ->
1643
          ((function
1644
            | `Assoc xs ->
1645
                let rec loop xs ((arg0,arg1) as _state) =
1646
                  match xs with
1647
                  | ("expr",x)::xs ->
1648
                      loop xs (((fun x  -> vhdl_expr_t_of_yojson x) x), arg1)
1649
                  | ("selection",x)::xs ->
1650
                      loop xs
1651
                        (arg0,
1652
                          ((fun x  -> vhdl_suffix_selection_t_of_yojson x) x))
1653
                  | [] ->
1654
                      arg1 >>=
1655
                        ((fun arg1  ->
1656
                            arg0 >>=
1657
                              (fun arg0  ->
1658
                                 Result.Ok
1659
                                   (SuffixMod
1660
                                      { expr = arg0; selection = arg1 }))))
1661
                  | _::xs -> loop xs _state  in
1662
                loop xs
1663
                  ((Result.Error "Vhdl_ast.vhdl_expr_t.expr"),
1664
                    (Result.Error "Vhdl_ast.vhdl_expr_t.selection"))
1665
            | _ -> Result.Error "Vhdl_ast.vhdl_expr_t")) arg0
1666
      | `List ((`String "AGGREGATE")::arg0::[]) ->
1667
          ((function
1668
            | `Assoc xs ->
1669
                let rec loop xs (arg0 as _state) =
1670
                  match xs with
1671
                  | ("elems",x)::xs ->
1672
                      loop xs
1673
                        ((function
1674
                          | `List xs ->
1675
                              map_bind
1676
                                (fun x  -> vhdl_element_assoc_t_of_yojson x)
1677
                                [] xs
1678
                          | _ -> Result.Error "Vhdl_ast.vhdl_expr_t.elems") x)
1679
                  | [] ->
1680
                      arg0 >>=
1681
                        ((fun arg0  -> Result.Ok (Aggregate { elems = arg0 })))
1682
                  | _::xs -> loop xs _state  in
1683
                loop xs (Result.Error "Vhdl_ast.vhdl_expr_t.elems")
1684
            | _ -> Result.Error "Vhdl_ast.vhdl_expr_t")) arg0
1685
      | `List ((`String "OTHERS")::[]) -> Result.Ok Others
1686
      | _ -> Result.Error "Vhdl_ast.vhdl_expr_t")
1687
  [@ocaml.warning "-A"])
1688
1689
and (vhdl_name_t_to_yojson : vhdl_name_t -> Yojson.Safe.json) =
1690
  ((let open! Ppx_deriving_yojson_runtime in
1691
      function
1692
      | Simple arg0 ->
1693
          `List
1694
            [`String "SIMPLE_NAME";
1695
            ((fun (x : Ppx_deriving_runtime.string)  -> `String x)) arg0]
1696
      | Identifier arg0 ->
1697
          `List
1698
            [`String "IDENTIFIER";
1699
            ((fun (x : Ppx_deriving_runtime.string)  -> `String x)) arg0]
1700
      | Selected arg0 ->
1701
          `List
1702
            [`String "SELECTED_NAME";
1703
            ((fun x  ->
1704
                `List (List.map (fun x  -> vhdl_name_t_to_yojson x) x))) arg0]
1705
      | Index arg0 ->
1706
          `List
1707
            [`String "INDEXED_NAME";
1708
            (let fields = []  in
1709
             let fields =
1710
               ("exprs",
1711
                 ((fun x  ->
1712
                     `List (List.map (fun x  -> vhdl_expr_t_to_yojson x) x))
1713
                    arg0.exprs))
1714
               :: fields  in
1715
             let fields =
1716
               ("id", ((fun x  -> vhdl_name_t_to_yojson x) arg0.id)) ::
1717
               fields  in
1718
             `Assoc fields)]
1719
      | Slice arg0 ->
1720
          `List
1721
            [`String "SLICE_NAME";
1722
            (let fields = []  in
1723
             let fields =
1724
               ("range",
1725
                 ((fun x  -> vhdl_discrete_range_t_to_yojson x) arg0.range))
1726
               :: fields  in
1727
             let fields =
1728
               ("id", ((fun x  -> vhdl_name_t_to_yojson x) arg0.id)) ::
1729
               fields  in
1730
             `Assoc fields)]
1731
      | Attribute arg0 ->
1732
          `List
1733
            [`String "ATTRIBUTE_NAME";
1734
            (let fields = []  in
1735
             let fields =
1736
               if arg0.expr = IsNull
1737
               then fields
1738
               else
1739
                 ("expr", (((fun x  -> vhdl_expr_t_to_yojson x)) arg0.expr))
1740
                 :: fields
1741
                in
1742
             let fields =
1743
               ("designator",
1744
                 ((fun x  -> vhdl_name_t_to_yojson x) arg0.designator))
1745
               :: fields  in
1746
             let fields =
1747
               ("id", ((fun x  -> vhdl_name_t_to_yojson x) arg0.id)) ::
1748
               fields  in
1749
             `Assoc fields)]
1750
      | Function arg0 ->
1751
          `List
1752
            [`String "FUNCTION_CALL";
1753
            (let fields = []  in
1754
             let fields =
1755
               ("assoc_list",
1756
                 ((fun x  ->
1757
                     `List
1758
                       (List.map (fun x  -> vhdl_assoc_element_t_to_yojson x)
1759
                          x)) arg0.assoc_list))
1760
               :: fields  in
1761
             let fields =
1762
               ("id", ((fun x  -> vhdl_name_t_to_yojson x) arg0.id)) ::
1763
               fields  in
1764
             `Assoc fields)]
1765
      | NoName  -> `List [`String "NoName"])
1766
  [@ocaml.warning "-A"])
1767
1768
and (vhdl_name_t_of_yojson :
1769
      Yojson.Safe.json -> vhdl_name_t Ppx_deriving_yojson_runtime.error_or)
1770
  =
1771
  ((let open! Ppx_deriving_yojson_runtime in
1772
      function
1773
      | `List ((`String "SIMPLE_NAME")::arg0::[]) ->
1774
          ((function
1775
            | `String x -> Result.Ok x
1776
            | _ -> Result.Error "Vhdl_ast.vhdl_name_t") arg0) >>=
1777
            ((fun arg0  -> Result.Ok (Simple arg0)))
1778
      | `List ((`String "IDENTIFIER")::arg0::[]) ->
1779
          ((function
1780
            | `String x -> Result.Ok x
1781
            | _ -> Result.Error "Vhdl_ast.vhdl_name_t") arg0) >>=
1782
            ((fun arg0  -> Result.Ok (Identifier arg0)))
1783
      | `List ((`String "SELECTED_NAME")::arg0::[]) ->
1784
          ((function
1785
            | `List xs -> map_bind (fun x  -> vhdl_name_t_of_yojson x) [] xs
1786
            | _ -> Result.Error "Vhdl_ast.vhdl_name_t") arg0) >>=
1787
            ((fun arg0  -> Result.Ok (Selected arg0)))
1788
      | `List ((`String "INDEXED_NAME")::arg0::[]) ->
1789
          ((function
1790
            | `Assoc xs ->
1791
                let rec loop xs ((arg0,arg1) as _state) =
1792
                  match xs with
1793
                  | ("id",x)::xs ->
1794
                      loop xs (((fun x  -> vhdl_name_t_of_yojson x) x), arg1)
1795
                  | ("exprs",x)::xs ->
1796
                      loop xs
1797
                        (arg0,
1798
                          ((function
1799
                            | `List xs ->
1800
                                map_bind (fun x  -> vhdl_expr_t_of_yojson x)
1801
                                  [] xs
1802
                            | _ -> Result.Error "Vhdl_ast.vhdl_name_t.exprs")
1803
                             x))
1804
                  | [] ->
1805
                      arg1 >>=
1806
                        ((fun arg1  ->
1807
                            arg0 >>=
1808
                              (fun arg0  ->
1809
                                 Result.Ok
1810
                                   (Index { id = arg0; exprs = arg1 }))))
1811
                  | _::xs -> loop xs _state  in
1812
                loop xs
1813
                  ((Result.Error "Vhdl_ast.vhdl_name_t.id"),
1814
                    (Result.Error "Vhdl_ast.vhdl_name_t.exprs"))
1815
            | _ -> Result.Error "Vhdl_ast.vhdl_name_t")) arg0
1816
      | `List ((`String "SLICE_NAME")::arg0::[]) ->
1817
          ((function
1818
            | `Assoc xs ->
1819
                let rec loop xs ((arg0,arg1) as _state) =
1820
                  match xs with
1821
                  | ("id",x)::xs ->
1822
                      loop xs (((fun x  -> vhdl_name_t_of_yojson x) x), arg1)
1823
                  | ("range",x)::xs ->
1824
                      loop xs
1825
                        (arg0,
1826
                          ((fun x  -> vhdl_discrete_range_t_of_yojson x) x))
1827
                  | [] ->
1828
                      arg1 >>=
1829
                        ((fun arg1  ->
1830
                            arg0 >>=
1831
                              (fun arg0  ->
1832
                                 Result.Ok
1833
                                   (Slice { id = arg0; range = arg1 }))))
1834
                  | _::xs -> loop xs _state  in
1835
                loop xs
1836
                  ((Result.Error "Vhdl_ast.vhdl_name_t.id"),
1837
                    (Result.Error "Vhdl_ast.vhdl_name_t.range"))
1838
            | _ -> Result.Error "Vhdl_ast.vhdl_name_t")) arg0
1839
      | `List ((`String "ATTRIBUTE_NAME")::arg0::[]) ->
1840
          ((function
1841
            | `Assoc xs ->
1842
                let rec loop xs ((arg0,arg1,arg2) as _state) =
1843
                  match xs with
1844
                  | ("id",x)::xs ->
1845
                      loop xs
1846
                        (((fun x  -> vhdl_name_t_of_yojson x) x), arg1, arg2)
1847
                  | ("designator",x)::xs ->
1848
                      loop xs
1849
                        (arg0, ((fun x  -> vhdl_name_t_of_yojson x) x), arg2)
1850
                  | ("expr",x)::xs ->
1851
                      loop xs
1852
                        (arg0, arg1, ((fun x  -> vhdl_expr_t_of_yojson x) x))
1853
                  | [] ->
1854
                      arg2 >>=
1855
                        ((fun arg2  ->
1856
                            arg1 >>=
1857
                              (fun arg1  ->
1858
                                 arg0 >>=
1859
                                   (fun arg0  ->
1860
                                      Result.Ok
1861
                                        (Attribute
1862
                                           {
1863
                                             id = arg0;
1864
                                             designator = arg1;
1865
                                             expr = arg2
1866
                                           })))))
1867
                  | _::xs -> loop xs _state  in
1868
                loop xs
1869
                  ((Result.Error "Vhdl_ast.vhdl_name_t.id"),
1870
                    (Result.Error "Vhdl_ast.vhdl_name_t.designator"),
1871
                    (Result.Ok IsNull))
1872
            | _ -> Result.Error "Vhdl_ast.vhdl_name_t")) arg0
1873
      | `List ((`String "FUNCTION_CALL")::arg0::[]) ->
1874
          ((function
1875
            | `Assoc xs ->
1876
                let rec loop xs ((arg0,arg1) as _state) =
1877
                  match xs with
1878
                  | ("id",x)::xs ->
1879
                      loop xs (((fun x  -> vhdl_name_t_of_yojson x) x), arg1)
1880
                  | ("assoc_list",x)::xs ->
1881
                      loop xs
1882
                        (arg0,
1883
                          ((function
1884
                            | `List xs ->
1885
                                map_bind
1886
                                  (fun x  -> vhdl_assoc_element_t_of_yojson x)
1887
                                  [] xs
1888
                            | _ ->
1889
                                Result.Error
1890
                                  "Vhdl_ast.vhdl_name_t.assoc_list") x))
1891
                  | [] ->
1892
                      arg1 >>=
1893
                        ((fun arg1  ->
1894
                            arg0 >>=
1895
                              (fun arg0  ->
1896
                                 Result.Ok
1897
                                   (Function { id = arg0; assoc_list = arg1 }))))
1898
                  | _::xs -> loop xs _state  in
1899
                loop xs
1900
                  ((Result.Error "Vhdl_ast.vhdl_name_t.id"),
1901
                    (Result.Error "Vhdl_ast.vhdl_name_t.assoc_list"))
1902
            | _ -> Result.Error "Vhdl_ast.vhdl_name_t")) arg0
1903
      | `List ((`String "NoName")::[]) -> Result.Ok NoName
1904
      | _ -> Result.Error "Vhdl_ast.vhdl_name_t")
1905
  [@ocaml.warning "-A"])
1906
1907
and (vhdl_assoc_element_t_to_yojson :
1908
      vhdl_assoc_element_t -> Yojson.Safe.json)
1909
  =
1910
  ((let open! Ppx_deriving_yojson_runtime in
1911
      fun x  ->
1912
        let fields = []  in
1913
        let fields =
1914 00970bbf Arnaud Dieumegard
          if x.actual_expr = None
1915 40364f53 Arnaud Dieumegard
          then fields
1916
          else
1917
            ("actual_expr",
1918
              (((function
1919
                 | None  -> `Null
1920
                 | Some x -> ((fun x  -> vhdl_expr_t_to_yojson x)) x))
1921
                 x.actual_expr))
1922
            :: fields
1923
           in
1924
        let fields =
1925 00970bbf Arnaud Dieumegard
          if x.actual_designator = None
1926 40364f53 Arnaud Dieumegard
          then fields
1927
          else
1928
            ("actual_designator",
1929
              (((function
1930
                 | None  -> `Null
1931
                 | Some x -> ((fun x  -> vhdl_name_t_to_yojson x)) x))
1932
                 x.actual_designator))
1933
            :: fields
1934
           in
1935
        let fields =
1936 00970bbf Arnaud Dieumegard
          if x.actual_name = None
1937 40364f53 Arnaud Dieumegard
          then fields
1938
          else
1939
            ("actual_name",
1940
              (((function
1941
                 | None  -> `Null
1942
                 | Some x -> ((fun x  -> vhdl_name_t_to_yojson x)) x))
1943
                 x.actual_name))
1944
            :: fields
1945
           in
1946
        let fields =
1947 00970bbf Arnaud Dieumegard
          if x.formal_arg = None
1948 40364f53 Arnaud Dieumegard
          then fields
1949
          else
1950
            ("formal_arg",
1951
              (((function
1952
                 | None  -> `Null
1953
                 | Some x -> ((fun x  -> vhdl_name_t_to_yojson x)) x))
1954
                 x.formal_arg))
1955
            :: fields
1956
           in
1957
        let fields =
1958 00970bbf Arnaud Dieumegard
          if x.formal_name = None
1959 40364f53 Arnaud Dieumegard
          then fields
1960
          else
1961
            ("formal_name",
1962
              (((function
1963
                 | None  -> `Null
1964
                 | Some x -> ((fun x  -> vhdl_name_t_to_yojson x)) x))
1965
                 x.formal_name))
1966
            :: fields
1967
           in
1968
        `Assoc fields)
1969
  [@ocaml.warning "-A"])
1970
1971
and (vhdl_assoc_element_t_of_yojson :
1972
      Yojson.Safe.json ->
1973
        vhdl_assoc_element_t Ppx_deriving_yojson_runtime.error_or)
1974
  =
1975
  ((let open! Ppx_deriving_yojson_runtime in
1976
      function
1977
      | `Assoc xs ->
1978
          let rec loop xs ((arg0,arg1,arg2,arg3,arg4) as _state) =
1979
            match xs with
1980
            | ("formal_name",x)::xs ->
1981
                loop xs
1982
                  (((function
1983
                     | `Null -> Result.Ok None
1984
                     | x ->
1985
                         ((fun x  -> vhdl_name_t_of_yojson x) x) >>=
1986
                           ((fun x  -> Result.Ok (Some x)))) x), arg1, arg2,
1987
                    arg3, arg4)
1988
            | ("formal_arg",x)::xs ->
1989
                loop xs
1990
                  (arg0,
1991
                    ((function
1992
                      | `Null -> Result.Ok None
1993
                      | x ->
1994
                          ((fun x  -> vhdl_name_t_of_yojson x) x) >>=
1995
                            ((fun x  -> Result.Ok (Some x)))) x), arg2, arg3,
1996
                    arg4)
1997
            | ("actual_name",x)::xs ->
1998
                loop xs
1999
                  (arg0, arg1,
2000
                    ((function
2001
                      | `Null -> Result.Ok None
2002
                      | x ->
2003
                          ((fun x  -> vhdl_name_t_of_yojson x) x) >>=
2004
                            ((fun x  -> Result.Ok (Some x)))) x), arg3, arg4)
2005
            | ("actual_designator",x)::xs ->
2006
                loop xs
2007
                  (arg0, arg1, arg2,
2008
                    ((function
2009
                      | `Null -> Result.Ok None
2010
                      | x ->
2011
                          ((fun x  -> vhdl_name_t_of_yojson x) x) >>=
2012
                            ((fun x  -> Result.Ok (Some x)))) x), arg4)
2013
            | ("actual_expr",x)::xs ->
2014
                loop xs
2015
                  (arg0, arg1, arg2, arg3,
2016
                    ((function
2017
                      | `Null -> Result.Ok None
2018
                      | x ->
2019
                          ((fun x  -> vhdl_expr_t_of_yojson x) x) >>=
2020
                            ((fun x  -> Result.Ok (Some x)))) x))
2021
            | [] ->
2022
                arg4 >>=
2023
                  ((fun arg4  ->
2024
                      arg3 >>=
2025
                        (fun arg3  ->
2026
                           arg2 >>=
2027
                             (fun arg2  ->
2028
                                arg1 >>=
2029
                                  (fun arg1  ->
2030
                                     arg0 >>=
2031
                                       (fun arg0  ->
2032
                                          Result.Ok
2033
                                            {
2034
                                              formal_name = arg0;
2035
                                              formal_arg = arg1;
2036
                                              actual_name = arg2;
2037
                                              actual_designator = arg3;
2038
                                              actual_expr = arg4
2039
                                            }))))))
2040
            | _::xs -> loop xs _state  in
2041
          loop xs
2042
            ((Result.Ok (Some NoName)), (Result.Ok (Some NoName)),
2043
              (Result.Ok (Some NoName)), (Result.Ok (Some NoName)),
2044
              (Result.Ok (Some IsNull)))
2045
      | _ -> Result.Error "Vhdl_ast.vhdl_assoc_element_t")
2046
  [@ocaml.warning "-A"])
2047
2048
and (vhdl_element_assoc_t_to_yojson :
2049
      vhdl_element_assoc_t -> Yojson.Safe.json)
2050
  =
2051
  ((let open! Ppx_deriving_yojson_runtime in
2052
      fun x  ->
2053
        let fields = []  in
2054
        let fields = ("expr", ((fun x  -> vhdl_expr_t_to_yojson x) x.expr))
2055
          :: fields  in
2056
        let fields =
2057
          ("choices",
2058
            ((fun x  ->
2059
                `List (List.map (fun x  -> vhdl_expr_t_to_yojson x) x))
2060
               x.choices))
2061
          :: fields  in
2062
        `Assoc fields)
2063
  [@ocaml.warning "-A"])
2064
2065
and (vhdl_element_assoc_t_of_yojson :
2066
      Yojson.Safe.json ->
2067
        vhdl_element_assoc_t Ppx_deriving_yojson_runtime.error_or)
2068
  =
2069
  ((let open! Ppx_deriving_yojson_runtime in
2070
      function
2071
      | `Assoc xs ->
2072
          let rec loop xs ((arg0,arg1) as _state) =
2073
            match xs with
2074
            | ("choices",x)::xs ->
2075
                loop xs
2076
                  (((function
2077
                     | `List xs ->
2078
                         map_bind (fun x  -> vhdl_expr_t_of_yojson x) [] xs
2079
                     | _ ->
2080
                         Result.Error "Vhdl_ast.vhdl_element_assoc_t.choices")
2081
                      x), arg1)
2082
            | ("expr",x)::xs ->
2083
                loop xs (arg0, ((fun x  -> vhdl_expr_t_of_yojson x) x))
2084
            | [] ->
2085
                arg1 >>=
2086
                  ((fun arg1  ->
2087
                      arg0 >>=
2088
                        (fun arg0  ->
2089
                           Result.Ok { choices = arg0; expr = arg1 })))
2090
            | _::xs -> loop xs _state  in
2091
          loop xs
2092
            ((Result.Error "Vhdl_ast.vhdl_element_assoc_t.choices"),
2093
              (Result.Error "Vhdl_ast.vhdl_element_assoc_t.expr"))
2094
      | _ -> Result.Error "Vhdl_ast.vhdl_element_assoc_t")
2095
  [@ocaml.warning "-A"])
2096
2097
and (vhdl_array_attributes_t_to_yojson :
2098
      vhdl_array_attributes_t -> Yojson.Safe.json)
2099
  =
2100
  ((let open! Ppx_deriving_yojson_runtime in
2101
      function
2102
      | AAttInt arg0 ->
2103
          `List
2104
            [`String "AAttInt";
2105
            (let fields = []  in
2106
             let fields =
2107
               ("arg",
2108
                 ((fun (x : Ppx_deriving_runtime.int)  -> `Int x) arg0.arg))
2109
               :: fields  in
2110
             let fields =
2111
               ("id",
2112
                 ((fun (x : Ppx_deriving_runtime.string)  -> `String x)
2113
                    arg0.id))
2114
               :: fields  in
2115
             `Assoc fields)]
2116
      | AAttAscending  -> `List [`String "AAttAscending"])
2117
  [@ocaml.warning "-A"])
2118
2119
and (vhdl_array_attributes_t_of_yojson :
2120
      Yojson.Safe.json ->
2121
        vhdl_array_attributes_t Ppx_deriving_yojson_runtime.error_or)
2122
  =
2123
  ((let open! Ppx_deriving_yojson_runtime in
2124
      function
2125
      | `List ((`String "AAttInt")::arg0::[]) ->
2126
          ((function
2127
            | `Assoc xs ->
2128
                let rec loop xs ((arg0,arg1) as _state) =
2129
                  match xs with
2130
                  | ("id",x)::xs ->
2131
                      loop xs
2132
                        (((function
2133
                           | `String x -> Result.Ok x
2134
                           | _ ->
2135
                               Result.Error
2136
                                 "Vhdl_ast.vhdl_array_attributes_t.id") x),
2137
                          arg1)
2138
                  | ("arg",x)::xs ->
2139
                      loop xs
2140
                        (arg0,
2141
                          ((function
2142
                            | `Int x -> Result.Ok x
2143
                            | _ ->
2144
                                Result.Error
2145
                                  "Vhdl_ast.vhdl_array_attributes_t.arg") x))
2146
                  | [] ->
2147
                      arg1 >>=
2148
                        ((fun arg1  ->
2149
                            arg0 >>=
2150
                              (fun arg0  ->
2151
                                 Result.Ok
2152
                                   (AAttInt { id = arg0; arg = arg1 }))))
2153
                  | _::xs -> loop xs _state  in
2154
                loop xs
2155
                  ((Result.Error "Vhdl_ast.vhdl_array_attributes_t.id"),
2156
                    (Result.Error "Vhdl_ast.vhdl_array_attributes_t.arg"))
2157
            | _ -> Result.Error "Vhdl_ast.vhdl_array_attributes_t")) arg0
2158
      | `List ((`String "AAttAscending")::[]) -> Result.Ok AAttAscending
2159
      | _ -> Result.Error "Vhdl_ast.vhdl_array_attributes_t")
2160
  [@ocaml.warning "-A"])
2161
2162
and (vhdl_signal_attributes_t_to_yojson :
2163
      vhdl_signal_attributes_t -> Yojson.Safe.json)
2164
  =
2165
  ((let open! Ppx_deriving_yojson_runtime in
2166
      function
2167
      | SigAtt arg0 ->
2168
          `List
2169
            [`String "SigAtt";
2170
            ((fun (x : Ppx_deriving_runtime.string)  -> `String x)) arg0])
2171
  [@ocaml.warning "-A"])
2172
2173
and (vhdl_signal_attributes_t_of_yojson :
2174
      Yojson.Safe.json ->
2175
        vhdl_signal_attributes_t Ppx_deriving_yojson_runtime.error_or)
2176
  =
2177
  ((let open! Ppx_deriving_yojson_runtime in
2178
      function
2179
      | `List ((`String "SigAtt")::arg0::[]) ->
2180
          ((function
2181
            | `String x -> Result.Ok x
2182
            | _ -> Result.Error "Vhdl_ast.vhdl_signal_attributes_t") arg0)
2183
            >>= ((fun arg0  -> Result.Ok (SigAtt arg0)))
2184
      | _ -> Result.Error "Vhdl_ast.vhdl_signal_attributes_t")
2185
  [@ocaml.warning "-A"])
2186
2187
and (vhdl_string_attributes_t_to_yojson :
2188
      vhdl_string_attributes_t -> Yojson.Safe.json)
2189
  =
2190
  ((let open! Ppx_deriving_yojson_runtime in
2191
      function
2192
      | StringAtt arg0 ->
2193
          `List
2194
            [`String "StringAtt";
2195
            ((fun (x : Ppx_deriving_runtime.string)  -> `String x)) arg0])
2196
  [@ocaml.warning "-A"])
2197
2198
and (vhdl_string_attributes_t_of_yojson :
2199
      Yojson.Safe.json ->
2200
        vhdl_string_attributes_t Ppx_deriving_yojson_runtime.error_or)
2201
  =
2202
  ((let open! Ppx_deriving_yojson_runtime in
2203
      function
2204
      | `List ((`String "StringAtt")::arg0::[]) ->
2205
          ((function
2206
            | `String x -> Result.Ok x
2207
            | _ -> Result.Error "Vhdl_ast.vhdl_string_attributes_t") arg0)
2208
            >>= ((fun arg0  -> Result.Ok (StringAtt arg0)))
2209
      | _ -> Result.Error "Vhdl_ast.vhdl_string_attributes_t")
2210
  [@ocaml.warning "-A"])
2211
2212
and (vhdl_suffix_selection_t_to_yojson :
2213
      vhdl_suffix_selection_t -> Yojson.Safe.json)
2214
  =
2215
  ((let open! Ppx_deriving_yojson_runtime in
2216
      function
2217
      | Idx arg0 ->
2218
          `List
2219
            [`String "Idx";
2220
            ((fun (x : Ppx_deriving_runtime.int)  -> `Int x)) arg0]
2221
      | SuffixRange (arg0,arg1) ->
2222
          `List
2223
            [`String "SuffixRange";
2224
            ((fun (x : Ppx_deriving_runtime.int)  -> `Int x)) arg0;
2225
            ((fun (x : Ppx_deriving_runtime.int)  -> `Int x)) arg1])
2226
  [@ocaml.warning "-A"])
2227
2228
and (vhdl_suffix_selection_t_of_yojson :
2229
      Yojson.Safe.json ->
2230
        vhdl_suffix_selection_t Ppx_deriving_yojson_runtime.error_or)
2231
  =
2232
  ((let open! Ppx_deriving_yojson_runtime in
2233
      function
2234
      | `List ((`String "Idx")::arg0::[]) ->
2235
          ((function
2236
            | `Int x -> Result.Ok x
2237
            | _ -> Result.Error "Vhdl_ast.vhdl_suffix_selection_t") arg0) >>=
2238
            ((fun arg0  -> Result.Ok (Idx arg0)))
2239
      | `List ((`String "SuffixRange")::arg0::arg1::[]) ->
2240
          ((function
2241
            | `Int x -> Result.Ok x
2242
            | _ -> Result.Error "Vhdl_ast.vhdl_suffix_selection_t") arg1) >>=
2243
            ((fun arg1  ->
2244
                ((function
2245
                  | `Int x -> Result.Ok x
2246
                  | _ -> Result.Error "Vhdl_ast.vhdl_suffix_selection_t")
2247
                   arg0)
2248
                  >>= (fun arg0  -> Result.Ok (SuffixRange (arg0, arg1)))))
2249
      | _ -> Result.Error "Vhdl_ast.vhdl_suffix_selection_t")
2250
  [@ocaml.warning "-A"])
2251
2252
type 'basetype vhdl_type_attributes_t =
2253
  | TAttNoArg of {
2254
  id: string } 
2255
  | TAttIntArg of {
2256
  id: string ;
2257
  arg: int } 
2258
  | TAttValArg of {
2259
  id: string ;
2260
  arg: 'basetype } 
2261
  | TAttStringArg of {
2262
  id: string ;
2263
  arg: string } 
2264
2265 389493d3 Arnaud Dieumegard
(* TODO *)
2266 40364f53 Arnaud Dieumegard
let rec pp_vhdl_type_attributes_t
2267
  =
2268
  ((let open! Ppx_deriving_runtime in
2269
      fun poly_basetype  ->
2270
        fun fmt  ->
2271
          function
2272
          | TAttNoArg { id = aid } ->
2273
              (Format.fprintf fmt "@[<2>TAttNoArg {@,";
2274
               (Format.fprintf fmt "@[%s =@ " "id";
2275
                (Format.fprintf fmt "%S") aid;
2276
                Format.fprintf fmt "@]");
2277
               Format.fprintf fmt "@]}")
2278
          | TAttIntArg { id = aid; arg = aarg } ->
2279
              (Format.fprintf fmt "@[<2>TAttIntArg {@,";
2280
               ((Format.fprintf fmt "@[%s =@ " "id";
2281
                 (Format.fprintf fmt "%S") aid;
2282
                 Format.fprintf fmt "@]");
2283
                Format.fprintf fmt ";@ ";
2284
                Format.fprintf fmt "@[%s =@ " "arg";
2285
                (Format.fprintf fmt "%d") aarg;
2286
                Format.fprintf fmt "@]");
2287
               Format.fprintf fmt "@]}")
2288
          | TAttValArg { id = aid; arg = aarg } ->
2289
              (Format.fprintf fmt "@[<2>TAttValArg {@,";
2290
               ((Format.fprintf fmt "@[%s =@ " "id";
2291
                 (Format.fprintf fmt "%S") aid;
2292
                 Format.fprintf fmt "@]");
2293
                Format.fprintf fmt ";@ ";
2294
                Format.fprintf fmt "@[%s =@ " "arg";
2295
                (poly_basetype fmt) aarg;
2296
                Format.fprintf fmt "@]");
2297
               Format.fprintf fmt "@]}")
2298
          | TAttStringArg { id = aid; arg = aarg } ->
2299
              (Format.fprintf fmt "@[<2>TAttStringArg {@,";
2300
               ((Format.fprintf fmt "@[%s =@ " "id";
2301
                 (Format.fprintf fmt "%S") aid;
2302
                 Format.fprintf fmt "@]");
2303
                Format.fprintf fmt ";@ ";
2304
                Format.fprintf fmt "@[%s =@ " "arg";
2305
                (Format.fprintf fmt "%S") aarg;
2306
                Format.fprintf fmt "@]");
2307
               Format.fprintf fmt "@]}"))
2308
  [@ocaml.warning "-A"])
2309
2310
and show_vhdl_type_attributes_t  =
2311
  fun poly_basetype  ->
2312
    fun x  ->
2313
      Format.asprintf "%a" (pp_vhdl_type_attributes_t poly_basetype) x
2314
2315
let rec vhdl_type_attributes_t_to_yojson :
2316
  'basetype .
2317
    ('basetype -> Yojson.Safe.json) ->
2318
      'basetype vhdl_type_attributes_t -> Yojson.Safe.json
2319
  =
2320
  fun poly_basetype  ->
2321
    ((let open! Ppx_deriving_yojson_runtime in
2322
        function
2323
        | TAttNoArg arg0 ->
2324
            `List
2325
              [`String "TAttNoArg";
2326
              (let fields = []  in
2327
               let fields =
2328
                 ("id",
2329
                   ((fun (x : Ppx_deriving_runtime.string)  -> `String x)
2330
                      arg0.id))
2331
                 :: fields  in
2332
               `Assoc fields)]
2333
        | TAttIntArg arg0 ->
2334
            `List
2335
              [`String "TAttIntArg";
2336
              (let fields = []  in
2337
               let fields =
2338
                 ("arg",
2339
                   ((fun (x : Ppx_deriving_runtime.int)  -> `Int x) arg0.arg))
2340
                 :: fields  in
2341
               let fields =
2342
                 ("id",
2343
                   ((fun (x : Ppx_deriving_runtime.string)  -> `String x)
2344
                      arg0.id))
2345
                 :: fields  in
2346
               `Assoc fields)]
2347
        | TAttValArg arg0 ->
2348
            `List
2349
              [`String "TAttValArg";
2350
              (let fields = []  in
2351
               let fields =
2352
                 ("arg", ((poly_basetype : _ -> Yojson.Safe.json) arg0.arg))
2353
                 :: fields  in
2354
               let fields =
2355
                 ("id",
2356
                   ((fun (x : Ppx_deriving_runtime.string)  -> `String x)
2357
                      arg0.id))
2358
                 :: fields  in
2359
               `Assoc fields)]
2360
        | TAttStringArg arg0 ->
2361
            `List
2362
              [`String "TAttStringArg";
2363
              (let fields = []  in
2364
               let fields =
2365
                 ("arg",
2366
                   ((fun (x : Ppx_deriving_runtime.string)  -> `String x)
2367
                      arg0.arg))
2368
                 :: fields  in
2369
               let fields =
2370
                 ("id",
2371
                   ((fun (x : Ppx_deriving_runtime.string)  -> `String x)
2372
                      arg0.id))
2373
                 :: fields  in
2374
               `Assoc fields)])
2375
    [@ocaml.warning "-A"])
2376
2377
and vhdl_type_attributes_t_of_yojson :
2378
  'basetype .
2379
    (Yojson.Safe.json -> 'basetype Ppx_deriving_yojson_runtime.error_or) ->
2380
      Yojson.Safe.json ->
2381
        'basetype vhdl_type_attributes_t Ppx_deriving_yojson_runtime.error_or
2382
  =
2383
  fun poly_basetype  ->
2384
    ((let open! Ppx_deriving_yojson_runtime in
2385
        function
2386
        | `List ((`String "TAttNoArg")::arg0::[]) ->
2387
            ((function
2388
              | `Assoc xs ->
2389
                  let rec loop xs (arg0 as _state) =
2390
                    match xs with
2391
                    | ("id",x)::xs ->
2392
                        loop xs
2393
                          ((function
2394
                            | `String x -> Result.Ok x
2395
                            | _ ->
2396
                                Result.Error
2397
                                  "Vhdl_ast.vhdl_type_attributes_t.id") x)
2398
                    | [] ->
2399
                        arg0 >>=
2400
                          ((fun arg0  -> Result.Ok (TAttNoArg { id = arg0 })))
2401
                    | _::xs -> loop xs _state  in
2402
                  loop xs (Result.Error "Vhdl_ast.vhdl_type_attributes_t.id")
2403
              | _ -> Result.Error "Vhdl_ast.vhdl_type_attributes_t")) arg0
2404
        | `List ((`String "TAttIntArg")::arg0::[]) ->
2405
            ((function
2406
              | `Assoc xs ->
2407
                  let rec loop xs ((arg0,arg1) as _state) =
2408
                    match xs with
2409
                    | ("id",x)::xs ->
2410
                        loop xs
2411
                          (((function
2412
                             | `String x -> Result.Ok x
2413
                             | _ ->
2414
                                 Result.Error
2415
                                   "Vhdl_ast.vhdl_type_attributes_t.id") x),
2416
                            arg1)
2417
                    | ("arg",x)::xs ->
2418
                        loop xs
2419
                          (arg0,
2420
                            ((function
2421
                              | `Int x -> Result.Ok x
2422
                              | _ ->
2423
                                  Result.Error
2424
                                    "Vhdl_ast.vhdl_type_attributes_t.arg") x))
2425
                    | [] ->
2426
                        arg1 >>=
2427
                          ((fun arg1  ->
2428
                              arg0 >>=
2429
                                (fun arg0  ->
2430
                                   Result.Ok
2431
                                     (TAttIntArg { id = arg0; arg = arg1 }))))
2432
                    | _::xs -> loop xs _state  in
2433
                  loop xs
2434
                    ((Result.Error "Vhdl_ast.vhdl_type_attributes_t.id"),
2435
                      (Result.Error "Vhdl_ast.vhdl_type_attributes_t.arg"))
2436
              | _ -> Result.Error "Vhdl_ast.vhdl_type_attributes_t")) arg0
2437
        | `List ((`String "TAttValArg")::arg0::[]) ->
2438
            ((function
2439
              | `Assoc xs ->
2440
                  let rec loop xs ((arg0,arg1) as _state) =
2441
                    match xs with
2442
                    | ("id",x)::xs ->
2443
                        loop xs
2444
                          (((function
2445
                             | `String x -> Result.Ok x
2446
                             | _ ->
2447
                                 Result.Error
2448
                                   "Vhdl_ast.vhdl_type_attributes_t.id") x),
2449
                            arg1)
2450
                    | ("arg",x)::xs ->
2451
                        loop xs
2452
                          (arg0,
2453
                            ((poly_basetype : Yojson.Safe.json -> _ error_or)
2454
                               x))
2455
                    | [] ->
2456
                        arg1 >>=
2457
                          ((fun arg1  ->
2458
                              arg0 >>=
2459
                                (fun arg0  ->
2460
                                   Result.Ok
2461
                                     (TAttValArg { id = arg0; arg = arg1 }))))
2462
                    | _::xs -> loop xs _state  in
2463
                  loop xs
2464
                    ((Result.Error "Vhdl_ast.vhdl_type_attributes_t.id"),
2465
                      (Result.Error "Vhdl_ast.vhdl_type_attributes_t.arg"))
2466
              | _ -> Result.Error "Vhdl_ast.vhdl_type_attributes_t")) arg0
2467
        | `List ((`String "TAttStringArg")::arg0::[]) ->
2468
            ((function
2469
              | `Assoc xs ->
2470
                  let rec loop xs ((arg0,arg1) as _state) =
2471
                    match xs with
2472
                    | ("id",x)::xs ->
2473
                        loop xs
2474
                          (((function
2475
                             | `String x -> Result.Ok x
2476
                             | _ ->
2477
                                 Result.Error
2478
                                   "Vhdl_ast.vhdl_type_attributes_t.id") x),
2479
                            arg1)
2480
                    | ("arg",x)::xs ->
2481
                        loop xs
2482
                          (arg0,
2483
                            ((function
2484
                              | `String x -> Result.Ok x
2485
                              | _ ->
2486
                                  Result.Error
2487
                                    "Vhdl_ast.vhdl_type_attributes_t.arg") x))
2488
                    | [] ->
2489
                        arg1 >>=
2490
                          ((fun arg1  ->
2491
                              arg0 >>=
2492
                                (fun arg0  ->
2493
                                   Result.Ok
2494
                                     (TAttStringArg { id = arg0; arg = arg1 }))))
2495
                    | _::xs -> loop xs _state  in
2496
                  loop xs
2497
                    ((Result.Error "Vhdl_ast.vhdl_type_attributes_t.id"),
2498
                      (Result.Error "Vhdl_ast.vhdl_type_attributes_t.arg"))
2499
              | _ -> Result.Error "Vhdl_ast.vhdl_type_attributes_t")) arg0
2500
        | _ -> Result.Error "Vhdl_ast.vhdl_type_attributes_t")
2501
    [@ocaml.warning "-A"])
2502
2503
let typ_att_noarg = ["base"; "left"; "right"; "high"; "low"] 
2504
let typ_att_intarg = ["pos"; "val"; "succ"; "pred"; "leftof"; "rightof"] 
2505
let typ_att_valarg = ["image"] 
2506
let typ_att_stringarg = ["value"] 
2507
let array_att_intarg =
2508
  ["left"; "right"; "high"; "low"; "range"; "reverse_range"; "length"] 
2509
type vhdl_parameter_t =
2510
  {
2511
  names: vhdl_name_t list ;
2512
  mode: string list [@default []];
2513
  typ: vhdl_subtype_indication_t ;
2514 00970bbf Arnaud Dieumegard
  init_val: vhdl_cst_val_t option [@default None]}
2515 40364f53 Arnaud Dieumegard
2516 389493d3 Arnaud Dieumegard
(* TODO *)
2517 40364f53 Arnaud Dieumegard
let rec pp_vhdl_parameter_t :
2518
  Format.formatter -> vhdl_parameter_t -> Ppx_deriving_runtime.unit =
2519
  let __2 () = pp_vhdl_cst_val_t
2520
  
2521
  and __1 () = pp_vhdl_subtype_indication_t
2522
  
2523
  and __0 () = pp_vhdl_name_t
2524
   in
2525
  ((let open! Ppx_deriving_runtime in
2526
      fun fmt  ->
2527
        fun x  ->
2528
          Format.fprintf fmt "@[<2>{ ";
2529
          ((((Format.fprintf fmt "@[%s =@ " "names";
2530
              ((fun x  ->
2531
                  Format.fprintf fmt "@[<2>[";
2532
                  ignore
2533
                    (List.fold_left
2534
                       (fun sep  ->
2535
                          fun x  ->
2536
                            if sep then Format.fprintf fmt ";@ ";
2537
                            ((__0 ()) fmt) x;
2538
                            true) false x);
2539
                  Format.fprintf fmt "@,]@]")) x.names;
2540
              Format.fprintf fmt "@]");
2541
             Format.fprintf fmt ";@ ";
2542
             Format.fprintf fmt "@[%s =@ " "mode";
2543
             ((fun x  ->
2544
                 Format.fprintf fmt "@[<2>[";
2545
                 ignore
2546
                   (List.fold_left
2547
                      (fun sep  ->
2548
                         fun x  ->
2549
                           if sep then Format.fprintf fmt ";@ ";
2550
                           (Format.fprintf fmt "%S") x;
2551
                           true) false x);
2552
                 Format.fprintf fmt "@,]@]")) x.mode;
2553
             Format.fprintf fmt "@]");
2554
            Format.fprintf fmt ";@ ";
2555
            Format.fprintf fmt "@[%s =@ " "typ";
2556
            ((__1 ()) fmt) x.typ;
2557
            Format.fprintf fmt "@]");
2558
           Format.fprintf fmt ";@ ";
2559
           Format.fprintf fmt "@[%s =@ " "init_val";
2560
           ((function
2561
             | None  -> Format.pp_print_string fmt "None"
2562
             | Some x ->
2563
                 (Format.pp_print_string fmt "(Some ";
2564
                  ((__2 ()) fmt) x;
2565
                  Format.pp_print_string fmt ")"))) x.init_val;
2566
           Format.fprintf fmt "@]");
2567
          Format.fprintf fmt "@ }@]")
2568
    [@ocaml.warning "-A"])
2569
2570
and show_vhdl_parameter_t : vhdl_parameter_t -> Ppx_deriving_runtime.string =
2571
  fun x  -> Format.asprintf "%a" pp_vhdl_parameter_t x
2572
2573
let rec (vhdl_parameter_t_to_yojson : vhdl_parameter_t -> Yojson.Safe.json) =
2574
  ((let open! Ppx_deriving_yojson_runtime in
2575
      fun x  ->
2576
        let fields = []  in
2577
        let fields =
2578 00970bbf Arnaud Dieumegard
          if x.init_val = None
2579 40364f53 Arnaud Dieumegard
          then fields
2580
          else
2581
            ("init_val",
2582
              (((function
2583
                 | None  -> `Null
2584
                 | Some x -> ((fun x  -> vhdl_cst_val_t_to_yojson x)) x))
2585
                 x.init_val))
2586
            :: fields
2587
           in
2588
        let fields =
2589
          ("typ", ((fun x  -> vhdl_subtype_indication_t_to_yojson x) x.typ))
2590
          :: fields  in
2591
        let fields =
2592
          if x.mode = []
2593
          then fields
2594
          else
2595
            ("mode",
2596
              (((fun x  ->
2597
                   `List
2598
                     (List.map
2599
                        (fun (x : Ppx_deriving_runtime.string)  -> `String x)
2600
                        x))) x.mode))
2601
            :: fields
2602
           in
2603
        let fields =
2604
          ("names",
2605
            ((fun x  ->
2606
                `List (List.map (fun x  -> vhdl_name_t_to_yojson x) x))
2607
               x.names))
2608
          :: fields  in
2609
        `Assoc fields)
2610
  [@ocaml.warning "-A"])
2611
2612
and (vhdl_parameter_t_of_yojson :
2613
      Yojson.Safe.json ->
2614
        vhdl_parameter_t Ppx_deriving_yojson_runtime.error_or)
2615
  =
2616
  ((let open! Ppx_deriving_yojson_runtime in
2617
      function
2618
      | `Assoc xs ->
2619
          let rec loop xs ((arg0,arg1,arg2,arg3) as _state) =
2620
            match xs with
2621
            | ("names",x)::xs ->
2622
                loop xs
2623
                  (((function
2624
                     | `List xs ->
2625
                         map_bind (fun x  -> vhdl_name_t_of_yojson x) [] xs
2626
                     | _ -> Result.Error "Vhdl_ast.vhdl_parameter_t.names") x),
2627
                    arg1, arg2, arg3)
2628
            | ("mode",x)::xs ->
2629
                loop xs
2630
                  (arg0,
2631
                    ((function
2632
                      | `List xs ->
2633
                          map_bind
2634
                            (function
2635
                             | `String x -> Result.Ok x
2636
                             | _ ->
2637
                                 Result.Error
2638
                                   "Vhdl_ast.vhdl_parameter_t.mode") [] xs
2639
                      | _ -> Result.Error "Vhdl_ast.vhdl_parameter_t.mode") x),
2640
                    arg2, arg3)
2641
            | ("typ",x)::xs ->
2642
                loop xs
2643
                  (arg0, arg1,
2644
                    ((fun x  -> vhdl_subtype_indication_t_of_yojson x) x),
2645
                    arg3)
2646
            | ("init_val",x)::xs ->
2647
                loop xs
2648
                  (arg0, arg1, arg2,
2649
                    ((function
2650
                      | `Null -> Result.Ok None
2651
                      | x ->
2652
                          ((fun x  -> vhdl_cst_val_t_of_yojson x) x) >>=
2653
                            ((fun x  -> Result.Ok (Some x)))) x))
2654
            | [] ->
2655
                arg3 >>=
2656
                  ((fun arg3  ->
2657
                      arg2 >>=
2658
                        (fun arg2  ->
2659
                           arg1 >>=
2660
                             (fun arg1  ->
2661
                                arg0 >>=
2662
                                  (fun arg0  ->
2663
                                     Result.Ok
2664
                                       {
2665
                                         names = arg0;
2666
                                         mode = arg1;
2667
                                         typ = arg2;
2668
                                         init_val = arg3
2669
                                       })))))
2670
            | _::xs -> loop xs _state  in
2671
          loop xs
2672
            ((Result.Error "Vhdl_ast.vhdl_parameter_t.names"),
2673
              (Result.Ok []), (Result.Error "Vhdl_ast.vhdl_parameter_t.typ"),
2674
              (Result.Ok (Some (CstInt 0))))
2675
      | _ -> Result.Error "Vhdl_ast.vhdl_parameter_t")
2676
  [@ocaml.warning "-A"])
2677
2678
type vhdl_subprogram_spec_t =
2679
  {
2680
  name: string [@default ""];
2681
  typeMark: vhdl_name_t [@default NoName];
2682
  parameters: vhdl_parameter_t list ;
2683
  isPure: bool [@default false]}
2684
2685 389493d3 Arnaud Dieumegard
(* TODO *)
2686 40364f53 Arnaud Dieumegard
let rec pp_vhdl_subprogram_spec_t :
2687
  Format.formatter -> vhdl_subprogram_spec_t -> Ppx_deriving_runtime.unit =
2688
  let __1 () = pp_vhdl_parameter_t
2689
  
2690
  and __0 () = pp_vhdl_name_t
2691
   in
2692
  ((let open! Ppx_deriving_runtime in
2693
      fun fmt  ->
2694
        fun x  ->
2695
          Format.fprintf fmt "@[<2>{ ";
2696
          ((((Format.fprintf fmt "@[%s =@ " "name";
2697
              (Format.fprintf fmt "%S") x.name;
2698
              Format.fprintf fmt "@]");
2699
             Format.fprintf fmt ";@ ";
2700
             Format.fprintf fmt "@[%s =@ " "typeMark";
2701
             ((__0 ()) fmt) x.typeMark;
2702
             Format.fprintf fmt "@]");
2703
            Format.fprintf fmt ";@ ";
2704
            Format.fprintf fmt "@[%s =@ " "parameters";
2705
            ((fun x  ->
2706
                Format.fprintf fmt "@[<2>[";
2707
                ignore
2708
                  (List.fold_left
2709
                     (fun sep  ->
2710
                        fun x  ->
2711
                          if sep then Format.fprintf fmt ";@ ";
2712
                          ((__1 ()) fmt) x;
2713
                          true) false x);
2714
                Format.fprintf fmt "@,]@]")) x.parameters;
2715
            Format.fprintf fmt "@]");
2716
           Format.fprintf fmt ";@ ";
2717
           Format.fprintf fmt "@[%s =@ " "isPure";
2718
           (Format.fprintf fmt "%B") x.isPure;
2719
           Format.fprintf fmt "@]");
2720
          Format.fprintf fmt "@ }@]")
2721
    [@ocaml.warning "-A"])
2722
2723
and show_vhdl_subprogram_spec_t :
2724
  vhdl_subprogram_spec_t -> Ppx_deriving_runtime.string =
2725
  fun x  -> Format.asprintf "%a" pp_vhdl_subprogram_spec_t x
2726
2727
let rec (vhdl_subprogram_spec_t_to_yojson :
2728
          vhdl_subprogram_spec_t -> Yojson.Safe.json)
2729
  =
2730
  ((let open! Ppx_deriving_yojson_runtime in
2731
      fun x  ->
2732
        let fields = []  in
2733
        let fields =
2734
          if x.isPure = false
2735
          then fields
2736
          else
2737
            ("isPure",
2738
              (((fun (x : Ppx_deriving_runtime.bool)  -> `Bool x)) x.isPure))
2739
            :: fields
2740
           in
2741
        let fields =
2742
          ("parameters",
2743
            ((fun x  ->
2744
                `List (List.map (fun x  -> vhdl_parameter_t_to_yojson x) x))
2745
               x.parameters))
2746
          :: fields  in
2747
        let fields =
2748
          if x.typeMark = NoName
2749
          then fields
2750
          else
2751
            ("typeMark", (((fun x  -> vhdl_name_t_to_yojson x)) x.typeMark))
2752
            :: fields
2753
           in
2754
        let fields =
2755
          if x.name = ""
2756
          then fields
2757
          else
2758
            ("name",
2759
              (((fun (x : Ppx_deriving_runtime.string)  -> `String x)) x.name))
2760
            :: fields
2761
           in
2762
        `Assoc fields)
2763
  [@ocaml.warning "-A"])
2764
2765
and (vhdl_subprogram_spec_t_of_yojson :
2766
      Yojson.Safe.json ->
2767
        vhdl_subprogram_spec_t Ppx_deriving_yojson_runtime.error_or)
2768
  =
2769
  ((let open! Ppx_deriving_yojson_runtime in
2770
      function
2771
      | `Assoc xs ->
2772
          let rec loop xs ((arg0,arg1,arg2,arg3) as _state) =
2773
            match xs with
2774
            | ("name",x)::xs ->
2775
                loop xs
2776
                  (((function
2777
                     | `String x -> Result.Ok x
2778
                     | _ ->
2779
                         Result.Error "Vhdl_ast.vhdl_subprogram_spec_t.name")
2780
                      x), arg1, arg2, arg3)
2781
            | ("typeMark",x)::xs ->
2782
                loop xs
2783
                  (arg0, ((fun x  -> vhdl_name_t_of_yojson x) x), arg2, arg3)
2784
            | ("parameters",x)::xs ->
2785
                loop xs
2786
                  (arg0, arg1,
2787
                    ((function
2788
                      | `List xs ->
2789
                          map_bind (fun x  -> vhdl_parameter_t_of_yojson x)
2790
                            [] xs
2791
                      | _ ->
2792
                          Result.Error
2793
                            "Vhdl_ast.vhdl_subprogram_spec_t.parameters") x),
2794
                    arg3)
2795
            | ("isPure",x)::xs ->
2796
                loop xs
2797
                  (arg0, arg1, arg2,
2798
                    ((function
2799
                      | `Bool x -> Result.Ok x
2800
                      | _ ->
2801
                          Result.Error
2802
                            "Vhdl_ast.vhdl_subprogram_spec_t.isPure") x))
2803
            | [] ->
2804
                arg3 >>=
2805
                  ((fun arg3  ->
2806
                      arg2 >>=
2807
                        (fun arg2  ->
2808
                           arg1 >>=
2809
                             (fun arg1  ->
2810
                                arg0 >>=
2811
                                  (fun arg0  ->
2812
                                     Result.Ok
2813
                                       {
2814
                                         name = arg0;
2815
                                         typeMark = arg1;
2816
                                         parameters = arg2;
2817
                                         isPure = arg3
2818
                                       })))))
2819
            | _::xs -> loop xs _state  in
2820
          loop xs
2821
            ((Result.Ok ""), (Result.Ok NoName),
2822
              (Result.Error "Vhdl_ast.vhdl_subprogram_spec_t.parameters"),
2823
              (Result.Ok false))
2824
      | _ -> Result.Error "Vhdl_ast.vhdl_subprogram_spec_t")
2825
  [@ocaml.warning "-A"])
2826
2827
let arith_funs = ["+"; "-"; "*"; "/"; "mod"; "rem"; "abs"; "**"; "&"] 
2828
let bool_funs = ["and"; "or"; "nand"; "nor"; "xor"; "not"] 
2829
let rel_funs =
2830
  ["<";
2831
  ">";
2832
  "<=";
2833
  ">=";
2834
  "/=";
2835
  "=";
2836
  "?=";
2837
  "?/=";
2838
  "?<";
2839
  "?<=";
2840
  "?>";
2841
  "?>=";
2842
  "??"] 
2843
let shift_funs = ["sll"; "srl"; "sla"; "sra"; "rol"; "ror"] 
2844
type vhdl_sequential_stmt_t =
2845
  | VarAssign of
2846
  {
2847
  label: vhdl_name_t [@default NoName];
2848
  lhs: vhdl_name_t ;
2849
  rhs: vhdl_expr_t } [@name "VARIABLE_ASSIGNMENT_STATEMENT"]
2850
  | SigSeqAssign of
2851
  {
2852
  label: vhdl_name_t [@default NoName];
2853
  lhs: vhdl_name_t ;
2854
  rhs: vhdl_expr_t list } [@name "SIGNAL_ASSIGNMENT_STATEMENT"]
2855
  | If of
2856
  {
2857
  label: vhdl_name_t [@default NoName];
2858
  if_cases: vhdl_if_case_t list ;
2859
  default: vhdl_sequential_stmt_t list [@default []]} [@name "IF_STATEMENT"]
2860
  | Case of
2861
  {
2862
  label: vhdl_name_t [@default NoName];
2863
  guard: vhdl_expr_t ;
2864
  branches: vhdl_case_item_t list } [@name "CASE_STATEMENT_TREE"]
2865
  | Exit of
2866
  {
2867
  label: vhdl_name_t [@default NoName];
2868
  loop_label: string option [@default Some ""];
2869
  condition: vhdl_expr_t option [@default Some IsNull]}
2870
  [@name "EXIT_STATEMENT"]
2871
  | Assert of
2872
  {
2873
  label: vhdl_name_t [@default NoName];
2874
  cond: vhdl_expr_t ;
2875
  report: vhdl_expr_t [@default IsNull];
2876
  severity: vhdl_expr_t [@default IsNull]} [@name "ASSERTION_STATEMENT"]
2877 6d3b5007 Arnaud Dieumegard
  | ProcedureCall of
2878
  {
2879
  label: vhdl_name_t [@default NoName];
2880
  name: vhdl_name_t ;
2881
  assocs: vhdl_assoc_element_t list } [@name "PROCEDURE_CALL_STATEMENT"]
2882 40364f53 Arnaud Dieumegard
  | Wait [@name "WAIT_STATEMENT"]
2883
  | Null of {
2884
  label: vhdl_name_t [@default NoName]} [@name "NULL_STATEMENT"]
2885
  | Return of {
2886
  label: vhdl_name_t [@default NoName]} [@name "RETURN_STATEMENT"]
2887
and vhdl_if_case_t =
2888
  {
2889
  if_cond: vhdl_expr_t ;
2890
  if_block: vhdl_sequential_stmt_t list }
2891
and vhdl_case_item_t =
2892
  {
2893
  when_cond: vhdl_expr_t list ;
2894
  when_stmt: vhdl_sequential_stmt_t list }
2895
2896 6d3b5007 Arnaud Dieumegard
(* TODO Adapt for: Assert, ProcedureCall *)
2897 40364f53 Arnaud Dieumegard
let rec pp_vhdl_sequential_stmt_t :
2898
  Format.formatter -> vhdl_sequential_stmt_t -> Ppx_deriving_runtime.unit =
2899 6d3b5007 Arnaud Dieumegard
  let __22 () = pp_vhdl_name_t
2900
  
2901
  and __21 () = pp_vhdl_name_t
2902
  
2903
  and __20 () = pp_vhdl_assoc_element_t
2904
  
2905
  and __19 () = pp_vhdl_name_t
2906 40364f53 Arnaud Dieumegard
  
2907
  and __18 () = pp_vhdl_name_t
2908
  
2909
  and __17 () = pp_vhdl_expr_t
2910
  
2911
  and __16 () = pp_vhdl_expr_t
2912
  
2913
  and __15 () = pp_vhdl_expr_t
2914
  
2915
  and __14 () = pp_vhdl_name_t
2916
  
2917
  and __13 () = pp_vhdl_expr_t
2918
  
2919
  and __12 () = pp_vhdl_name_t
2920
  
2921
  and __11 () = pp_vhdl_case_item_t
2922
  
2923
  and __10 () = pp_vhdl_expr_t
2924
  
2925
  and __9 () = pp_vhdl_name_t
2926
  
2927
  and __8 () = pp_vhdl_sequential_stmt_t
2928
  
2929
  and __7 () = pp_vhdl_if_case_t
2930
  
2931
  and __6 () = pp_vhdl_name_t
2932
  
2933
  and __5 () = pp_vhdl_expr_t
2934
  
2935
  and __4 () = pp_vhdl_name_t
2936
  
2937
  and __3 () = pp_vhdl_name_t
2938
  
2939
  and __2 () = pp_vhdl_expr_t
2940
  
2941
  and __1 () = pp_vhdl_name_t
2942
  
2943
  and __0 () = pp_vhdl_name_t
2944
   in
2945
  ((let open! Ppx_deriving_runtime in
2946
      fun fmt  ->
2947
        function
2948
        | VarAssign { label = alabel; lhs = alhs; rhs = arhs } ->
2949 f779d524 Arnaud Dieumegard
            (match alabel with
2950
              | NoName -> Format.fprintf fmt "";
2951
              | _ -> (((__0 ()) fmt) alabel;
2952 1f15a1b9 Arnaud Dieumegard
                     Format.fprintf fmt ": ")
2953 f779d524 Arnaud Dieumegard
            );
2954
            ((__1 ()) fmt) alhs;
2955 1f15a1b9 Arnaud Dieumegard
            Format.fprintf fmt " := ";
2956 f779d524 Arnaud Dieumegard
            ((__2 ()) fmt) arhs;
2957
(* TODO: Check
2958 40364f53 Arnaud Dieumegard
            (Format.fprintf fmt "@[<2>VarAssign {@,";
2959
             (((Format.fprintf fmt "@[%s =@ " "label";
2960
                ((__0 ()) fmt) alabel;
2961
                Format.fprintf fmt "@]");
2962
               Format.fprintf fmt ";@ ";
2963
               Format.fprintf fmt "@[%s =@ " "lhs";
2964
               ((__1 ()) fmt) alhs;
2965
               Format.fprintf fmt "@]");
2966
              Format.fprintf fmt ";@ ";
2967
              Format.fprintf fmt "@[%s =@ " "rhs";
2968
              ((__2 ()) fmt) arhs;
2969
              Format.fprintf fmt "@]");
2970 f779d524 Arnaud Dieumegard
             Format.fprintf fmt "@]}") *)
2971 40364f53 Arnaud Dieumegard
        | SigSeqAssign { label = alabel; lhs = alhs; rhs = arhs } ->
2972 f779d524 Arnaud Dieumegard
            (match alabel with
2973
              | NoName -> Format.fprintf fmt "";
2974
              | _ -> (((__3 ()) fmt) alabel;
2975
                     Format.fprintf fmt ":@ ")
2976
            );
2977
            Format.fprintf fmt "@[<2>";
2978
            ((__4 ()) fmt) alhs;
2979
            Format.fprintf fmt "@ <=@ ";
2980
            ((fun x  ->
2981
               Format.fprintf fmt "@[";
2982
               ignore
2983
                 (List.fold_left
2984
                   (fun sep  ->
2985
                     fun x  ->
2986
                       if sep then Format.fprintf fmt "";
2987
                        ((__5 ()) fmt) x;
2988
                        true) false x);
2989 00970bbf Arnaud Dieumegard
            Format.fprintf fmt "@]@]")) arhs;
2990 40364f53 Arnaud Dieumegard
        | If { label = alabel; if_cases = aif_cases; default = adefault } ->
2991 f779d524 Arnaud Dieumegard
            (match alabel with
2992
              | NoName -> Format.fprintf fmt "";
2993
              | _ -> (((__6 ()) fmt) alabel;
2994
                     Format.fprintf fmt ":@ ")
2995
            );
2996
            Format.fprintf fmt "@[<v>if";
2997
            ((fun x ->
2998
               ignore
2999
               (List.fold_left
3000
                 (fun sep  ->
3001
                   fun x  ->
3002
                           if sep then Format.fprintf fmt "@;elseif";
3003
                                ((__7 ()) fmt) x;
3004
                                true
3005
                 ) false x);
3006
             )) aif_cases;
3007 00970bbf Arnaud Dieumegard
             (match adefault with
3008 f779d524 Arnaud Dieumegard
              | [] -> Format.fprintf fmt "";
3009
              | _  -> (Format.fprintf fmt "@;else";
3010
                      ((fun x  ->
3011
                          Format.fprintf fmt "@;<0 2>";
3012
                          ignore
3013
                            (List.fold_left
3014
                              (fun sep  ->
3015
                                fun x  ->
3016
                                        if sep then Format.fprintf fmt "";
3017
                          ((__8 ()) fmt) x;
3018 00970bbf Arnaud Dieumegard
                          true) false x))) adefault));
3019
            Format.fprintf fmt "@;end if;@]"
3020 40364f53 Arnaud Dieumegard
        | Case { label = alabel; guard = aguard; branches = abranches } ->
3021 f779d524 Arnaud Dieumegard
            (match alabel with
3022
              | NoName -> Format.fprintf fmt "";
3023
              | _ -> (((__9 ()) fmt) alabel;
3024
                     Format.fprintf fmt ":@ ")
3025
            );
3026
            Format.fprintf fmt "@[<v>case ";
3027
            ((__10 ()) fmt) aguard;
3028
            Format.fprintf fmt " is";
3029
            ((fun x  ->
3030
                ignore
3031
                  (List.fold_left
3032
                     (fun sep  ->
3033
                        fun x  ->
3034
                          if sep then Format.fprintf fmt "";
3035
                          ((__11 ()) fmt) x;
3036
                          true) false x);)) abranches;
3037 00970bbf Arnaud Dieumegard
            Format.fprintf fmt "@;end case;@]";
3038 40364f53 Arnaud Dieumegard
        | Exit
3039
            { label = alabel; loop_label = aloop_label;
3040
              condition = acondition }
3041
            ->
3042 52323a31 Arnaud Dieumegard
            (match alabel with
3043
              | NoName -> Format.fprintf fmt "";
3044
              | _ -> (((__12 ()) fmt) alabel;
3045
                     Format.fprintf fmt ":@ ")
3046
            );
3047
            Format.fprintf fmt "exit";
3048
            (match aloop_label with
3049
               | None  -> Format.pp_print_string fmt ""
3050
               | Some x -> (Format.fprintf fmt "@ %s@ ") x);
3051
            ((function
3052
               | None  -> Format.pp_print_string fmt ""
3053
               | Some x ->
3054
                   (Format.pp_print_string fmt "when@ ";
3055
                    ((__13 ()) fmt) x;))) acondition;
3056 40364f53 Arnaud Dieumegard
        | Assert
3057
            { label = alabel; cond = acond; report = areport;
3058
              severity = aseverity }
3059
            ->
3060
            (Format.fprintf fmt "@[<2>Assert {@,";
3061
             ((((Format.fprintf fmt "@[%s =@ " "label";
3062
                 ((__14 ()) fmt) alabel;
3063
                 Format.fprintf fmt "@]");
3064
                Format.fprintf fmt ";@ ";
3065
                Format.fprintf fmt "@[%s =@ " "cond";
3066
                ((__15 ()) fmt) acond;
3067
                Format.fprintf fmt "@]");
3068
               Format.fprintf fmt ";@ ";
3069
               Format.fprintf fmt "@[%s =@ " "report";
3070
               ((__16 ()) fmt) areport;
3071
               Format.fprintf fmt "@]");
3072
              Format.fprintf fmt ";@ ";
3073
              Format.fprintf fmt "@[%s =@ " "severity";
3074
              ((__17 ()) fmt) aseverity;
3075
              Format.fprintf fmt "@]");
3076
             Format.fprintf fmt "@]}")
3077 6d3b5007 Arnaud Dieumegard
        | ProcedureCall { label = alabel; name = aname; assocs = aassocs } ->
3078
            (match alabel with
3079
              | NoName -> Format.fprintf fmt "";
3080
              | _ -> (((__18 ()) fmt) alabel;
3081
                     Format.fprintf fmt ":@ ")
3082
            );
3083
            ((__19 ()) fmt) aname;
3084
            ((fun x  ->
3085
                Format.fprintf fmt "(";
3086
                ignore
3087
                  (List.fold_left
3088
                     (fun sep  ->
3089
                        fun x  ->
3090
                          if sep then Format.fprintf fmt ",@ ";
3091
                          ((__20 ()) fmt) x;
3092
                          true) false x);
3093
            Format.fprintf fmt ")")) aassocs;
3094 52323a31 Arnaud Dieumegard
        | Wait  -> Format.pp_print_string fmt "wait"
3095 40364f53 Arnaud Dieumegard
        | Null { label = alabel } ->
3096 52323a31 Arnaud Dieumegard
            (match alabel with
3097
              | NoName -> Format.fprintf fmt "";
3098
              | _ -> (((__18 ()) fmt) alabel;
3099
                     Format.fprintf fmt ":@ ")
3100
            );
3101
            Format.fprintf fmt "null";
3102 40364f53 Arnaud Dieumegard
        | Return { label = alabel } ->
3103 52323a31 Arnaud Dieumegard
            (match alabel with
3104
              | NoName -> Format.fprintf fmt "";
3105
              | _ -> (((__19 ()) fmt) alabel;
3106
                     Format.fprintf fmt ":@ ")
3107
            );
3108
            Format.fprintf fmt "return";)
3109 40364f53 Arnaud Dieumegard
    [@ocaml.warning "-A"])
3110
3111
and show_vhdl_sequential_stmt_t :
3112
  vhdl_sequential_stmt_t -> Ppx_deriving_runtime.string =
3113
  fun x  -> Format.asprintf "%a" pp_vhdl_sequential_stmt_t x
3114
3115
and pp_vhdl_if_case_t :
3116
  Format.formatter -> vhdl_if_case_t -> Ppx_deriving_runtime.unit =
3117
  let __1 () = pp_vhdl_sequential_stmt_t
3118
  
3119
  and __0 () = pp_vhdl_expr_t
3120
   in
3121
  ((let open! Ppx_deriving_runtime in
3122
      fun fmt  ->
3123
        fun x  ->
3124 f779d524 Arnaud Dieumegard
          Format.fprintf fmt " (";
3125
          ((__0 ()) fmt) x.if_cond;
3126
          Format.fprintf fmt ") then@;<0 2>";
3127
          ((fun x  ->
3128
             ignore
3129
               (List.fold_left
3130
                  (fun sep  ->
3131
                     fun x  ->
3132
                             if sep then Format.fprintf fmt "@;<0 2>";
3133
                       ((__1 ()) fmt) x;
3134
                       true) false x);
3135
          )) x.if_block;)
3136 40364f53 Arnaud Dieumegard
    [@ocaml.warning "-A"])
3137
3138
and show_vhdl_if_case_t : vhdl_if_case_t -> Ppx_deriving_runtime.string =
3139
  fun x  -> Format.asprintf "%a" pp_vhdl_if_case_t x
3140
3141
and pp_vhdl_case_item_t :
3142
  Format.formatter -> vhdl_case_item_t -> Ppx_deriving_runtime.unit =
3143
  let __1 () = pp_vhdl_sequential_stmt_t
3144
  
3145
  and __0 () = pp_vhdl_expr_t
3146
   in
3147
  ((let open! Ppx_deriving_runtime in
3148
      fun fmt  ->
3149
        fun x  ->
3150 1f15a1b9 Arnaud Dieumegard
                Format.fprintf fmt "@;@[<v 2>when ";
3151 40364f53 Arnaud Dieumegard
            ((fun x  ->
3152
                ignore
3153
                  (List.fold_left
3154
                     (fun sep  ->
3155
                        fun x  ->
3156 f779d524 Arnaud Dieumegard
                          if sep then Format.fprintf fmt "@ |@ ";
3157 40364f53 Arnaud Dieumegard
                          ((__0 ()) fmt) x;
3158 f779d524 Arnaud Dieumegard
                          true) false x);)) x.when_cond;
3159
           Format.fprintf fmt " => ";
3160 1f15a1b9 Arnaud Dieumegard
           (fun x  ->
3161 40364f53 Arnaud Dieumegard
               ignore
3162
                 (List.fold_left
3163
                    (fun sep  ->
3164
                       fun x  ->
3165 1f15a1b9 Arnaud Dieumegard
                         if sep then Format.fprintf fmt "@;";
3166 40364f53 Arnaud Dieumegard
                         ((__1 ()) fmt) x;
3167 1f15a1b9 Arnaud Dieumegard
                         Format.fprintf fmt ";";
3168
                         true) ((List.length x) > 1) x);) x.when_stmt;
3169
           Format.fprintf fmt "@]")
3170 40364f53 Arnaud Dieumegard
    [@ocaml.warning "-A"])
3171
3172
and show_vhdl_case_item_t : vhdl_case_item_t -> Ppx_deriving_runtime.string =
3173
  fun x  -> Format.asprintf "%a" pp_vhdl_case_item_t x
3174
3175
let rec (vhdl_sequential_stmt_t_to_yojson :
3176
          vhdl_sequential_stmt_t -> Yojson.Safe.json)
3177
  =
3178
  ((let open! Ppx_deriving_yojson_runtime in
3179
      function
3180
      | VarAssign arg0 ->
3181
          `List
3182
            [`String "VARIABLE_ASSIGNMENT_STATEMENT";
3183
            (let fields = []  in
3184
             let fields =
3185
               ("rhs", ((fun x  -> vhdl_expr_t_to_yojson x) arg0.rhs)) ::
3186
               fields  in
3187
             let fields =
3188
               ("lhs", ((fun x  -> vhdl_name_t_to_yojson x) arg0.lhs)) ::
3189
               fields  in
3190
             let fields =
3191
               if arg0.label = NoName
3192
               then fields
3193
               else
3194
                 ("label",
3195
                   (((fun x  -> vhdl_name_t_to_yojson x)) arg0.label))
3196
                 :: fields
3197
                in
3198
             `Assoc fields)]
3199
      | SigSeqAssign arg0 ->
3200
          `List
3201
            [`String "SIGNAL_ASSIGNMENT_STATEMENT";
3202
            (let fields = []  in
3203
             let fields =
3204
               ("rhs",
3205
                 ((fun x  ->
3206
                     `List (List.map (fun x  -> vhdl_expr_t_to_yojson x) x))
3207
                    arg0.rhs))
3208
               :: fields  in
3209
             let fields =
3210
               ("lhs", ((fun x  -> vhdl_name_t_to_yojson x) arg0.lhs)) ::
3211
               fields  in
3212
             let fields =
3213
               if arg0.label = NoName
3214
               then fields
3215
               else
3216
                 ("label",
3217
                   (((fun x  -> vhdl_name_t_to_yojson x)) arg0.label))
3218
                 :: fields
3219
                in
3220
             `Assoc fields)]
3221
      | If arg0 ->
3222
          `List
3223
            [`String "IF_STATEMENT";
3224
            (let fields = []  in
3225
             let fields =
3226
               if arg0.default = []
3227
               then fields
3228
               else
3229
                 ("default",
3230
                   (((fun x  ->
3231
                        `List
3232
                          (List.map
3233
                             (fun x  -> vhdl_sequential_stmt_t_to_yojson x) x)))
3234
                      arg0.default))
3235
                 :: fields
3236
                in
3237
             let fields =
3238
               ("if_cases",
3239
                 ((fun x  ->
3240
                     `List
3241
                       (List.map (fun x  -> vhdl_if_case_t_to_yojson x) x))
3242
                    arg0.if_cases))
3243
               :: fields  in
3244
             let fields =
3245
               if arg0.label = NoName
3246
               then fields
3247
               else
3248
                 ("label",
3249
                   (((fun x  -> vhdl_name_t_to_yojson x)) arg0.label))
3250
                 :: fields
3251
                in
3252
             `Assoc fields)]
3253
      | Case arg0 ->
3254
          `List
3255
            [`String "CASE_STATEMENT_TREE";
3256
            (let fields = []  in
3257
             let fields =
3258
               ("branches",
3259
                 ((fun x  ->
3260
                     `List
3261
                       (List.map (fun x  -> vhdl_case_item_t_to_yojson x) x))
3262
                    arg0.branches))
3263
               :: fields  in
3264
             let fields =
3265
               ("guard", ((fun x  -> vhdl_expr_t_to_yojson x) arg0.guard)) ::
3266
               fields  in
3267
             let fields =
3268
               if arg0.label = NoName
3269
               then fields
3270
               else
3271
                 ("label",
3272
                   (((fun x  -> vhdl_name_t_to_yojson x)) arg0.label))
3273
                 :: fields
3274
                in
3275
             `Assoc fields)]
3276
      | Exit arg0 ->
3277
          `List
3278
            [`String "EXIT_STATEMENT";
3279
            (let fields = []  in
3280
             let fields =
3281
               if arg0.condition = (Some IsNull)
3282
               then fields
3283
               else
3284
                 ("condition",
3285
                   (((function
3286
                      | None  -> `Null
3287
                      | Some x -> ((fun x  -> vhdl_expr_t_to_yojson x)) x))
3288
                      arg0.condition))
3289
                 :: fields
3290
                in
3291
             let fields =
3292
               if arg0.loop_label = (Some "")
3293
               then fields
3294
               else
3295
                 ("loop_label",
3296
                   (((function
3297
                      | None  -> `Null
3298
                      | Some x ->
3299
                          ((fun (x : Ppx_deriving_runtime.string)  ->
3300
                              `String x)) x)) arg0.loop_label))
3301
                 :: fields
3302
                in
3303
             let fields =
3304
               if arg0.label = NoName
3305
               then fields
3306
               else
3307
                 ("label",
3308
                   (((fun x  -> vhdl_name_t_to_yojson x)) arg0.label))
3309
                 :: fields
3310
                in
3311
             `Assoc fields)]
3312
      | Assert arg0 ->
3313
          `List
3314
            [`String "ASSERTION_STATEMENT";
3315
            (let fields = []  in
3316
             let fields =
3317
               if arg0.severity = IsNull
3318
               then fields
3319
               else
3320
                 ("severity",
3321
                   (((fun x  -> vhdl_expr_t_to_yojson x)) arg0.severity))
3322
                 :: fields
3323
                in
3324
             let fields =
3325
               if arg0.report = IsNull
3326
               then fields
3327
               else
3328
                 ("report",
3329
                   (((fun x  -> vhdl_expr_t_to_yojson x)) arg0.report))
3330
                 :: fields
3331
                in
3332
             let fields =
3333
               ("cond", ((fun x  -> vhdl_expr_t_to_yojson x) arg0.cond)) ::
3334
               fields  in
3335
             let fields =
3336
               if arg0.label = NoName
3337
               then fields
3338
               else
3339
                 ("label",
3340
                   (((fun x  -> vhdl_name_t_to_yojson x)) arg0.label))
3341
                 :: fields
3342
                in
3343
             `Assoc fields)]
3344 6d3b5007 Arnaud Dieumegard
      | ProcedureCall arg0 ->
3345
          `List
3346
            [`String "PROCEDURE_CALL_STATEMENT";
3347
            (let fields = []  in
3348
             let fields =
3349
               ("assocs",
3350
                 ((fun x  ->
3351
                     `List
3352
                       (List.map (fun x  -> vhdl_assoc_element_t_to_yojson x)
3353
                          x)) arg0.assocs))
3354
               :: fields  in
3355
             let fields =
3356
               ("name", ((fun x  -> vhdl_name_t_to_yojson x) arg0.name)) ::
3357
               fields  in
3358
             let fields =
3359
               if arg0.label = NoName
3360
               then fields
3361
               else
3362
                 ("label",
3363
                   (((fun x  -> vhdl_name_t_to_yojson x)) arg0.label))
3364
                 :: fields
3365
                in
3366
             `Assoc fields)]
3367 40364f53 Arnaud Dieumegard
      | Wait  -> `List [`String "WAIT_STATEMENT"]
3368
      | Null arg0 ->
3369
          `List
3370
            [`String "NULL_STATEMENT";
3371
            (let fields = []  in
3372
             let fields =
3373
               if arg0.label = NoName
3374
               then fields
3375
               else
3376
                 ("label",
3377
                   (((fun x  -> vhdl_name_t_to_yojson x)) arg0.label))
3378
                 :: fields
3379
                in
3380
             `Assoc fields)]
3381
      | Return arg0 ->
3382
          `List
3383
            [`String "RETURN_STATEMENT";
3384
            (let fields = []  in
3385
             let fields =
3386
               if arg0.label = NoName
3387
               then fields
3388
               else
3389
                 ("label",
3390
                   (((fun x  -> vhdl_name_t_to_yojson x)) arg0.label))
3391
                 :: fields
3392
                in
3393
             `Assoc fields)])
3394
  [@ocaml.warning "-A"])
3395
3396
and (vhdl_sequential_stmt_t_of_yojson :
3397
      Yojson.Safe.json ->
3398
        vhdl_sequential_stmt_t Ppx_deriving_yojson_runtime.error_or)
3399
  =
3400
  ((let open! Ppx_deriving_yojson_runtime in
3401
      function
3402
      | `List ((`String "VARIABLE_ASSIGNMENT_STATEMENT")::arg0::[]) ->
3403
          ((function
3404
            | `Assoc xs ->
3405
                let rec loop xs ((arg0,arg1,arg2) as _state) =
3406
                  match xs with
3407
                  | ("label",x)::xs ->
3408
                      loop xs
3409
                        (((fun x  -> vhdl_name_t_of_yojson x) x), arg1, arg2)
3410
                  | ("lhs",x)::xs ->
3411
                      loop xs
3412
                        (arg0, ((fun x  -> vhdl_name_t_of_yojson x) x), arg2)
3413
                  | ("rhs",x)::xs ->
3414
                      loop xs
3415
                        (arg0, arg1, ((fun x  -> vhdl_expr_t_of_yojson x) x))
3416
                  | [] ->
3417
                      arg2 >>=
3418
                        ((fun arg2  ->
3419
                            arg1 >>=
3420
                              (fun arg1  ->
3421
                                 arg0 >>=
3422
                                   (fun arg0  ->
3423
                                      Result.Ok
3424
                                        (VarAssign
3425
                                           {
3426
                                             label = arg0;
3427
                                             lhs = arg1;
3428
                                             rhs = arg2
3429
                                           })))))
3430
                  | _::xs -> loop xs _state  in
3431
                loop xs
3432
                  ((Result.Ok NoName),
3433
                    (Result.Error "Vhdl_ast.vhdl_sequential_stmt_t.lhs"),
3434
                    (Result.Error "Vhdl_ast.vhdl_sequential_stmt_t.rhs"))
3435
            | _ -> Result.Error "Vhdl_ast.vhdl_sequential_stmt_t")) arg0
3436
      | `List ((`String "SIGNAL_ASSIGNMENT_STATEMENT")::arg0::[]) ->
3437
          ((function
3438
            | `Assoc xs ->
3439
                let rec loop xs ((arg0,arg1,arg2) as _state) =
3440
                  match xs with
3441
                  | ("label",x)::xs ->
3442
                      loop xs
3443
                        (((fun x  -> vhdl_name_t_of_yojson x) x), arg1, arg2)
3444
                  | ("lhs",x)::xs ->
3445
                      loop xs
3446
                        (arg0, ((fun x  -> vhdl_name_t_of_yojson x) x), arg2)
3447
                  | ("rhs",x)::xs ->
3448
                      loop xs
3449
                        (arg0, arg1,
3450
                          ((function
3451
                            | `List xs ->
3452
                                map_bind (fun x  -> vhdl_expr_t_of_yojson x)
3453
                                  [] xs
3454
                            | _ ->
3455
                                Result.Error
3456
                                  "Vhdl_ast.vhdl_sequential_stmt_t.rhs") x))
3457
                  | [] ->
3458
                      arg2 >>=
3459
                        ((fun arg2  ->
3460
                            arg1 >>=
3461
                              (fun arg1  ->
3462
                                 arg0 >>=
3463
                                   (fun arg0  ->
3464
                                      Result.Ok
3465
                                        (SigSeqAssign
3466
                                           {
3467
                                             label = arg0;
3468
                                             lhs = arg1;
3469
                                             rhs = arg2
3470
                                           })))))
3471
                  | _::xs -> loop xs _state  in
3472
                loop xs
3473
                  ((Result.Ok NoName),
3474
                    (Result.Error "Vhdl_ast.vhdl_sequential_stmt_t.lhs"),
3475
                    (Result.Error "Vhdl_ast.vhdl_sequential_stmt_t.rhs"))
3476
            | _ -> Result.Error "Vhdl_ast.vhdl_sequential_stmt_t")) arg0
3477
      | `List ((`String "IF_STATEMENT")::arg0::[]) ->
3478
          ((function
3479
            | `Assoc xs ->
3480
                let rec loop xs ((arg0,arg1,arg2) as _state) =
3481
                  match xs with
3482
                  | ("label",x)::xs ->
3483
                      loop xs
3484
                        (((fun x  -> vhdl_name_t_of_yojson x) x), arg1, arg2)
3485
                  | ("if_cases",x)::xs ->
3486
                      loop xs
3487
                        (arg0,
3488
                          ((function
3489
                            | `List xs ->
3490
                                map_bind
3491
                                  (fun x  -> vhdl_if_case_t_of_yojson x) []
3492
                                  xs
3493
                            | _ ->
3494
                                Result.Error
3495
                                  "Vhdl_ast.vhdl_sequential_stmt_t.if_cases")
3496
                             x), arg2)
3497
                  | ("default",x)::xs ->
3498
                      loop xs
3499
                        (arg0, arg1,
3500
                          ((function
3501
                            | `List xs ->
3502
                                map_bind
3503
                                  (fun x  ->
3504
                                     vhdl_sequential_stmt_t_of_yojson x) []
3505
                                  xs
3506
                            | _ ->
3507
                                Result.Error
3508
                                  "Vhdl_ast.vhdl_sequential_stmt_t.default")
3509
                             x))
3510
                  | [] ->
3511
                      arg2 >>=
3512
                        ((fun arg2  ->
3513
                            arg1 >>=
3514
                              (fun arg1  ->
3515
                                 arg0 >>=
3516
                                   (fun arg0  ->
3517
                                      Result.Ok
3518
                                        (If
3519
                                           {
3520
                                             label = arg0;
3521
                                             if_cases = arg1;
3522
                                             default = arg2
3523
                                           })))))
3524
                  | _::xs -> loop xs _state  in
3525
                loop xs
3526
                  ((Result.Ok NoName),
3527
                    (Result.Error "Vhdl_ast.vhdl_sequential_stmt_t.if_cases"),
3528
                    (Result.Ok []))
3529
            | _ -> Result.Error "Vhdl_ast.vhdl_sequential_stmt_t")) arg0
3530
      | `List ((`String "CASE_STATEMENT_TREE")::arg0::[]) ->
3531
          ((function
3532
            | `Assoc xs ->
3533
                let rec loop xs ((arg0,arg1,arg2) as _state) =
3534
                  match xs with
3535
                  | ("label",x)::xs ->
3536
                      loop xs
3537
                        (((fun x  -> vhdl_name_t_of_yojson x) x), arg1, arg2)
3538
                  | ("guard",x)::xs ->