Project

General

Profile

« Previous | Next » 

Revision efc2cd2f

Added by Pierre-Loïc Garoche almost 5 years ago

[seal] more progress on seal extract

View differences:

src/tools/seal/seal_extract.ml
166 166
                Location.dummy_loc
167 167
                (Expr_const
168 168
                   (Const_real
169
                      (num, 0, s)))
169
                      (Real.create_num num s)))
170 170
            else if Z3.Arithmetic.is_int ze then
171 171
              mkexpr
172 172
                Location.dummy_loc
......
355 355
    Format.eprintf "After simplify: %a@." (pp_guard_list pp_elem) l; 
356 356
    Format.eprintf "@[<v 2>Z3 check sat: [%a]@ " (pp_guard_list pp_elem)l;
357 357
  );
358
  
358 359
  let solver = Z3.Solver.mk_simple_solver !ctx in
359 360
  try (
360 361
    let zl =
......
456 457
  (* Filtering out trivial cases. More semantics ones would have to be
457 458
     addressed later *)
458 459
  let check_sat e = (* temp function before we clean the original one *)
460
    (* Format.eprintf "CheckSAT? %a@." (pp_guard_list pp_elem) e; *)
459 461
    let ok, _ = check_sat e in
462
    (* Format.eprintf "CheckSAT DONE@."; *)
460 463
    ok
461 464
  in
462 465
  let implies (e1,pn1) (e2,pn2) =
......
580 583
    (* Rewrite the expression expr, replacing any occurence of a variable
581 584
   by its definition.
582 585
     *)
583
let rec rewrite defs expr : elem_guarded_expr list =
586
let rec rewrite defs expr : elem_guarded_expr list =   
584 587
  let rewrite = rewrite defs in
585 588
  let res =
586 589
    match expr.expr_desc with
587 590
    | Expr_appl (id, args, None) ->
588 591
       let args = rewrite args in
589 592
       List.map (fun (guards, e) ->
590
           guards,
591
           Expr (Corelang.mkexpr expr.expr_loc (Expr_appl(id, deelem e, None)))
593
       let new_e =
594
         Corelang.mkexpr
595
           expr.expr_loc
596
           (Expr_appl(id, deelem e, None))
597
       in
598
       guards,
599
       Expr (Corelang.partial_eval new_e) 
592 600
         ) args 
593 601
    | Expr_const _  -> [[], Expr expr]
594 602
    | Expr_ident id ->
......
640 648
                    fun accu (gl, minituple) ->
641 649
                    let is_compat, guard_comb = combine_guards g gl in
642 650
                    if is_compat then
643
                      let new_gt : elem_boolexpr guard * expr list = (guard_comb, (deelem e)::minituple) in
651
                      let new_gt : elem_boolexpr guard * expr list =
652
                        (guard_comb, (deelem e)::minituple) in
644 653
                      new_gt::accu
645 654
                    else
646 655
                      accu
......
655 664
         gtuples
656 665
    | Expr_fby _
657 666
      | Expr_appl _
658
                  (* Should be removed by mormalization and inlining *)
667
                  (* Should be removed by normalization and inlining *)
659 668
      -> Format.eprintf "Pb expr: %a@.@?" Printers.pp_expr expr; assert false
660 669
    | Expr_array _ | Expr_access _ | Expr_power _
661 670
                                                (* Arrays not handled here yet *)
......
668 677
   *   (Utils.fprintf_list ~sep:"@ "
669 678
   *        pp_guard_expr) res; *)
670 679
  res
680
  
