Project

General

Profile

Download (2.98 KB) Statistics
| Branch: | Tag: | Revision:
1
open Lustre_types
2
open Utils
3
   
4
let report = Log.report ~plugin:"seal"
5
let seal_debug = ref false
6

    
7
type 'boolexpr guard = 'boolexpr list           
8
type ('guard, 'elem)  guarded_expr = 'guard * 'elem
9

    
10
                        
11
type element = IsInit | Expr of expr
12
type elem_boolexpr = element * bool
13

    
14
type elem_guarded_expr = (elem_boolexpr guard, element) guarded_expr
15
type 'ge mdef_t = 'ge list 
16
                                   
17
               (*          
18
type mdef_t = guarded_expr list
19
                *)
20
                     
21
let pp_elem fmt e =
22
  match e with
23
  | IsInit -> Format.fprintf fmt "init"
24
  | Expr e -> Format.fprintf fmt "%a" Printers.pp_expr e 
25

    
26
let pp_guard_list pp_elem fmt gl =
27
  (fprintf_list ~sep:";@ "
28
     (fun fmt (e,b) -> if b then pp_elem fmt e else Format.fprintf fmt "not(%a)" pp_elem e)) fmt gl
29
  
30
let pp_guard_expr pp_elem  fmt (gl,e) =
31
  Format.fprintf fmt "@[%a@] -> @[<hov 2>%a@]"
32
    (pp_guard_list pp_elem) gl
33
    pp_elem e
34

    
35
let pp_mdefs pp_elem fmt gel = fprintf_list ~sep:"@ " (pp_guard_expr pp_elem) fmt gel
36

    
37
                             
38
  
39
let deelem e =  match e with
40
    Expr e -> e
41
  | IsInit -> assert false (* Wasn't expecting isinit here: we are building values! *)
42

    
43
let is_eq_elem elem elem' =
44
  match elem, elem' with
45
  | IsInit, IsInit -> true
46
  | Expr e, Expr e' -> Corelang.is_eq_expr e e' 
47
  | _ -> false
48

    
49
let select_elem elem (gelem, _) =
50
  is_eq_elem elem gelem
51

    
52
let pp_gl pp_expr =
53
  fprintf_list ~sep:", " (fun fmt (e,b) -> Format.fprintf fmt "%s%a" (if b then "" else "NOT ") pp_expr e)
54
  
55
let pp_gl_short = pp_gl (fun fmt e -> Format.fprintf fmt "%i" e.Lustre_types.expr_tag) 
56
let pp_up fmt up = List.iter (fun (id,e) -> Format.fprintf fmt "%s->%i; " id e.expr_tag) up 
57

    
58
let pp_sys fmt sw = List.iter (fun (gl,up) ->
59
                        match gl with
60
                        | None ->
61
                           pp_up fmt up
62
                        | Some gl ->
63
                           Format.fprintf fmt "[@[%a@]] -> (%a)@ "
64
                             Printers.pp_expr gl pp_up up) sw
65
let pp_all_defs =
66
  (Utils.fprintf_list ~sep:",@ "
67
     (fun fmt (id, gel) -> Format.fprintf fmt "%s -> [@[<v 0>%a]@]"
68
                             id
69
                             (pp_mdefs pp_elem) gel))              
70
module UpMap =
71
      struct
72
        include Map.Make (
73
                    struct
74
                      type t = (ident * expr) list
75
                      let compare l1 l2 =
76
                        let proj l = List.map (fun (s,e) -> s, e.expr_tag) l in
77
                        compare (proj l1) (proj l2) 
78
                    end)
79
        let pp = pp_up 
80
      end
81
    
82
module Guards = struct
83
  include Set.Make (
84
              struct
85
                type t = (expr * bool) 
86
                let compare l1 l2 =
87
                  let proj (e,b) = e.expr_tag, b in
88
                  compare (proj l1) (proj l2) 
89
              end)
90
  let pp_short fmt s = pp_gl_short fmt (elements s)
91
  let pp_long fmt s = pp_gl Printers.pp_expr fmt (elements s)
92
end
93
                  
94
        
(4-4/5)