Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

lustrec / src / clocks.ml @ 7dedc5f0

History | View | Annotate | Download (19.3 KB)

1
(********************************************************************)
2
(*                                                                  *)
3
(*  The LustreC compiler toolset   /  The LustreC Development Team  *)
4
(*  Copyright 2012 -    --   ONERA - CNRS - INPT - LIFL             *)
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
(*  This file was originally from the Prelude compiler              *)
11
(*                                                                  *) 
12
(********************************************************************)
13

    
14
(** Clocks definitions and a few utility functions on clocks. *)
15
open Utils
16
open Format
17

    
18
(* Clock type sets, for subtyping. *)
19
type clock_set =
20
    CSet_all
21
  | CSet_pck of int*rat
22

    
23
(* Clock carriers basically correspond to the "c" in "x when c" *)
24
type carrier_desc =
25
  | Carry_const of ident
26
  | Carry_name
27
  | Carry_var
28
  | Carry_link of carrier_expr
29

    
30
(* Carriers are scoped, to detect clock extrusion. In other words, we
31
   check the scope of a clock carrier before generalizing it. *)
32
and carrier_expr =
33
    {mutable carrier_desc: carrier_desc;
34
     mutable carrier_scoped: bool;
35
     carrier_id: int}
36

    
37
type clock_expr =
38
    {mutable cdesc: clock_desc;
39
     mutable cscoped: bool;
40
     cid: int}
41

    
42
(* pck stands for periodic clock. Easier not to separate pck from other clocks *)
43
and clock_desc =
44
  | Carrow of clock_expr * clock_expr
45
  | Ctuple of clock_expr list
46
  | Con of clock_expr * carrier_expr * ident
47
  | Pck_up of clock_expr * int
48
  | Pck_down of clock_expr * int
49
  | Pck_phase of clock_expr * rat
50
  | Pck_const of int * rat
51
  | Cvar of clock_set (* Monomorphic clock variable *)
52
  | Cunivar of clock_set (* Polymorphic clock variable *)
53
  | Clink of clock_expr (* During unification, make links instead of substitutions *)
54
  | Ccarrying of carrier_expr * clock_expr
55

    
56
type error =
57
  | Clock_clash of clock_expr * clock_expr
58
  | Not_pck
59
  | Clock_set_mismatch of clock_expr * clock_set
60
  | Cannot_be_polymorphic of clock_expr
61
  | Invalid_imported_clock of clock_expr
62
  | Invalid_const of clock_expr
63
  | Factor_zero
64
  | Carrier_mismatch of carrier_expr * carrier_expr
65
  | Carrier_extrusion of clock_expr * carrier_expr
66
  | Clock_extrusion of clock_expr * clock_expr
67

    
68
exception Unify of clock_expr * clock_expr
69
exception Subsume of clock_expr * clock_set
70
exception Mismatch of carrier_expr * carrier_expr
71
exception Scope_carrier of carrier_expr
72
exception Scope_clock of clock_expr
73
exception Error of Location.t * error
74

    
75
let new_id = ref (-1)
76

    
77
let new_ck desc scoped =
78
  incr new_id; {cdesc=desc; cid = !new_id; cscoped = scoped}
79

    
80
let new_var scoped =
81
  new_ck (Cvar CSet_all) scoped
82

    
83
let new_univar () =
84
  new_ck (Cunivar CSet_all) false
85

    
86
let new_carrier_id = ref (-1)
87

    
88
let new_carrier desc scoped =
89
  incr new_carrier_id; {carrier_desc = desc;
90
                        carrier_id = !new_carrier_id;
91
                        carrier_scoped = scoped}
92

    
93
let new_carrier_name () =
94
  new_carrier Carry_name true
95

    
96
let rec repr =
97
  function