671 681
and add_def defs vid expr =
672 682
  (* Format.eprintf "Add_def: %s = %a@."
673 683
   *   vid
......
676 686
  (* Format.eprintf "-> @[<v 0>%a@]@."
677 687
   *   (Utils.fprintf_list ~sep:"@ "
678 688
   *      (pp_guard_expr pp_elem)) vid_defs;   *)
679
  (* Format.eprintf "Add_def: %s = %a@. -> @[<v 0>%a@]@."
680
   *     vid
681
   *     Printers.pp_expr expr
682
   *     (
683
   *       (Utils.fprintf_list ~sep:"@ "
684
   *          pp_guard_expr)) vid_defs;  *)
685
  Hashtbl.add defs vid vid_defs
689
  report ~level:6 (fun fmt -> Format.fprintf fmt  "Add_def: %s = %a@. -> @[<v 0>%a@]@."
690
      vid
691
      Printers.pp_expr expr
692
      
693
      (
694
        (Utils.fprintf_list ~sep:"@ "
695
           (pp_guard_expr pp_elem))) vid_defs);
696
  Hashtbl.add defs vid vid_defs;
697
  vid_defs
686 698

  
687 699
(* Takes a list of guarded exprs (ge) and a guard
688 700
returns the same list of ge splited into the ones where the guard is true and the ones where it is false. In both lists the associated ge do not mention that guard anymore.
......
843 855
      (* Special cases to avoid useless computations: true, false conditions *)
844 856
      match elem.expr_desc with
845 857
      (*| Expr_ident "true"  ->   build_switch_sys pos prefix *)
846
      | Expr_const (Const_tag tag) when tag = Corelang.tag_true
858
      | Expr_const (Const_tag tag) when tag = tag_true
847 859
        ->   build_switch_sys pos prefix
848 860
      (*| Expr_ident "false" ->   build_switch_sys neg prefix *)
849
      | Expr_const (Const_tag tag) when tag = Corelang.tag_false 
861
      | Expr_const (Const_tag tag) when tag = tag_false 
850 862
        ->   build_switch_sys neg prefix
851 863
      | _ -> (* Regular case *)
852 864
         (* let _ = (
......
923 935
    List.iter (fun c -> Hashtbl.add const_defs c.const_id c.const_value) consts
924 936
  in
925 937

  
938
  report ~level:4 (fun fmt -> Format.fprintf fmt "Computing definitions for equations@.%a@."
939
                            Printers.pp_node_eqs sorted_eqs
940
    );
941
  
926 942
  
927 943
  (* Registering node equations: identifying mem definitions and
928 944
     storing others in the "defs" hashtbl.
......
941 957
               | Expr_pre def_m ->
942 958
                  report ~level:3 (fun fmt ->
943 959
                      Format.fprintf fmt "Preparing mem %s@." vid);
944
                  (vid, rewrite defs def_m)::accu_mems, accu_outputs
960
                  let def_vid = rewrite defs def_m in
961
                  report ~level:4 (fun fmt ->
962
                      Format.fprintf fmt "%s = %a@." vid
963
 (
964
        (Utils.fprintf_list ~sep:"@ "
965
           (pp_guard_expr pp_elem))) 
966
                        def_vid);
967
                  (vid, def_vid)::accu_mems, accu_outputs
945 968
               | _ -> assert false
946 969
             ) 
947 970
           else if List.exists (fun v -> v.var_id = vid) nd.node_outputs then (
948 971
             report ~level:3 (fun fmt ->
949 972
                 Format.fprintf fmt "Output variable %s@." vid);
950
             add_def vid eq.eq_rhs;
951
             accu_mems, (vid, rewrite defs eq.eq_rhs)::accu_outputs
973
             let def_vid = add_def vid eq.eq_rhs in
974
             accu_mems, (vid, def_vid)::accu_outputs
952 975
             
953 976
           )
954 977
           else
955 978
             (
956 979
               report ~level:3 (fun fmt ->
957 980
                   Format.fprintf fmt "Registering variable %s@." vid);
958
               add_def vid eq.eq_rhs;
981
               let _ = add_def vid eq.eq_rhs in
959 982
               accu_mems, accu_outputs
960 983
             )
961 984
        | _ -> assert false (* should have been removed by normalization *)
......
1200 1223
  if !seal_debug then Format.eprintf "Map: %i elements@ " (UpMap.cardinal map);
1201 1224
  UpMap.fold (fun up (common, disj) accu ->
1202 1225
      if !seal_debug then
1203
        Format.eprintf
1226
        report ~level:6 (fun fmt -> Format.fprintf fmt 
1204 1227
          "Guards:@.shared: [%a]@.disj: [@[<v 0>%a@ ]@]@.Updates: %a@."
1205 1228
          Guards.pp_short common
1206 1229
          (fprintf_list ~sep:";@ " Guards.pp_long) disj
1207
          UpMap.pp up;
1230
          UpMap.pp up);
1208 1231
      let disj = clean_disj disj in
1209 1232
      let guard_expr = (gl_as_expr common)@disj in
1210 1233
      
src/tools/seal/seal_utils.ml
43 43
let is_eq_elem elem elem' =
44 44
  match elem, elem' with
45 45
  | IsInit, IsInit -> true
46
  | Expr e, Expr e' -> e = e' (*
47
     Corelang.is_eq_expr e e' *)
46
  | Expr e, Expr e' -> Corelang.is_eq_expr e e' 
48 47
  | _ -> false
49 48

  
50 49
let select_elem elem (gelem, _) =
src/tools/seal/seal_verifier.ml
52 52
        machines; 
53 53
      exit 1
54 54
    )
55
    | s -> s
55
    | s -> ( (* should have been addessed before *)
56
      match Machine_code_common.get_machine_opt machines s with
57
      | None -> begin
58
          Global.main_node := s;
59
          Format.eprintf "Code generation error: %a@." Error.pp_error_msg Error.Main_not_found;
60
          raise (Corelang.Error (Location.dummy_loc, Error.Main_not_found))
61
        end
62
      | Some _ -> s
63
    )
56 64
  in
57 65
  let m = Machine_code_common.get_machine machines node_name in
58 66
  let nd = m.mname in
......
62 70
  let msch = Utils.desome m.msch in
63 71
  (* Format.eprintf "graph: %a@." Causality.pp_dep_graph deps; *)
64 72
  let sliced_nd = slice_node (mems@nd.node_outputs) msch nd in
65
  (* Format.eprintf "Sliced Node %a@." Printers.pp_node sliced_nd; *)
73
  if false then Format.eprintf "Sliced Node %a@." Printers.pp_node sliced_nd;
66 74
  report ~level:3 (fun fmt -> Format.fprintf fmt "Node sliced@.");
67 75

  
68 76
  let consts = Corelang.(List.map const_of_top (get_consts prog)) in
......
96 104
  report ~level:1 (fun fmt ->
97 105
      (*let pp_res = pp_res (fun fmt e -> Format.fprintf fmt "%i" e.Lustre_types.expr_tag)  in*)
98 106
       let pp_res = pp_res Printers.pp_expr in
99
      Format.fprintf fmt "@[<v 0>@[<v 3>Init:@ %a@]@ "
107
      Format.fprintf fmt "DynSys:@ @[<v 0>@[<v 3>Init:@ %a@]@ "
100 108
        pp_res  sw_init;
101 109
      Format.fprintf fmt "@[<v 3>Step:@ %a@]@]@ "
102 110
        pp_res  sw_sys
103 111
    );
112
  report ~level:1 (fun fmt ->
113
      (*let pp_res = pp_res (fun fmt e -> Format.fprintf fmt "%i" e.Lustre_types.expr_tag)  in*)
114
       let pp_res = pp_res Printers.pp_expr in
115
      Format.fprintf fmt "Output:@ @[<v 0>@[<v 3>Init:@ %a@]@ "
116
        pp_res  init_out;
117
      Format.fprintf fmt "@[<v 3>Step:@ %a@]@]@ "
118
        pp_res  update_out
119
    );
104 120
  let _ = match !seal_export with
105 121
    | Some "lustre" | Some "lus" ->
106 122
       Seal_export.to_lustre basename prog m sw_init sw_sys init_out update_out  
......
122 138
      ]
123 139
    let activate () =
124 140
      active := true;
125
      Options.global_inline := true
141
      Options.global_inline := true;
142
      Options.optimization := 0;
143
      Options.const_unfold := true;
144
      ()
126 145
      
127 146
    let is_active () = !active
128 147
    let run = seal_run
src/tools/zustre/zustre_common.ml
194 194

  
195 195
  (* Used to print boolean constants *)
196 196
let horn_tag_to_expr t =
197
  if t = Corelang.tag_true then
197
  if t = tag_true then
198 198
    Z3.Boolean.mk_true !ctx
199
  else if t = Corelang.tag_false then
199
  else if t = tag_false then
200 200
    Z3.Boolean.mk_false !ctx
201 201
  else
202 202
    (* Finding the associated sort *)
......
215 215
let rec horn_const_to_expr c =
216 216
  match c with
217 217
    | Const_int i    -> Z3.Arithmetic.Integer.mk_numeral_i !ctx i
218
    | Const_real (_,_,s)   -> Z3.Arithmetic.Real.mk_numeral_s !ctx s
218
    | Const_real r  -> Z3.Arithmetic.Real.mk_numeral_s !ctx (Real.to_string r)
219 219
    | Const_tag t    -> horn_tag_to_expr t
220 220
    | _              -> assert false
221 221

  
......
350 350
       (val_to_expr v1)
351 351
       (val_to_expr v2)
352 352

  
353
  | "int_to_real", [v1] ->
354
     Z3.Arithmetic.Integer.mk_int2real
355
       !ctx
356
       (val_to_expr v1)
353 357

  
354 358
    
355 359
  (* | _, [v1; v2] ->      Z3.Boolean.mk_and

Also available in: Unified diff