Project

General

Profile

Download (19.9 KB) Statistics
| Branch: | Tag: | Revision:
1
(********************************************************************)
2
(*                                                                  *)
3
(*  The LustreC compiler toolset   /  The LustreC Development Team  *)
4
(*  Copyright 2012 -    --   ONERA - CNRS - INPT                    *)
5
(*                                                                  *)
6
(*  LustreC is free software, distributed WITHOUT ANY WARRANTY      *)
7
(*  under the terms of the GNU Lesser General Public License        *)
8
(*  version 2.1.                                                    *)
9
(*                                                                  *)
10
(********************************************************************)
11

    
12
open Lustre_types
13
open Format
14
open Utils
15

    
16
(* Prints [v] as [pp_fun] would do, but adds a backslash at each end of line,
17
   following the C convention for multiple lines macro *)
18
let pp_as_c_macro pp_fun fmt v =
19
  let formatter_out_funs = pp_get_formatter_out_functions fmt () in
20
  let macro_newline () =
21
    begin
22
      formatter_out_funs.out_string "\\" 0 1;
23
      formatter_out_funs.out_newline ()
24
    end in
25
  begin
26
    pp_set_formatter_out_functions fmt { formatter_out_funs with out_newline = macro_newline };
27
    pp_fun fmt v;
28
    pp_set_formatter_out_functions fmt formatter_out_funs;
29
  end
30

    
31
let rec pp_var_struct_type_field fmt (label, tdesc) =
32
  fprintf fmt "%a : %a;" pp_print_string label pp_var_type_dec_desc tdesc
33
and pp_var_type_dec_desc fmt tdesc =
34
  match tdesc with 
35
  | Tydec_any -> fprintf fmt "<any>"
36
  | Tydec_int -> fprintf fmt "int"
37
  | Tydec_real -> fprintf fmt "real"
38
  (* | Tydec_float -> fprintf fmt "float" *)
39
  | Tydec_bool -> fprintf fmt "bool"
40
  | Tydec_clock t -> fprintf fmt "%a clock" pp_var_type_dec_desc t
41
  | Tydec_const t -> fprintf fmt "%s" t
42
  | Tydec_enum id_list -> fprintf fmt "enum {%a }" (fprintf_list ~sep:", " pp_print_string) id_list
43
  | Tydec_struct f_list -> fprintf fmt "struct {%a }" (fprintf_list ~sep:" " pp_var_struct_type_field) f_list
44
  | Tydec_array (s, t) -> fprintf fmt "%a^%a" pp_var_type_dec_desc t Dimension.pp_dimension s
45

    
46
let pp_var_type_dec fmt ty =
47
  pp_var_type_dec_desc fmt ty.ty_dec_desc
48

    
49
let pp_var_name fmt id = fprintf fmt "%s" id.var_id
50
let pp_var_type fmt id =
51
  if !Options.print_dec_types then
52
    pp_var_type_dec fmt id.var_dec_type
53
  else
54
    Types.print_node_ty fmt id.var_type
55
let pp_var_clock fmt id = Clocks.print_ck_suffix fmt id.var_clock
56
  
57
let pp_eq_lhs = fprintf_list ~sep:", " pp_print_string
58

    
59
let pp_var fmt id =
60
  fprintf fmt "%s%s: %a"
61
    (if id.var_dec_const then "const " else "")
62
    id.var_id
63
    pp_var_type id
64

    
65
let pp_vars fmt vars =
66
  fprintf_list ~sep:"; " pp_var fmt vars
67
  
68
let pp_quantifiers fmt (q, vars) =
69
  match q with
70
    | Forall -> fprintf fmt "forall %a" pp_vars vars 
71
    | Exists -> fprintf fmt "exists %a" pp_vars vars 
72

    
73
let rec pp_struct_const_field fmt (label, c) =
74
  fprintf fmt "%a = %a;" pp_print_string label pp_const c
75
and pp_const fmt c = 
76
  match c with
77
    | Const_int i -> pp_print_int fmt i
78
    | Const_real (c, e, s) -> fprintf fmt "%s%s"
79
                                s
80
                                (if String.get s (-1 + String.length s) = '.' then "0" else "")
81
    (*if e = 0 then pp_print_int fmt c else if e < 0 then Format.fprintf fmt "%ie%i" c (-e) else Format.fprintf fmt "%ie-%i" c e *)
