Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

lustrec / src / backends / VHDL / vhdl_ast_deriving.ml @ ab6312e7

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