Source file astV6Dump.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
open Lxm
open AstPredef
open AstV6
open AstCore
open Format
let rec (op2string : AstCore.by_pos_op -> string) =
fun op ->
match op with
| Predef_n(op) -> (AstPredef.op2string op.it)
| (CALL_n ne) -> string_of_node_exp ne.it
| (PRE_n ) -> "pre"
| (CURRENT_n) -> "current"
| (ARROW_n ) -> "->"
| (WHEN_n _ce) -> "when"
| (HAT_n ) -> "^"
| (CONCAT_n ) -> "|"
| (IDENT_n idref) -> Lv6Id.string_of_idref false idref
| (FBY_n ) -> "fby"
| (WITH_n(_,_,_)) -> "with"
| (TUPLE_n ) -> assert false
| (ARRAY_n ) -> assert false
| (ARRAY_ACCES_n _ ) -> assert false
| (ARRAY_SLICE_n _sl) -> assert false
| (STRUCT_ACCESS_n _fld) -> assert false
and t (os: Format.formatter) (tree: AstV6.t) =
match tree with
| PRPackBody(_sl,pbody) -> packbody os pbody
| PRPack_or_models(_,_) -> assert false
and packbody (os: Format.formatter) (pkg: AstV6.packbody) =
let dump_def (d: item_ident) =
try (
(match d with
| ConstItem id -> dump_const os (Hashtbl.find pkg.pk_const_table id)
| TypeItem id -> dump_type os (Hashtbl.find pkg.pk_type_table id)
| NodeItem (id,sparams) ->
let {src = lxm ; it = ninfo } = Hashtbl.find pkg.pk_node_table id in
dump_node os {src = lxm ; it = ninfo };
fprintf os " <<@\n" ;
fprintf os "@[<b 3>@ %a@]@\n" dump_static_param_list sparams;
fprintf os ">>\n"
);
Format.fprintf os "@\n"
)
with Not_found ->
print_string ("*** unable to find a definition for " ^
(match d with
ConstItem id
| TypeItem id
| NodeItem (id,_) -> Lv6Id.to_string id
)
);
flush stdout;
assert false
in
List.iter dump_def pkg.pk_def_list ;
and dump_const (os: Format.formatter) (x: const_info srcflagged) = (
let lxm = x.src and info = x.it in
fprintf os "-- %s@\n" (Lxm.details lxm) ;
fprintf os "const %s " (Lxm.str lxm) ;
dump_const_def os info ;
fprintf os " ;@\n" ;
)
and dump_const_def (os: Format.formatter) (info: const_info) = (
match info with
| ExternalConst (_id, ty,None) -> fprintf os ": %a " dump_type_exp ty
| ExternalConst (_id, ty, Some v) ->
fprintf os ": %a = %a" dump_type_exp ty dump_val_exp v
| DefinedConst (_id, None, exp) -> fprintf os "= %a " dump_val_exp exp
| DefinedConst (_id, Some ty, exp) ->
fprintf os ": %a = %a " dump_type_exp ty dump_val_exp exp
| EnumConst (_id, _ty) -> fprintf os "XXX printme!"
)
and dump_type (os: Format.formatter) (x: type_info srcflagged) = (
let lxm = x.src and info = x.it in
let id = Lxm.str lxm in
fprintf os "-- %s@\n" (Lxm.details lxm) ;
fprintf os "type %s " id ;
dump_type_def os info ;
fprintf os " ;@\n" ;
)
and dump_type_def (os: Format.formatter) (info: type_info ) = (
match info with
| ExternalType _id -> ()
| AliasedType (_id, te) -> fprintf os "= %a" dump_type_exp te
| EnumType (_id, clist) ->
fprintf os "= enum { %a}" dump_id_list clist
| StructType {st_name = _id; st_flist = fl; st_ftable = ft} ->
let filst = List.map (function id -> (Hashtbl.find ft id).it) fl in
fprintf os "= struct {@\n@[<b 3> %a@]@\n}"
dump_field_list filst
| ArrayType (_id, texp, vexp) ->
fprintf os " = %a" dump_type_exp texp;
fprintf os "^%a" dump_val_exp vexp;
)
and dump_id_list (os : formatter) (idlst : Lv6Id.t srcflagged list) = (
match idlst with
[] -> ()
| h::[] -> ( fprintf os "%s" (Lv6Id.to_string h.it))
| h::t -> ( fprintf os "%s, %a" (Lv6Id.to_string h.it) dump_id_list t)
)
and dump_field_list (os: Format.formatter) (filst: field_info list) = (
match filst with
[] -> ()
| h::[] -> ( fprintf os "%a" dump_field h )
| h::t -> ( fprintf os "%a;@\n%a" dump_field h dump_field_list t)
)
and dump_field (os: Format.formatter) (finfo: field_info) = (
match finfo with
{fd_name=id; fd_type=ty; fd_value=None} -> (
fprintf os "%s : %a" (Lv6Id.to_string id) dump_type_exp ty
)
|
{fd_name=id; fd_type=ty; fd_value=Some ex} -> (
fprintf os "%s : %a = %a" (Lv6Id.to_string id)
dump_type_exp ty dump_val_exp ex
)
)
and _dump_param_list
(os: Format.formatter)
(plst: (Lv6Id.t option * type_exp) list) =
(
match plst with
[] -> ()
| h::[] -> ( fprintf os "%a" _dump_param h )
| h::t -> ( fprintf os "%a; %a" _dump_param h _dump_param_list t)
)
and _dump_param (os: Format.formatter) (p: (Lv6Id.t option * type_exp)) = (
match p with
(None, ty) -> (fprintf os "%a" dump_type_exp ty)
| (Some id, ty) -> (fprintf os "%s : %a" (Lv6Id.to_string id) dump_type_exp ty)
)
and dump_item_info_list
(os: Format.formatter)
(lst: item_info srcflagged list) =
(
match lst with
[] -> ()
| h::[] -> dump_item_info os h
| h::t -> fprintf os "%a;@\n%a" dump_item_info h dump_item_info_list t
)
and dump_item_info
(os: Format.formatter)
(ie: item_info srcflagged) = (
match ie.it with
| ConstInfo ci -> dump_const os (Lxm.flagit ci ie.src)
| TypeInfo ti -> dump_type os (Lxm.flagit ti ie.src)
| NodeInfo ni -> dump_node os (Lxm.flagit ni ie.src)
)
and dump_static_param_list
(os: Format.formatter)
(lst: static_param srcflagged list) =
(
match lst with
[] -> ()
| h::[] -> dump_static_param os h
| h::t -> fprintf os "%a;@\n%a" dump_static_param h dump_static_param_list t
)
and dump_static_param
(os: Format.formatter)
(sp: static_param srcflagged) =
(
match sp.it with
| StaticParamType id -> fprintf os "type %s" (Lv6Id.to_string id)
| StaticParamConst (id, exp) -> fprintf os "const %s : %a"
(Lv6Id.to_string id) dump_type_exp exp
| StaticParamNode (id, ins, outs, has_mem,is_safe) -> (
fprintf os "%s%s %s(@,%a@,)returns(@,%a@,)"
(if is_safe then "" else "unsafe ")
(if has_mem then "node" else "function")
(Lv6Id.to_string id)
dump_line_var_decl_list ins dump_line_var_decl_list outs
)
)
and dump_node (os: Format.formatter) (x: node_info srcflagged) = (
let lxm = x.src and ninfo = x.it in
fprintf os "-- %s" (Lxm.details lxm) ;
fprintf os " (node definition)@\n" ;
fprintf os "node %s" (Lv6Id.to_string ninfo.name);
fprintf os " <<@\n" ;
fprintf os "@[<b 3>@ %a@]@\n" dump_static_param_list ninfo.static_params;
fprintf os ">>\n";
(match ninfo.vars with
| None -> ()
| Some {
inlist = inlist;
outlist = outlist;
loclist = loclist_opt;
vartable = vartab;
} ->
let get_info (id: Lv6Id.t) = (Hashtbl.find vartab id).it in
let inlst = List.map get_info inlist in
let outlst = List.map get_info outlist in
fprintf os "(@\n" ;
fprintf os "@[<b 3>@ %a@]@\n" dump_var_decl_list inlst ;
fprintf os ") returns (@\n" ;
fprintf os "@[<b 3>@ %a@]@\n" dump_var_decl_list outlst ;
fprintf os ");@\n" ;
match loclist_opt with
| None -> ()
| Some loclist ->
let loclst = List.map get_info loclist in
fprintf os "var@\n";
fprintf os "@[<b 3> %a;@]@\n" dump_var_decl_list loclst;
);
(match ninfo.def with
| Extern -> fprintf os "extern"
| Abstract -> fprintf os "abstract"
| Body body -> dump_node_body os body
| Alias {it = _nexp; src = _lxm} -> assert false
);
if ninfo.has_mem then () else ();
if ninfo.is_safe then () else ();
)
and dump_node_body (os: Format.formatter) (nbody: node_body) = (
fprintf os "@[<b 3>let" ;
dump_assert_list os nbody.asserts ;
dump_eq_list os nbody.eqs ;
fprintf os "@]@\ntel" ;
)
and dump_var_decl_list (os: Format.formatter) (lst: var_info list) = (
match lst with
[] -> ()
| h::[] -> ( fprintf os "%a" dump_var_decl h )
| h::t -> ( fprintf os "%a;@\n%a" dump_var_decl h dump_var_decl_list t )
)
and dump_line_var_decl_list (os: Format.formatter) (lst: var_info srcflagged list) = (
match lst with
[] -> ()
| h::[] -> ( fprintf os "%a" dump_var_decl h.it )
| h::t -> ( fprintf os "%a;@,%a" dump_var_decl h.it dump_line_var_decl_list t )
)
and dump_var_decl (os: Format.formatter) (vinfo: var_info ) = (
fprintf os "%s : %a" (Lv6Id.to_string vinfo.var_name) dump_type_exp vinfo.var_type ;
(
match vinfo.var_clock with
Base -> ()
| NamedClock({it=cc,id;src=_lxm}) ->
let cc_str = Lv6Id.string_of_long false cc in
let id_str = Lv6Id.to_string id in
let clk_str =
if cc_str = "true" then id_str
else if cc_str = "false" then ("not " ^ id_str)
else (cc_str ^ "(" ^ id_str ^ ")")
in
(fprintf os " when %s" ) clk_str
)
)
and dump_type_exp (os: Format.formatter) (x: type_exp) = (
match x.it with
Bool_type_exp -> fprintf os "bool"
| Int_type_exp -> fprintf os "int"
| Real_type_exp -> fprintf os "real"
| Named_type_exp id -> fprintf os "%s" (Lv6Id.string_of_idref false id)
| Array_type_exp (te, sz) -> (
dump_type_exp os te ;
fprintf os "^" ;
dump_val_exp os sz
)
)
and dump_assert_list (os: Format.formatter) (af: (val_exp srcflagged) list) = (
match af with
[] -> ()
| a :: reste -> (
Format.fprintf os "@\nassert %a;" dump_val_exp a.it ;
Format.fprintf os "%a" dump_assert_list reste
)
)
and dump_eq_list (os: Format.formatter) (eqfs: (eq_info srcflagged) list) = (
match eqfs with
[] -> ()
| {it=(lflst,exp); src=_lxm} :: reste -> (
Format.fprintf os "@\n%a = %a;%a"
dump_left_part_list lflst
dump_val_exp exp
dump_eq_list reste
)
)
and dump_left_part_list (os: Format.formatter) (lfts: left_part list) =
(
match lfts with
l::[] -> dump_left_part os l
| l::reste -> fprintf os "%a,@,%a" dump_left_part l dump_left_part_list reste
| _ -> assert false
)
and dump_left_part (os: Format.formatter) (lft: left_part) =
(
match lft with
LeftVar idflg -> fprintf os "%s" (Lv6Id.to_string idflg.it)
| LeftField (l, idflg) -> fprintf os "%a.%s" dump_left_part l (Lv6Id.to_string idflg.it)
| LeftArray (l, expflg) ->
fprintf os "%a[@,%a@,]" dump_left_part l dump_val_exp expflg.it
| LeftSlice (l, slcflg) ->
fprintf os "%a[@,%a@,]" dump_left_part l dump_slice_info slcflg.it
)
and dump_val_exp (os: Format.formatter) (x: val_exp) = (
match x with
| CallByPos ( {it=oper; src=_lxm} , pars ) -> dump_by_pos_exp os oper pars
| CallByName ({it=oper; src=_lxm},nm_pars) -> dump_by_name_exp os oper nm_pars
| Merge_n (id, _) ->
fprintf os "merge %a (...) " dump_val_exp id.it
| Merge_bool_n({it=id;_}, t, f) ->
fprintf os "merge %a (true -> %a) (false -> %a)"
dump_val_exp id dump_val_exp t dump_val_exp f
)
and dump_val_exp_list (os : formatter) (xl: val_exp list) = (
match xl with
[] -> ()
| h::[] -> ( fprintf os "%a" dump_val_exp h )
| h::t -> ( fprintf os "%a,@,%a" dump_val_exp h dump_val_exp_list t)
)
and dump_by_pos_exp (os: Format.formatter) (oper: by_pos_op) (pars: operands) =
(
match (oper, pars) with
| (IDENT_n id,Oper []) -> dump_leaf_exp os (Lv6Id.string_of_idref false id)
| (PRE_n, Oper [p0]) -> dump_unary_exp os "pre" p0
| (CURRENT_n, Oper [p0]) -> dump_unary_exp os "current" p0
| (ARROW_n, Oper [p0;p1]) -> dump_binary_exp os "->" p0 p1
| (FBY_n, Oper [p0;p1]) -> dump_binary_exp os "fby" p0 p1
| (WHEN_n _, Oper [p0;p1]) -> dump_binary_exp os "when" p0 p1
| (Predef_n (x), _) -> (
match (x.it, pars) with
| (TRUE_n, Oper []) -> dump_leaf_exp os "true"
| (FALSE_n, Oper []) -> dump_leaf_exp os "false"
| (ICONST_n s, Oper []) -> dump_leaf_exp os (Lv6Id.to_string s)
| (RCONST_n s, Oper []) -> dump_leaf_exp os (Lv6Id.to_string s)
| (NOT_n, Oper [p0]) -> dump_unary_exp os "not" p0
| (UMINUS_n, Oper [p0]) -> dump_unary_exp os "-" p0
| (RUMINUS_n, Oper [p0]) -> dump_unary_exp os "-" p0
| (IUMINUS_n, Oper [p0]) -> dump_unary_exp os "-" p0
| (REAL2INT_n, Oper [p0]) -> dump_unary_exp os "int" p0
| (INT2REAL_n, Oper [p0]) -> dump_unary_exp os "real" p0
| (AND_n, Oper [p0;p1]) -> dump_binary_exp os "and" p0 p1
| (OR_n, Oper [p0;p1]) -> dump_binary_exp os "or" p0 p1
| (XOR_n, Oper [p0;p1]) -> dump_binary_exp os "xor" p0 p1
| (IMPL_n, Oper [p0;p1]) -> dump_binary_exp os "=>" p0 p1
| (EQ_n, Oper [p0;p1]) -> dump_binary_exp os "=" p0 p1
| (NEQ_n, Oper [p0;p1]) -> dump_binary_exp os "<>" p0 p1
| (LT_n, Oper [p0;p1]) -> dump_binary_exp os "<" p0 p1
| (LTE_n, Oper [p0;p1]) -> dump_binary_exp os "<=" p0 p1
| (GT_n, Oper [p0;p1]) -> dump_binary_exp os ">" p0 p1
| (GTE_n, Oper [p0;p1]) -> dump_binary_exp os ">=" p0 p1
| (DIV_n, Oper [p0;p1]) -> dump_binary_exp os "div" p0 p1
| (MOD_n, Oper [p0;p1]) -> dump_binary_exp os "mod" p0 p1
| (MINUS_n, Oper [p0;p1]) -> dump_binary_exp os "-" p0 p1
| (RMINUS_n, Oper [p0;p1]) -> dump_binary_exp os "-" p0 p1
| (IMINUS_n, Oper [p0;p1]) -> dump_binary_exp os "-" p0 p1
| (PLUS_n, Oper [p0;p1]) -> dump_binary_exp os "+" p0 p1
| (RPLUS_n, Oper [p0;p1]) -> dump_binary_exp os "+" p0 p1
| (IPLUS_n, Oper [p0;p1]) -> dump_binary_exp os "+" p0 p1
| (SLASH_n, Oper [p0;p1]) -> dump_binary_exp os "/" p0 p1
| (RSLASH_n, Oper [p0;p1]) -> dump_binary_exp os "/" p0 p1
| (ISLASH_n, Oper [p0;p1]) -> dump_binary_exp os "/" p0 p1
| (TIMES_n, Oper [p0;p1]) -> dump_binary_exp os "*" p0 p1
| (RTIMES_n, Oper [p0;p1]) -> dump_binary_exp os "*" p0 p1
| (ITIMES_n, Oper [p0;p1]) -> dump_binary_exp os "*" p0 p1
| (IF_n, Oper [p0;p1;p2]) -> dump_ternary_exp os "if" "then" "else" p0 p1 p2
| (NOR_n, Oper pl) -> dump_nary_exp os "nor" pl
| (DIESE_n, Oper pl) -> dump_nary_exp os "#" pl
| (_,_) -> (
Lv6errors.print_internal_error "AstV6Dump.dump_by_pos_exp"
(Printf.sprintf "unexpected op '%s'" (AstPredef.op2string_long x.it));
assert false
)
)
| (HAT_n, Oper [p0;p1]) -> dump_binary_exp os "^" p0 p1
| (CONCAT_n, Oper [p0;p1]) -> dump_binary_exp os "|" p0 p1
| (WITH_n(_), Oper [p0;p1;p2]) -> dump_ternary_exp os "with" "then" "else" p0 p1 p2
| (TUPLE_n, Oper pl) -> dump_nary_exp os "" pl
| (CALL_n s, Oper pl) -> fprintf os "%a(@,%a@,)"
dump_node_exp s.it dump_val_exp_list pl
| (ARRAY_n, Oper pl) -> fprintf os "[@,%a@,]" dump_val_exp_list pl
| (ARRAY_ACCES_n ix, Oper [p0]) -> fprintf os "%a[@,%a@,]"
dump_val_exp p0 dump_val_exp ix
| (ARRAY_SLICE_n sl, Oper [p0]) -> fprintf os "%a[@,%a@,]"
dump_val_exp p0 dump_slice_info sl
| (STRUCT_ACCESS_n fld, Oper [p0]) -> fprintf os "%a.%s"
dump_val_exp p0 (Lv6Id.to_string fld)
| (FBY_n, _) -> assert false
| (STRUCT_ACCESS_n _, _) -> assert false
| (ARRAY_SLICE_n _, _) -> assert false
| (ARRAY_ACCES_n _, _) -> assert false
| (WITH_n(_), _) -> assert false
| (CONCAT_n, _) -> assert false
| (HAT_n, _) -> assert false
| (WHEN_n _, _) -> assert false
| (ARROW_n, _) -> assert false
| (CURRENT_n, _) -> assert false
| (PRE_n, _) -> assert false
| (IDENT_n _, _) -> assert false
)
and dump_leaf_exp (os : Format.formatter) (s : string) = (
fprintf os "%s" s
)
and dump_unary_exp
(os : Format.formatter)
(s : string)
(op0: val_exp)
= (
fprintf os "(@,%s %a@,)" s dump_val_exp op0
)
and dump_binary_exp
(os : Format.formatter)
(s : string)
(op0: val_exp)
(op1: val_exp)
= (
fprintf os "(@,%a %s %a@,)" dump_val_exp op0 s dump_val_exp op1
)
and dump_ternary_exp
(os : Format.formatter)
(s : string)
(t : string)
(e : string)
(op0: val_exp)
(op1: val_exp)
(op2: val_exp)
= (
fprintf os "(@,%s %a %s %a %s %a@,)"
s dump_val_exp op0 t dump_val_exp op1 e dump_val_exp op2
)
and dump_nary_exp
(os : Format.formatter)
(s: string)
(ops: val_exp list)
= (
fprintf os "%s(@,%a@,)" s dump_val_exp_list ops
)
and string_of_node_exp (id, sal) =
(Lv6Id.string_of_idref false id) ^
(if sal = [] then "" else
"<<" ^ (String.concat ", " (List.map static_arg_to_string sal)) ^ ">>")
and static_arg_to_string arg =
match arg.it with
| StaticArgLv6Id id -> Lv6Id.string_of_idref false id
| StaticArgConst _ve -> "const xxx"
| StaticArgType _te -> "type xxx"
| StaticArgNode op -> "node "^(op2string op)
and dump_node_exp os ne =
fprintf os "%s" (string_of_node_exp ne)
and _dump_static_sarg_list
(os : Format.formatter)
(lst: (static_arg srcflagged) list)
= (
match lst with
| [] -> ()
| [sa] -> fprintf os "%a" _dump_static_sarg sa.it
| sa::reste ->
fprintf os "%a, @,%a" _dump_static_sarg sa.it _dump_static_sarg_list reste
)
and _dump_static_sarg
(os : Format.formatter)
(sa: static_arg)
=
match sa with
| StaticArgLv6Id id -> fprintf os "%s" (Lv6Id.string_of_idref false id)
| StaticArgConst ve -> fprintf os "const %a" dump_val_exp ve
| StaticArgType te -> fprintf os "type %a" dump_type_exp te
| StaticArgNode op -> fprintf os "node %s" (op2string op)
and dump_static_arg_list
(os : Format.formatter)
(lst: (Lv6Id.t * static_arg srcflagged) list)
= (
match lst with
| [] -> ()
| [sa] -> fprintf os "%a" dump_static_arg sa
| sa::reste ->
fprintf os "%a, @,%a" dump_static_arg sa dump_static_arg_list reste
)
and dump_static_arg
(os : Format.formatter)
((id,sa): Lv6Id.t * static_arg srcflagged)
=
fprintf os "%s = " (Lv6Id.to_string id);
match sa.it with
| StaticArgLv6Id id -> fprintf os "%s" (Lv6Id.string_of_idref false id)
| StaticArgConst ve -> fprintf os "const %a" dump_val_exp ve
| StaticArgType te -> fprintf os "type %a" dump_type_exp te
| StaticArgNode op -> fprintf os "node %s" (op2string op)
and dump_slice_info
(os : Format.formatter)
(sl: slice_info)
= (
fprintf os "%a@, .. @,%a" dump_val_exp sl.si_first dump_val_exp sl.si_last ;
match sl.si_step with
Some e -> fprintf os "@, step %a" dump_val_exp e
| None -> ()
)
and dump_by_name_exp
(os: Format.formatter)
(oper: by_name_op)
(pars: (Lv6Id.t srcflagged * val_exp) list) =
(
match (oper, pars) with
| (STRUCT_n id, pl) -> (
fprintf os "%s{@,%a@,}" (Lv6Id.string_of_idref false id) dump_named_pars pl
)
| (STRUCT_WITH_n (id1,id2), pl) -> (
fprintf os "%s{ %s with @,%a@,}" (Lv6Id.string_of_idref false id1)
(Lv6Id.string_of_idref false id2) dump_named_pars pl
)
| (STRUCT_anonymous_n, pl) -> (
fprintf os "{@,%a@,}" dump_named_pars pl
)
)
and dump_named_pars
(os: Format.formatter)
(pars: (Lv6Id.t srcflagged * val_exp) list) =
( match pars with
[] -> ()
|(v,e)::[] -> fprintf os "%s = %a" (Lv6Id.to_string v.it) dump_val_exp e
|(v,e)::l ->
fprintf os "%s = %a;@,%a" (Lv6Id.to_string v.it) dump_val_exp e
dump_named_pars l
)
let dump_packinstance (os: Format.formatter) (pi: AstV6.pack_instance) = (
Format.fprintf os "= %s(%a);@\n"
(Lv6Id.to_string pi.pi_model)
dump_static_arg_list pi.pi_args ;
)
let dump_packgiven (os: Format.formatter) (pg: AstV6.pack_given) = (
(
match (pg.pg_provides) with
Some pl -> (
Format.fprintf os "provides@\n@[<b 3> %a@]@,;@\n"
dump_item_info_list pl
) | _ -> ()
);
Format.fprintf os "body@\n@[<b 3> %a@]@\nend@\n"
packbody pg.pg_body ;
)
let packinfo (os: Format.formatter) (pf: AstV6.pack_info srcflagged) = (
let (p, lxm) = (pf.it, pf.src) in
Format.fprintf os "@?@[<b 0>" ;
Format.fprintf os "-----------------------------\n";
Format.fprintf os "-- PACKAGE DEF \"%s\"\n" (Lv6Id.pack_name_to_string p.pa_name);
Format.fprintf os "-----------------------------\n";
Format.fprintf os "-- %s\n" (Lxm.details lxm) ;
(
match (p.pa_def) with
PackGiven pg -> dump_packgiven os pg
| PackInstance pi -> dump_packinstance os pi
);
Format.fprintf os "-----------------------------\n";
Format.fprintf os "@]@."
)
let modelinfo (os: Format.formatter) (mf: AstV6.model_info srcflagged) = (
let (m, lxm) = (mf.it, mf.src) in
Format.fprintf os "@?@[<b 0>" ;
Format.fprintf os "-----------------------------\n";
Format.fprintf os "-- MODEL DEF \"%s\"\n" (Lv6Id.pack_name_to_string m.mo_name);
Format.fprintf os "-----------------------------\n";
Format.fprintf os "-- %s\n" (Lxm.details lxm) ;
Format.fprintf os "model %s@\n" (Lv6Id.pack_name_to_string m.mo_name);
( match (m.mo_needs) with
[] -> ()
| _ -> (
Format.fprintf os "needs@\n@[<b 3> %a@]@,;@\n"
dump_static_param_list m.mo_needs
)
);
( match (m.mo_provides) with
Some pl -> (
Format.fprintf os "provides@\n@[<b 3> %a@]@,;@\n"
dump_item_info_list pl
) | _ -> ()
);
Format.fprintf os "body@\n@[<b 3> %a@]@\nend@\n"
packbody m.mo_body ;
Format.fprintf os "-----------------------------\n";
Format.fprintf os "@]@."
)
let print_val_exp oc ve =
let os = Format.formatter_of_out_channel oc in
dump_val_exp os ve;
pp_print_flush os ()
let print_node_exp oc ne =
let os = Format.formatter_of_out_channel oc in
dump_node_exp os ne;
pp_print_flush os ()
let print_short_val_exp oc ve =
let os = Format.formatter_of_out_channel oc in
let fof : Format.formatter_out_functions =
pp_get_formatter_out_functions os ()
in
let fof = {
fof
with
Format.out_string = (fun s p n -> output_string oc (String.sub s p n));
Format.out_newline = (fun () -> ());
Format.out_spaces = (fun _ -> ());
Format.out_flush = (fun () -> flush oc);
}
in
Format.pp_set_formatter_out_functions os fof;
dump_val_exp os ve;
pp_print_flush os ()