82
    (* | Const_float r -> pp_print_float fmt r *)
83
    | Const_tag  t -> pp_print_string fmt t
84
    | Const_array ca -> fprintf fmt "[%a]" (Utils.fprintf_list ~sep:"," pp_const) ca
85
    | Const_struct fl -> fprintf fmt "{%a }" (Utils.fprintf_list ~sep:" " pp_struct_const_field) fl
86

    
87
    (* used only for annotations *)
88
    | Const_string s -> pp_print_string fmt ("\"" ^ s ^ "\"")
89
    | Const_modeid s -> pp_print_string fmt ("\"" ^ s ^ "\"")
90

    
91

    
92
let pp_annot_key fmt kwds =
93
  match kwds with
94
  | [] -> assert false
95
  | [x] -> pp_print_string fmt x
96
  | _ -> fprintf fmt "/%a/" (fprintf_list ~sep:"/" pp_print_string) kwds
97

    
98
let rec pp_expr fmt expr =
99
  (match expr.expr_annot with 
100
  | None -> fprintf fmt "%t" 
101
  | Some ann -> fprintf fmt "@[(%a %t)@]" pp_expr_annot ann)
102
    (fun fmt -> 
103
      match expr.expr_desc with
104
    | Expr_const c -> pp_const fmt c
105
    | Expr_ident id -> fprintf fmt "%s" id
106
    | Expr_array a -> fprintf fmt "[%a]" pp_tuple a
107
    | Expr_access (a, d) -> fprintf fmt "%a[%a]" pp_expr a Dimension.pp_dimension d
108
    | Expr_power (a, d) -> fprintf fmt "(%a^%a)" pp_expr a Dimension.pp_dimension d
109
    | Expr_tuple el -> fprintf fmt "(%a)" pp_tuple el
110
    | Expr_ite (c, t, e) -> fprintf fmt "@[<hov 1>(if %a then@ @[<hov 2>%a@]@ else@ @[<hov 2>%a@]@])" pp_expr c pp_expr t pp_expr e
111
    | Expr_arrow (e1, e2) -> fprintf fmt "(%a -> %a)" pp_expr e1 pp_expr e2
112
    | Expr_fby (e1, e2) -> fprintf fmt "%a fby %a" pp_expr e1 pp_expr e2
113
    | Expr_pre e -> fprintf fmt "pre %a" pp_expr e
114
    | Expr_when (e, id, l) -> fprintf fmt "%a when %s(%s)" pp_expr e l id
115
    | Expr_merge (id, hl) -> 
116
      fprintf fmt "merge %s %a" id pp_handlers hl
117
    | Expr_appl (id, e, r) -> pp_app fmt id e r
118
    )
119
and pp_tuple fmt el =
120
 fprintf_list ~sep:"," pp_expr fmt el
121

    
122
and pp_handler fmt (t, h) =
123
 fprintf fmt "(%s -> %a)" t pp_expr h
124

    
125
and pp_handlers fmt hl =
126
 fprintf_list ~sep:" " pp_handler fmt hl
127

    
128
and pp_app fmt id e r =
129
  match r with
130
  | None -> pp_call fmt id e
131
  | Some c ->
132
     if !Options.kind2_print &&
133
          not (List.mem id Basic_library.internal_funs) then
134
       (* We only translate calls to nodes in kind2. The other may be
135
          rejected by Kind2 *)
136
       fprintf fmt "(restart %s every (%a)) (%a)"
137
         id
138
         pp_expr c
139
         pp_expr e
140
     else
141
       fprintf fmt "%t every (%a)" (fun fmt -> pp_call fmt id e) pp_expr c 
142

    
143
and pp_call fmt id e =
144
  match id, e.expr_desc with
145
  | "+", Expr_tuple([e1;e2]) -> fprintf fmt "(%a + %a)" pp_expr e1 pp_expr e2
146
  | "uminus", _ -> fprintf fmt "(- %a)" pp_expr e
147
  | "-", Expr_tuple([e1;e2]) -> fprintf fmt "(%a - %a)" pp_expr e1 pp_expr e2
148
  | "*", Expr_tuple([e1;e2]) -> fprintf fmt "(%a * %a)" pp_expr e1 pp_expr e2