98
      {cdesc=Clink ck'} ->
99
        repr ck'
100
    | ck -> ck
101

    
102
let rec carrier_repr =
103
  function {carrier_desc = Carry_link cr'} -> carrier_repr cr'
104
    | cr -> cr
105

    
106
(** Splits [ck] into the [lhs,rhs] of an arrow clock. Expects an arrow clock
107
    (ensured by language syntax) *)
108
let split_arrow ck =
109
  match (repr ck).cdesc with
110
  | Carrow (cin,cout) -> cin,cout
111
    (* Functions are not first order, I don't think the var case
112
       needs to be considered here *)
113
  | _ -> failwith "Internal error: not an arrow clock"
114

    
115
let get_carrier_name ck =
116
 match (repr ck).cdesc with
117
 | Ccarrying (cr, _) -> Some cr
118
 | _                 -> None
119

    
120
let uncarrier ck =
121
 match ck.cdesc with
122
 | Ccarrying (_, ck') -> ck'
123
 | _                  -> ck
124

    
125
(* Removes all links in a clock. Only used for clocks
126
   simplification though. *)
127
let rec deep_repr ck =
128
  match ck.cdesc with
129
  | Carrow (ck1,ck2) ->
130
      new_ck (Carrow (deep_repr ck1, deep_repr ck2)) ck.cscoped
131
  | Ctuple cl ->
132
      new_ck (Ctuple (List.map deep_repr cl)) ck.cscoped
133
  | Con (ck', c, l) ->
134
      new_ck (Con (deep_repr ck', c, l)) ck.cscoped
135
  | Pck_up (ck',k) ->
136
      new_ck (Pck_up (deep_repr ck',k)) ck.cscoped
137
  | Pck_down (ck',k) ->
138
      new_ck (Pck_down (deep_repr ck',k)) ck.cscoped
139
  | Pck_phase (ck',q) ->
140
      new_ck (Pck_phase (deep_repr ck',q)) ck.cscoped
141
  | Pck_const (_,_) | Cvar _ | Cunivar _ -> ck
142
  | Clink ck' -> deep_repr ck'
143
  | Ccarrying (cr,ck') -> new_ck (Ccarrying (cr, deep_repr ck')) ck.cscoped
144

    
145
(** Splits ck into the [lhs,rhs] of an arrow clock. Expects an arrow clock
146
    (ensured by language syntax) *)
147
let split_arrow ck =
148
  match (repr ck).cdesc with
149
  | Carrow (cin,cout) -> cin,cout
150
  | _ -> failwith "Internal error: not an arrow clock"
151

    
152
(** Returns the clock corresponding to a clock list. *)
153
let clock_of_clock_list ckl =
154
  if (List.length ckl) > 1 then
155
    new_ck (Ctuple ckl) true
156
  else
157
    List.hd ckl
158

    
159
let clock_list_of_clock ck =
160
 match (repr ck).cdesc with
161
 | Ctuple cl -> cl
162
 | _         -> [ck]
163

    
164
let clock_on ck cr l =
165
 clock_of_clock_list (List.map (fun ck -> new_ck (Con (ck,cr,l)) true) (clock_list_of_clock ck))
166

    
167
let clock_of_impnode_clock ck =
168
  let ck = repr ck in
169
  match ck.cdesc with
170
  | Carrow _ | Clink _ | Cvar _ | Cunivar _ ->
171
      failwith "internal error clock_of_impnode_clock"
172
  | Ctuple cklist -> List.hd cklist
173
  | Con (_,_,_) | Pck_up (_,_) | Pck_down (_,_) | Pck_phase (_,_)
174
  | Pck_const (_,_) | Ccarrying (_,_) -> ck
175

    
176
(** [intersect set1 set2] returns the intersection of clock subsets
177
    [set1] and [set2]. *)
178
let intersect set1 set2 =
179
  match set1,set2 with
180
  | CSet_all,_ -> set2
181
  | _,CSet_all -> set1
182
  | CSet_pck (k,q), CSet_pck (k',q') ->
183
      let k'',q'' = lcm k k',max_rat q q' in
184
      CSet_pck (k'',q'')
185

    
186
(** [can_be_pck ck] returns true if [ck] "may be" a pclock (the uncertainty is
187
    due to clock variables) *)
188
let rec can_be_pck ck =
189
  match (repr ck).cdesc with
190
  | Pck_up (_,_) | Pck_down (_,_) | Pck_phase (_,_) | Pck_const (_,_)
191
  | Cvar _ | Cunivar _ ->
192
      true
193
  | Ccarrying (_,ck') -> can_be_pck ck
194
  | _ -> false
195

    
196
(** [is_concrete_pck ck] returns true if [ck] is a concrete [pck] (pck
197
    transformations applied to a pck constant) *)
198
let rec is_concrete_pck ck =
199
  match ck.cdesc with
200
  | Carrow (_,_) | Ctuple _ | Con (_,_,_)
201
  | Cvar _ | Cunivar _ -> false
202
  | Pck_up (ck',_) | Pck_down (ck',_) -> is_concrete_pck ck'
203
  | Pck_phase (ck',_) -> is_concrete_pck ck'
204
  | Pck_const (_,_) -> true
205
  | Clink ck' -> is_concrete_pck ck'
206
  | Ccarrying (_,ck') -> false
207

    
208
(** [is_polymorphic ck] returns true if [ck] is polymorphic. *)
209
let rec is_polymorphic ck =
210
  match ck.cdesc with
211
  | Cvar _ | Pck_const (_,_) -> false
212
  | Carrow (ck1,ck2) -> (is_polymorphic ck1) || (is_polymorphic ck2)
213
  | Ctuple ckl -> List.exists (fun c -> is_polymorphic c) ckl
214
  | Con (ck',_,_) -> is_polymorphic ck'
215
  | Pck_up (ck',_) | Pck_down (ck',_) -> is_polymorphic ck'
216
  | Pck_phase (ck',_) -> is_polymorphic ck'
217
  | Cunivar _ -> true
218
  | Clink ck' -> is_polymorphic ck'
219
  | Ccarrying (_,ck') -> is_polymorphic ck'
220

    
221
(** [constrained_vars_of_clock ck] returns the clock variables subject
222
    to sub-typing constraints appearing in clock [ck]. Removes duplicates *)
223
(* Used mainly for debug, non-linear complexity. *)
224
let rec constrained_vars_of_clock ck =
225
  let rec aux vars ck =
226
    match ck.cdesc with
227
    | Pck_const (_,_) ->
228
        vars
229
    | Cvar cset ->
230
        begin
231
          match cset with
232
          | CSet_all -> vars
233
          | _ ->
234
              list_union [ck] vars
235
        end
236
    | Carrow (ck1,ck2) ->
237
        let l = aux vars ck1 in
238
        aux l ck2
239
    | Ctuple ckl ->
240
        List.fold_left
241
          (fun acc ck' -> aux acc ck') 
242
          vars ckl
243
    | Con (ck',_,_) -> aux vars ck'
244
    | Pck_up (ck',_) | Pck_down (ck',_) -> aux vars ck'
245
    | Pck_phase (ck',_) -> aux vars ck'
246
    | Cunivar cset ->
247
        begin
248
          match cset with
249
          | CSet_all -> vars
250
          | _ -> list_union [ck] vars
251
        end
252
    | Clink ck' -> aux vars ck'
253
    | Ccarrying (_,ck') -> aux vars ck'
254
  in
255
  aux [] ck
256

    
257
let print_ckset fmt s =
258
  match s with
259
  | CSet_all -> ()
260
  | CSet_pck (k,q) ->
261
      let (a,b) = simplify_rat q in
262
      if k = 1 && a = 0 then
263
        fprintf fmt "<:P"
264
      else
265
        fprintf fmt "<:P_(%i,%a)" k print_rat (a,b)
266

    
267
let rec print_carrier fmt cr =
268
 (* (if cr.carrier_scoped then fprintf fmt "[%t]" else fprintf fmt "%t") (fun fmt -> *)
269
  match cr.carrier_desc with
270
  | Carry_const id -> fprintf fmt "%s" id
271
  | Carry_name ->
272
      fprintf fmt "_%s" (name_of_carrier cr.carrier_id)
273
  | Carry_var ->
274
    fprintf fmt "'%s" (name_of_carrier cr.carrier_id)
275
  | Carry_link cr' ->
276
    print_carrier fmt cr'
277

    
278
(* Simple pretty-printing, performs no simplifications. Linear
279
   complexity. For debug mainly. *)
280
let rec print_ck_long fmt ck =
281
  match ck.cdesc with
282
  | Carrow (ck1,ck2) ->
283
      fprintf fmt "%a->%a" print_ck_long ck1 print_ck_long ck2
284
  | Ctuple cklist ->
285
    fprintf fmt "(%a)"
286
      (fprintf_list ~sep:" * " print_ck_long) cklist
287
  | Con (ck,c,l) ->
288
    fprintf fmt "%a on %s(%a)" print_ck_long ck l print_carrier c
289
  | Pck_up (ck,k) ->
290
    fprintf fmt "%a*^%i" print_ck_long ck k
291
  | Pck_down (ck,k) ->
292
    fprintf fmt "%a/^%i" print_ck_long ck k
293
  | Pck_phase (ck,q) ->
294
    fprintf fmt "%a~>%a" print_ck_long ck print_rat (simplify_rat q)
295
  | Pck_const (n,p) ->
296
    fprintf fmt "(%i,%a)" n print_rat (simplify_rat p)
297
  | Cvar cset ->
298
    fprintf fmt "'_%i%a" ck.cid print_ckset cset
299
  | Cunivar cset ->
300
    fprintf fmt "'%i%a" ck.cid print_ckset cset
301
  | Clink ck' ->
302
    fprintf fmt "link %a" print_ck_long ck'
303
  | Ccarrying (cr,ck') ->
304
    fprintf fmt "(%a:%a)" print_carrier cr print_ck_long ck'
305

    
306
(** [period ck] returns the period of [ck]. Expects a constant pclock
307
    expression belonging to the correct clock set. *)
308
let rec period ck =
309
  let rec aux ck =
310
    match ck.cdesc with
311
    | Carrow (_,_) | Ctuple _ | Con (_,_,_)
312
    | Cvar _ | Cunivar _ ->
313
        failwith "internal error: can only compute period of const pck"
314
    | Pck_up (ck',k) ->
315
        (aux ck')/.(float_of_int k)
316
    | Pck_down (ck',k) ->
317
        (float_of_int k)*.(aux ck')
318
    | Pck_phase (ck',_) ->
319
        aux ck'
320
    | Pck_const (n,_) ->
321
        float_of_int n
322
    | Clink ck' -> aux ck'
323
    | Ccarrying (_,ck') -> aux ck'
324
  in
325
  int_of_float (aux ck)
326

    
327
(** [phase ck] returns the phase of [ck]. It is not expressed as a
328
    fraction of the period, but instead as an amount of time. Expects a
329
    constant expression belonging to the correct P_k *)
330
let phase ck =
331
  let rec aux ck =
332
  match ck.cdesc with
333
  | Carrow (_,_) | Ctuple _ | Con (_,_,_)
334
  | Cvar _ | Cunivar _ ->
335
      failwith "internal error: can only compute phase of const pck"
336
  | Pck_up (ck',_) ->
337
      aux ck'
338
  | Pck_down (ck',k) ->
339
      aux ck'
340
  | Pck_phase (ck',(a,b)) ->
341
      let n = period ck' in
342
      let (a',b') = aux ck' in
343
      sum_rat (a',b') (n*a,b)
344
  | Pck_const (n,(a,b)) ->
345
      (n*a,b)
346
  | Clink ck' -> aux ck'
347
  | Ccarrying (_,ck') -> aux ck'
348
  in
349
  let (a,b) = aux ck in
350
  simplify_rat (a,b)
351

    
352
let eq_carrier cr1 cr2 =
353
  match (carrier_repr cr1).carrier_desc, (carrier_repr cr2).carrier_desc with
354
 | Carry_const id1, Carry_const id2 -> id1 = id2
355
 | _                                -> cr1.carrier_id = cr2.carrier_id
356

    
357
let eq_clock ck1 ck2 =
358
 (repr ck1).cid = (repr ck2).cid
359

    
360
(* Returns the clock root of a clock *)
361
let rec root ck =
362
  let ck = repr ck in
363
  match ck.cdesc with
364
  | Ctuple (ck'::_)
365
  | Con (ck',_,_) | Clink ck' | Ccarrying (_,ck') -> root ck'
366
  | Pck_up _ | Pck_down _ | Pck_phase _ | Pck_const _ | Cvar _ | Cunivar _ -> ck
367
  | Carrow _ | Ctuple _ -> failwith "Internal error root"
368

    
369
(* Returns the branch of clock [ck] in its clock tree *)
370
let rec branch ck =
371
  let rec branch ck acc =
372
    match (repr ck).cdesc with
373
    | Ccarrying (_, ck) -> branch ck acc
374
    | Con (ck, cr, l)   -> branch ck ((cr, l) :: acc)
375
    | Ctuple (ck::_)    -> branch ck acc
376
    | Ctuple _
377
    | Carrow _          -> assert false
378
    | _                 -> acc
379
  in branch ck [];;
380

    
381
(* Tests whether clock branches [br1] nd [br2] are statically disjoint *)
382
let rec disjoint_branches br1 br2 =
383
 match br1, br2 with
384
 | []          , _
385
 | _           , []           -> false
386
 | (cr1,l1)::q1, (cr2,l2)::q2 -> eq_carrier cr1 cr2 && ((l1 <> l2) || disjoint_branches q1 q2);;
387

    
388
(* Disjunction relation between variables based upon their static clocks. *)
389
let disjoint ck1 ck2 =
390
  eq_clock (root ck1) (root ck2) && disjoint_branches (branch ck1) (branch ck2)
391

    
392
(** [normalize pck] returns the normal form of clock [pck]. *)
393
let normalize pck =
394
  let changed = ref true in
395
  let rec aux pck =
396
    match pck.cdesc with
397
    | Pck_up ({cdesc=Pck_up (pck',k')},k) ->
398
        changed:=true;
399
        new_ck (Pck_up (aux pck',k*k')) pck.cscoped
400
    | Pck_up ({cdesc=Pck_down (pck',k')},k) ->
401
        changed:=true;
402
        new_ck (Pck_down (new_ck (Pck_up (aux pck',k)) pck.cscoped,k')) pck.cscoped
403
    | Pck_up ({cdesc=Pck_phase (pck',(a,b))},k) ->
404
        changed:=true;
405
        new_ck (Pck_phase (new_ck (Pck_up (aux pck',k)) pck.cscoped,(a*k,b))) pck.cscoped
406
    | Pck_down ({cdesc=Pck_down (pck',k')},k) ->
407
        changed:=true;
408
        new_ck (Pck_down (aux pck',k*k')) pck.cscoped
409
    | Pck_down ({cdesc=Pck_phase (pck',(a,b))},k) ->
410
        changed:=true;
411
        new_ck (Pck_phase (new_ck (Pck_down (aux pck',k)) pck.cscoped,(a,b*k))) pck.cscoped
412
    | Pck_phase ({cdesc=Pck_phase (pck',(a',b'))},(a,b)) ->
413
        changed:=true;
414
        let (a'',b'') = sum_rat (a,b) (a',b') in
415
        new_ck (Pck_phase (aux pck',(a'',b''))) pck.cscoped
416
    | Pck_up (pck',k') ->
417
        new_ck (Pck_up (aux pck',k')) pck.cscoped
418
    | Pck_down (pck',k') ->
419
        new_ck (Pck_down (aux pck',k')) pck.cscoped
420
    | Pck_phase (pck',k') ->
421
        new_ck (Pck_phase (aux pck',k')) pck.cscoped
422
    | Ccarrying (cr,ck') ->
423
        new_ck (Ccarrying (cr, aux ck')) pck.cscoped
424
    | _ -> pck
425
  in
426
  let nf=ref pck in
427
  while !changed do
428
    changed:=false;
429
    nf:=aux !nf
430
  done;
431
  !nf
432

    
433
(** [canonize pck] reduces transformations of [pck] and removes
434
    identity transformations. Expects a normalized periodic clock ! *)
435
let canonize pck =
436
  let rec remove_id_trans pck =
437
    match pck.cdesc with
438
    | Pck_up (pck',1) | Pck_down (pck',1) | Pck_phase (pck',(0,_)) ->
439
        remove_id_trans pck'
440
    | _ -> pck
441
  in
442
  let pck =
443
    match pck.cdesc with
444
    | Pck_phase ({cdesc=Pck_down ({cdesc=Pck_up (v,k)},k')},k'') ->
445
        let gcd = gcd k k' in
446
        new_ck (Pck_phase
447
                  (new_ck (Pck_down
448
                             (new_ck (Pck_up (v,k/gcd)) pck.cscoped,k'/gcd))
449
                     pck.cscoped,k''))
450
          pck.cscoped
451
    | Pck_down ({cdesc=Pck_up (v,k)},k') ->
452
        let gcd = gcd k k' in
453
        new_ck (Pck_down (new_ck (Pck_up (v,k/gcd)) pck.cscoped,k'/gcd)) pck.cscoped
454
    | _ -> pck
455
  in
456
  remove_id_trans pck
457

    
458
(** [simplify pck] applies pclocks simplifications to [pck] *)
459
let simplify pck =
460
  if (is_concrete_pck pck) then
461
    let n = period pck in
462
    let (a,b) = phase pck in
463
    let phase' = simplify_rat (a,b*n) in 
464
    new_ck (Pck_const (n,phase')) pck.cscoped
465
  else
466
    let pck' = deep_repr pck in
467
    let nf_pck = normalize pck' in
468
    canonize nf_pck
469
        
470
let print_cvar fmt cvar =
471
  match cvar.cdesc with
472
  | Cvar cset ->
473
 (*
474
      if cvar.cscoped
475
      then
476
	fprintf fmt "[_%s%a]"
477
	  (name_of_type cvar.cid)
478
	  print_ckset cset
479
      else
480
 *)
481
	fprintf fmt "_%s%a"
482
	  (name_of_type cvar.cid)
483
	  print_ckset cset
484
  | Cunivar cset ->
485
 (*
486
      if cvar.cscoped
487
      then
488
	fprintf fmt "['%s%a]"
489
	  (name_of_type cvar.cid)
490
	  print_ckset cset
491
      else
492
 *)
493
	fprintf fmt "'%s%a"
494
	  (name_of_type cvar.cid)
495
	  print_ckset cset
496
  | _ -> failwith "Internal error print_cvar"
497

    
498
(* Nice pretty-printing. Simplifies expressions before printing them. Non-linear
499
   complexity. *)
500
let print_ck fmt ck =
501
  let rec aux fmt ck =
502
    let ck = simplify ck in
503
    match ck.cdesc with
504
    | Carrow (ck1,ck2) ->
505
      fprintf fmt "%a->%a" aux ck1 aux ck2
506
    | Ctuple cklist ->
507
      fprintf fmt "(%a)" 
508
	(fprintf_list ~sep:" * " aux) cklist
509
    | Con (ck,c,l) ->
510
      fprintf fmt "%a on %s(%a)" aux ck l print_carrier c
511
    | Pck_up (ck,k) ->
512
      fprintf fmt "%a*.%i" aux ck k
513
    | Pck_down (ck,k) ->
514
      fprintf fmt "%a/.%i" aux ck k
515
    | Pck_phase (ck,q) ->
516
      fprintf fmt "%a->.%a" aux ck print_rat (simplify_rat q)
517
    | Pck_const (n,p) ->
518
      fprintf fmt "(%i,%a)" n print_rat (simplify_rat p)
519
    | Cvar cset ->
520
(*
521
      if ck.cscoped
522
      then
523
        fprintf fmt "[_%s]" (name_of_type ck.cid)
524
      else
525
*)
526
	fprintf fmt "_%s" (name_of_type ck.cid)
527
    | Cunivar cset ->
528
(*
529
      if ck.cscoped
530
      then
531
        fprintf fmt "['%s]" (name_of_type ck.cid)
532
      else
533
*)
534
        fprintf fmt "'%s" (name_of_type ck.cid)
535
    | Clink ck' ->
536
        aux fmt ck'
537
    | Ccarrying (cr,ck') ->
538
      fprintf fmt "(%a:%a)" print_carrier cr aux ck'
539
  in
540
  let cvars = constrained_vars_of_clock ck in
541
  aux fmt ck;
542
  if cvars <> [] then
543
    fprintf fmt " (where %a)"
544
      (fprintf_list ~sep:", " print_cvar) cvars
545

    
546
(* prints only the Con components of a clock, useful for printing nodes *)
547
let rec print_ck_suffix fmt ck =
548
  let ck = simplify ck in
549
  match ck.cdesc with
550
  | Carrow _
551
  | Ctuple _
552
  | Cvar _
553
  | Cunivar _   -> ()
554
  | Con (ck,c,l) ->
555
    fprintf fmt "%a when %s(%a)" print_ck_suffix ck l print_carrier c
556
  | Clink ck' ->
557
    print_ck_suffix fmt ck'
558
  | Ccarrying (cr,ck') ->
559
    fprintf fmt "%a" print_ck_suffix ck'
560
  | _ -> assert false
561

    
562
let pp_error fmt = function
563
  | Clock_clash (ck1,ck2) ->
564
      reset_names ();
565
      fprintf fmt "Expected clock %a, got clock %a@."
566
      print_ck ck1
567
      print_ck ck2
568
  | Not_pck ->
569
    fprintf fmt "The clock of this expression must be periodic@."
570
  | Carrier_mismatch (cr1, cr2) ->
571
     fprintf fmt "Name clash. Expected clock %a, got clock %a@."
572
       print_carrier cr1
573
       print_carrier cr2
574
  | Clock_set_mismatch (ck,cset) ->
575
      reset_names ();
576
    fprintf fmt "Clock %a is not included in clock set %a@."
577
      print_ck ck
578
      print_ckset cset
579
  | Cannot_be_polymorphic ck ->
580
      reset_names ();
581
    fprintf fmt "The main node cannot have a polymorphic clock: %a@."
582
      print_ck ck
583
  | Invalid_imported_clock ck ->
584
      reset_names ();
585
    fprintf fmt "Not a valid imported node clock: %a@."
586
      print_ck ck
587
  | Invalid_const ck ->
588
      reset_names ();
589
    fprintf fmt "Clock %a is not a valid periodic clock@."
590
      print_ck ck;
591
  | Factor_zero ->
592
    fprintf fmt "Cannot apply clock transformation with factor 0@."
593
  | Carrier_extrusion (ck,cr) ->
594
    fprintf fmt "This node has clock@.%a@.It is invalid as %a escapes its scope@."
595
      print_ck ck
596
      print_carrier cr
597
  | Clock_extrusion (ck_node,ck) ->
598
    fprintf fmt "This node has clock@.%a@.It is invalid as %a escapes its scope@."
599
      print_ck ck_node
600
      print_ck ck
601

    
602
let const_of_carrier cr =
603
 match (carrier_repr cr).carrier_desc with
604
 | Carry_const id -> id
605
 | Carry_name
606
 | Carry_var
607
 | Carry_link _ -> (Format.eprintf "internal error: const_of_carrier %a@." print_carrier cr; assert false) (* TODO check this Xavier *)
608
 
609
let uneval const cr =
610
  (*Format.printf "Clocks.uneval %s %a@." const print_carrier cr;*)
611
  let cr = carrier_repr cr in
612
  match cr.carrier_desc with
613
  | Carry_var -> cr.carrier_desc <- Carry_const const
614
  | Carry_name -> cr.carrier_desc <- Carry_const const
615
  | _         -> assert false
616

    
617
(* Local Variables: *)
618
(* compile-command:"make -C .." *)
619
(* End: *)