Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

lustrec / src / clocks.ml @ d52e7821

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
(* Returns the clock root of a clock *)
358
let rec root ck =
359
  match (repr ck).cdesc with
360
  | Ctuple (ck'::_)
361
  | Con (ck',_,_) | Clink ck' | Ccarrying (_,ck') -> root ck'
362
  | Pck_up _ | Pck_down _ | Pck_phase _ | Pck_const _ | Cvar _ | Cunivar _ -> ck
363
  | Carrow _ | Ctuple _ -> failwith "Internal error root"
364

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

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

    
383
(* Disjunction relation between variables based upon their static clocks. *)
384
let disjoint ck1 ck2 =
385
 root ck1 = root ck2 && disjoint_branches (branch ck1) (branch ck2);;
386

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

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

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

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

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

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

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

    
612
(* Local Variables: *)
613
(* compile-command:"make -C .." *)
614
(* End: *)