149
  | "/", Expr_tuple([e1;e2]) -> fprintf fmt "(%a / %a)" pp_expr e1 pp_expr e2
150
  | "mod", Expr_tuple([e1;e2]) -> fprintf fmt "(%a mod %a)" pp_expr e1 pp_expr e2
151
  | "&&", Expr_tuple([e1;e2]) -> fprintf fmt "(%a and %a)" pp_expr e1 pp_expr e2
152
  | "||", Expr_tuple([e1;e2]) -> fprintf fmt "(%a or %a)" pp_expr e1 pp_expr e2
153
  | "xor", Expr_tuple([e1;e2]) -> fprintf fmt "(%a xor %a)" pp_expr e1 pp_expr e2
154
  | "impl", Expr_tuple([e1;e2]) -> fprintf fmt "(%a => %a)" pp_expr e1 pp_expr e2
155
  | "<", Expr_tuple([e1;e2]) -> fprintf fmt "(%a < %a)" pp_expr e1 pp_expr e2
156
  | "<=", Expr_tuple([e1;e2]) -> fprintf fmt "(%a <= %a)" pp_expr e1 pp_expr e2
157
  | ">", Expr_tuple([e1;e2]) -> fprintf fmt "(%a > %a)" pp_expr e1 pp_expr e2
158
  | ">=", Expr_tuple([e1;e2]) -> fprintf fmt "(%a >= %a)" pp_expr e1 pp_expr e2
159
  | "!=", Expr_tuple([e1;e2]) -> fprintf fmt "(%a <> %a)" pp_expr e1 pp_expr e2
160
  | "=", Expr_tuple([e1;e2]) -> fprintf fmt "(%a = %a)" pp_expr e1 pp_expr e2
161
  | "not", _ -> fprintf fmt "(not %a)" pp_expr e
162
  | _, Expr_tuple _ -> fprintf fmt "%s %a" id pp_expr e
163
  | _ -> fprintf fmt "%s (%a)" id pp_expr e
164

    
165
and pp_eexpr fmt e =
166
  fprintf fmt "%a%t %a"
167
    (Utils.fprintf_list ~sep:"; " pp_quantifiers) e.eexpr_quantifiers
168
    (fun fmt -> match e.eexpr_quantifiers with [] -> () | _ -> fprintf fmt ";")
169
    pp_expr e.eexpr_qfexpr
170

    
171
and  pp_sf_value fmt e =
172
   fprintf fmt "%a"
173
     (* (Utils.fprintf_list ~sep:"; " pp_quantifiers) e.eexpr_quantifiers *)
174
     (* (fun fmt -> match e.eexpr_quantifiers *)
175
     (*             with [] -> () *)
176
     (*                | _ -> fprintf fmt ";") *)
177
     pp_expr e.eexpr_qfexpr
178

    
179
and pp_s_function fmt expr_ann =
180
  let pp_annot fmt (kwds, ee) =
181
    fprintf fmt " %t : %a"
182
                   (fun fmt -> match kwds with
183
                               | [] -> assert false
184
                               | [x] -> pp_print_string fmt x
185
                               | _ -> fprintf fmt "%a" (fprintf_list ~sep:"/" pp_print_string) kwds)
186
                   pp_sf_value ee
187
  in
188
  fprintf_list ~sep:"@ " pp_annot fmt expr_ann.annots
189

    
190
and pp_expr_annot fmt expr_ann =
191
  let pp_annot fmt (kwds, ee) =
192
    fprintf fmt "(*!%a: %a; *)"
193
      pp_annot_key kwds
194
      pp_eexpr ee
195
  in
196
  fprintf_list ~sep:"@ " pp_annot fmt expr_ann.annots
197

    
198

    
199
let pp_asserts fmt asserts =
200
  match asserts with 
201
  | _::_ -> (
202
    fprintf fmt "(* Asserts definitions *)@ ";
203
    fprintf_list ~sep:"@ " (fun fmt assert_ -> 
204
      let expr = assert_.assert_expr in
205
      fprintf fmt "assert %a;" pp_expr expr 
206
    ) fmt asserts 
207
  )
208
  | _ -> ()
209

    
210
(*
211
let pp_node_var fmt id = fprintf fmt "%s%s: %a(%a)%a" (if id.var_dec_const then "const " else "") id.var_id print_dec_ty id.var_dec_type.ty_dec_desc Types.print_ty id.var_type Clocks.print_ck_suffix id.var_clock
212
*)
213
let pp_node_var fmt id =
214
  begin
215
    fprintf fmt "%s%s: %a%a"
216
      (if id.var_dec_const then "const " else "")
217
      id.var_id
218
      pp_var_type id
219
      pp_var_clock id;
220
    match id.var_dec_value with
221
    | None -> () 
222
    | Some v -> fprintf fmt " = %a" pp_expr v
223
  end 
224

    
225
let pp_node_args = fprintf_list ~sep:";@ " pp_node_var 
226

    
227
let pp_node_eq fmt eq = 
228
  fprintf fmt "%a = %a;" 
229
    pp_eq_lhs eq.eq_lhs
230
    pp_expr eq.eq_rhs
231

    
232
let pp_restart fmt restart =
233
  fprintf fmt "%s" (if restart then "restart" else "resume")
234

    
235
let pp_unless fmt (_, expr, restart, st) =
236
  fprintf fmt "unless %a %a %s"
237
    pp_expr expr
238
    pp_restart restart
239
    st
240

    
241
let pp_until fmt (_, expr, restart, st) =
242
  fprintf fmt "until %a %a %s"
243
    pp_expr expr
244
    pp_restart restart
245
    st
246

    
247
let rec pp_handler fmt handler =
248
  fprintf fmt "state %s:@ @[<v 2>  %a%t%alet@,@[<v 2>  %a@ %a@ %a@]@,tel@ %a@]"
249
    handler.hand_state
250
    (Utils.fprintf_list ~sep:"@ " pp_unless) handler.hand_unless
251
    (fun fmt -> if not ([] = handler.hand_unless) then fprintf fmt "@ ")
252
    (fun fmt locals ->
253
      match locals with [] -> () | _ ->
254
	fprintf fmt "@[<v 4>var %a@]@ " 
255
	  (Utils.fprintf_list ~sep:"@ " 
256
	     (fun fmt v -> fprintf fmt "%a;" pp_node_var v))
257
	  locals)
258
    handler.hand_locals
259
    (fprintf_list ~sep:"@ " pp_expr_annot) handler.hand_annots
260
    pp_node_stmts handler.hand_stmts
261
    pp_asserts handler.hand_asserts
262
    (Utils.fprintf_list ~sep:"@," pp_until) handler.hand_until
263

    
264
and pp_node_stmt fmt stmt =
265
  match stmt with
266
  | Eq eq -> pp_node_eq fmt eq
267
  | Aut aut -> pp_node_aut fmt aut
268

    
269
and pp_node_stmts fmt stmts = fprintf_list ~sep:"@ " pp_node_stmt fmt stmts
270

    
271
and pp_node_aut fmt aut =
272
  fprintf fmt "@[<v 0>automaton %s@,%a@]"
273
    aut.aut_id
274
    (Utils.fprintf_list ~sep:"@ " pp_handler) aut.aut_handlers
275

    
276
and pp_node_eqs fmt eqs = fprintf_list ~sep:"@ " pp_node_eq fmt eqs
277

    
278
let pp_typedef fmt ty =
279
  fprintf fmt "type %s = %a;" ty.tydef_id pp_var_type_dec_desc ty.tydef_desc
280

    
281
let pp_typedec fmt ty =
282
  fprintf fmt "type %s;" ty.tydec_id
283

    
284
(* let rec pp_var_type fmt ty =  *)
285
(*   fprintf fmt "%a" (match ty.tdesc with  *)
286
(*     | Tvar | Tarrow | Tlink | Tunivar -> assert false *)
287
(*     | Tint -> pp_print_string fmt "int" *)
288
(*     | Treal -> pp_print_string fmt "real" *)
289
(*     | Tbool -> pp_print_string fmt "bool" *)
290
(*     | Trat -> pp_print_string fmt "rat" *)
291
(*     | Tclock -> pp_print_string fmt "clock"  *)
292
(*     | Ttuple tel -> fprintf_list ~sep:" * " pp_var_type fmt tel *)
293
(*   ) *)
294

    
295

    
296

    
297
(* let pp_quantifiers fmt (q, vars) =
298
 *   match q with
299
 *     | Forall -> fprintf fmt "forall %a" pp_vars vars 
300
 *     | Exists -> fprintf fmt "exists %a" (fprintf_list ~sep:"; " pp_var) vars  *)
301

    
302
(*let pp_eexpr fmt e =
303
  fprintf fmt "%a%t %a"
304
    (Utils.fprintf_list ~sep:"; " pp_quantifiers) e.eexpr_quantifiers
305
    (fun fmt -> match e.eexpr_quantifiers with [] -> () | _ -> fprintf fmt ";")
306
    pp_expr e.eexpr_qfexpr
307
 *)
308
    
309
let pp_spec_eq fmt eq = 
310
  fprintf fmt "var %a : %a = %a;" 
311
    pp_eq_lhs eq.eq_lhs
312
    Types.print_node_ty eq.eq_rhs.expr_type
313
    pp_expr eq.eq_rhs
314
  
315
let pp_spec_stmt fmt stmt =
316
  match stmt with
317
  | Eq eq -> pp_spec_eq fmt eq
318
  | Aut aut -> assert false (* Not supported yet *)
319
             
320
  
321
let pp_spec fmt spec =
322
  (* const are prefixed with const in pp_var and with nothing for regular
323
     variables. We adapt the call to produce the appropriate output. *)
324
    fprintf_list ~eol:"@, " ~sep:"@, " (fun fmt v ->
325
    fprintf fmt "%a = %t;"
326
      pp_var v
327
      (fun fmt -> match v.var_dec_value with None -> assert false | Some e -> pp_expr fmt e)
328
    ) fmt spec.consts;
329
  
330
  fprintf_list ~eol:"@, " ~sep:"@, " (fun fmt s -> pp_spec_stmt fmt s) fmt spec.stmts;
331
  fprintf_list ~eol:"@, " ~sep:"@, " (fun fmt r -> fprintf fmt "assume %a;" pp_eexpr r) fmt spec.assume;
332
  fprintf_list ~eol:"@, " ~sep:"@, " (fun fmt r -> fprintf fmt "guarantee %a;" pp_eexpr r) fmt spec.guarantees;
333
  fprintf_list ~eol:"@, " ~sep:"@, " (fun fmt mode ->
334
    fprintf fmt "mode %s (@[<v 0>%a@ %a@]);" 
335
      mode.mode_id
336
      (fprintf_list ~eol:"" ~sep:"@ " (fun fmt r -> fprintf fmt "require %a;" pp_eexpr r)) mode.require
337
      (fprintf_list ~eol:"" ~sep:"@ " (fun fmt r -> fprintf fmt "ensure %a;" pp_eexpr r)) mode.ensure
338
  ) fmt spec.modes;
339
  fprintf_list ~eol:"@, " ~sep:"@, " (fun fmt import ->
340
    fprintf fmt "import %s (%a) returns (%a);" 
341
      import.import_nodeid
342
      pp_expr import.inputs
343
      pp_expr import.outputs
344
  ) fmt spec.imports
345

    
346
(* Project the contract node as a pure contract: local memories are pushed back in the contract definition. Should mainly be used to print it *) 
347
let node_as_contract nd =
348
  match nd.node_spec with
349
  | None | Some (NodeSpec _) -> raise (Invalid_argument "Not a contract")
350
  | Some (Contract c) -> (
351
    (* While a processed contract shall have no locals, sttms nor
352
       consts, an unprocessed one could. So we conservatively merge
353
       elements, to enable printing unprocessed contracts *)
354
    let consts, locals = List.partition(fun v -> v.var_dec_const) nd.node_locals in
355
    { c with
356
      consts = consts @ c.consts;
357
      locals = locals @ c.locals;
358
      stmts = nd.node_stmts @ c.stmts;
359
    }
360
  )
361

    
362
(* Printing top contract as comments in regular output and as contract
363
   in kind2 *)
364
let pp_contract fmt nd =    
365
   let c = node_as_contract nd in
366
  fprintf fmt "@[<v 2>%scontract %s(%a) returns (%a);@ "
367
    (if !Options.kind2_print then "" else "(*@")
368
    nd.node_id
369
    pp_node_args nd.node_inputs
370
    pp_node_args nd.node_outputs;
371
  fprintf fmt "@[<v 2>let@ ";
372
  pp_spec fmt c;
373
  fprintf fmt "@]@ tel@ @]%s@ "
374
  (if !Options.kind2_print then "" else "*)")
375
    
376
let pp_spec_as_comment fmt (inl, outl, spec) =
377
  match spec with
378
  | Contract c -> (* should have been processed by now *)
379
     fprintf fmt "@[<hov 2>(*@contract@ ";
380
     pp_spec fmt c;
381
     fprintf fmt "@]*)@ "
382
     
383
  | NodeSpec name -> (* Pushing stmts in contract. We update the
384
                      original information with the computed one in
385
                      nd. *)
386
     let pp_l = fprintf_list ~sep:"," pp_var_name in
387
     fprintf fmt "@[<hov 2>(*@contract import %s(%a) returns (%a); @]*)@ "
388
       name
389
       pp_l inl
390
       pp_l outl
391
     
392
              
393
let pp_node fmt nd =
394
  fprintf fmt "@[<v 0>";
395
  (* Prototype *)
396
  fprintf fmt  "%s @[<hov 0>%s (@[%a)@]@ returns (@[%a)@]@]@ "
397
    (if nd.node_dec_stateless then "function" else "node")
398
    nd.node_id
399
    pp_node_args nd.node_inputs
400
    pp_node_args nd.node_outputs;
401
  (* Contracts *)
402
  fprintf fmt "%a"
403
    (fun fmt s -> match s with Some s -> pp_spec_as_comment fmt (nd.node_inputs, nd.node_outputs, s) | _ -> ()) nd.node_spec
404
    (* (fun fmt -> match nd.node_spec with None -> () | Some _ -> fprintf fmt "@ ") *);
405
  (* Locals *)
406
  fprintf fmt "%a" (fun fmt locals ->
407
      match locals with [] -> () | _ ->
408
                                    fprintf fmt "@[<v 4>var %a@]@ " 
409
                                      (fprintf_list ~sep:"@ " 
410
	                                 (fun fmt v -> fprintf fmt "%a;" pp_node_var v))
411
                                      locals
412
    ) nd.node_locals;
413
  (* Checks *)
414
  fprintf fmt "%a"
415
    (fun fmt checks ->
416
      match checks with [] -> () | _ ->
417
                                    fprintf fmt "@[<v 4>check@ %a@]@ " 
418
                                      (fprintf_list ~sep:"@ " 
419
	                                 (fun fmt d -> fprintf fmt "%a" Dimension.pp_dimension d))
420
                                      checks
421
    ) nd.node_checks;
422
  (* Body *)
423
  fprintf fmt "let@[<h 2>   @ @[<v>";
424
  (* Annotations *)
425
  fprintf fmt "%a@ " (fprintf_list ~sep:"@ " pp_expr_annot) nd.node_annot;
426
  (* Statements *)
427
  fprintf fmt "%a@ " pp_node_stmts nd.node_stmts;
428
  (* Asserts *)    
429
  fprintf fmt "%a" pp_asserts nd.node_asserts;
430
  (* closing boxes body (2)  and node (1) *) 
431
  fprintf fmt "@]@]@ tel@]@ "
432

    
433

    
434
(*fprintf fmt "@ /* Scheduling: %a */ @ " (fprintf_list ~sep:", " pp_print_string) (Scheduling.schedule_node nd)*)
435

    
436
let pp_node fmt nd =
437
  match nd.node_spec, nd.node_iscontract with
438
  | None, false
439
    | Some (NodeSpec _), false 
440
    -> pp_node fmt nd
441
  | Some (Contract _), false -> pp_node fmt nd (* may happen early in the compil process *)
442
  | Some (Contract _), true -> pp_contract fmt nd 
443
  | _ -> assert false
444
     
445
let pp_imported_node fmt ind = 
446
  fprintf fmt "@[<v 0>";
447
  (* Prototype *)
448
  fprintf fmt  "%s @[<hov 0>%s (@[%a)@]@ returns (@[%a)@]@]@ "
449
    (if ind.nodei_stateless then "function" else "node")
450
    ind.nodei_id
451
    pp_node_args ind.nodei_inputs
452
    pp_node_args ind.nodei_outputs;
453
  (* Contracts *)
454
  fprintf fmt "%a%t"
455
    (fun fmt s -> match s with Some s -> pp_spec_as_comment fmt (ind.nodei_inputs, ind.nodei_outputs, s) | _ -> ()) ind.nodei_spec
456
    (fun fmt -> match ind.nodei_spec with None -> () | Some _ -> fprintf fmt "@ ");
457
  fprintf fmt "@]@ "
458
  
459

    
460
let pp_const_decl fmt cdecl =
461
  fprintf fmt "%s = %a;" cdecl.const_id pp_const cdecl.const_value
462

    
463
let pp_const_decl_list fmt clist = 
464
  fprintf_list ~sep:"@ " pp_const_decl fmt clist
465

    
466

    
467
  
468
let pp_decl fmt decl =
469
  match decl.top_decl_desc with
470
  | Node nd -> fprintf fmt "%a" pp_node nd
471
  | ImportedNode ind -> (* We do not print imported nodes *)
472
     fprintf fmt "(* imported %a; *)" pp_imported_node ind
473
  | Const c -> fprintf fmt "const %a" pp_const_decl c
474
  | Open (local, s) -> if local then fprintf fmt "#open \"%s\"" s else fprintf fmt "#open <%s>" s
475
  | Include s -> fprintf fmt "include \"%s\"" s
476
  | TypeDef tdef -> fprintf fmt "%a" pp_typedef tdef
477
  
478
let pp_prog fmt prog =
479
  (* we first print types: the function SortProg.sort could do the job but ut
480
     introduces a cyclic dependance *)
481

    
482
  let open_decl, prog =
483
    List.partition (fun decl -> match decl.top_decl_desc with Open _ -> true | _ -> false) prog
484
  in
485
  let type_decl, prog =
486
    List.partition (fun decl -> match decl.top_decl_desc with TypeDef _ -> true | _ -> false) prog
487
  in
488
  fprintf fmt "@[<v 0>%a@]" (fprintf_list ~sep:"@ " pp_decl) (open_decl@type_decl@prog)
489

    
490
(* Gives a short overview of model content. Do not print all node content *)
491
let pp_short_decl fmt decl =
492
  match decl.top_decl_desc with
493
  | Node nd -> fprintf fmt "node %s@ " nd.node_id
494
  | ImportedNode ind -> fprintf fmt "imported node %s" ind.nodei_id
495
  | Const c -> fprintf fmt "const %a@ " pp_const_decl c
496
  | Include s -> fprintf fmt "include \"%s\"" s
497
  | Open (local, s) -> if local then fprintf fmt "#open \"%s\"@ " s else fprintf fmt "#open <%s>@ " s
498
  | TypeDef tdef -> fprintf fmt "type %s;@ " tdef.tydef_id
499
  
500
let pp_lusi fmt decl = 
501
  match decl.top_decl_desc with
502
  | ImportedNode ind -> fprintf fmt "%a;@ " pp_imported_node ind
503
  | Const c -> fprintf fmt "const %a@ " pp_const_decl c
504
  | Include s -> fprintf fmt "include \"%s\"" s
505
  | Open (local, s) -> if local then fprintf fmt "#open \"%s\"@ " s else fprintf fmt "#open <%s>@ " s
506
  | TypeDef tdef -> fprintf fmt "%a@ " pp_typedef tdef
507
  | Node _ -> assert false
508
                
509
let pp_lusi_header fmt basename prog =
510
  fprintf fmt "@[<v 0>";
511
  fprintf fmt "(* Generated Lustre Interface file from %s.lus *)@ " basename;
512
  fprintf fmt "(* by Lustre-C compiler version %s, %a *)@ " Version.number pp_date (Unix.gmtime (Unix.time ()));
513
  fprintf fmt "(* Feel free to mask some of the definitions by removing them from this file. *)@ @ ";
514
  List.iter (fprintf fmt "%a@ " pp_lusi) prog;
515
  fprintf fmt "@]@."
516

    
517
let pp_offset fmt offset =
518
  match offset with
519
  | Index i -> fprintf fmt "[%a]" Dimension.pp_dimension i
520
  | Field f -> fprintf fmt ".%s" f
521

    
522
(* Local Variables: *)
523
(* compile-command:"make -C .." *)
524
(* End: *)
(55-55/67)