Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

lustrec / src / main_lustre_verifier.ml @ 04a188ec

History | View | Annotate | Download (5.36 KB)

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 Format
13
open Log
14
open Compiler_common
15

    
16
open Utils
17
open Lustre_types
18
 
19

    
20
let usage = "Usage: lustrev [options] \x1b[4msource file\x1b[0m"
21

    
22
let extensions = [".ec"; ".lus"; ".lusi"]
23

    
24

    
25
(* verify a .lus source file 
26

    
27
we have multiple "backends"
28
- zustre: linked to z3/spacer. Shall preserve the structure and rely on contracts. Produces both a lustre model with new properties, maybe as a lusi with lustre contract, and a JSON summarizing the results and providing tests cases or counter examples if any
29

    
30
- seal: linked to seal. Require global inline and main node
31
  focuses only on the selected node (the main)
32
  map the machine code into SEAL datastructure and compute invariants
33
  - provides the node and its information (typical point of interest for taylor expansion, range for inputs, existing invariants, computation error for the node content)
34
  - simplification of program through taylor expansion
35
  - scaling when provided with typical ranges (not required to be sound for the moment)
36
  - computation of lyapunov invariants
37
  - returns an annotated node with invariants and a JSON to explain computation
38
  - could also returns plots
39

    
40
- tiny: linked to tiny library to perform floating point analyses
41
  shall be provided with ranges for inputs or local variables (memories)
42
  
43
*)
44
let rec verify dirname basename extension =
45
  let source_name = dirname ^ "/" ^ basename ^ extension in
46
  Options.compile_header := false; (* to avoid producing .h / .lusic *)
47
  Log.report ~level:1 (fun fmt -> fprintf fmt "@[<v 0>");
48
  decr Options.verbose_level;
49

    
50
  (* Parsing source *)
51
  let prog = parse source_name extension in
52

    
53
  (* Checking which solver is active *)
54
  incr Options.verbose_level;
55
  let verifier = Verifiers.get_active () in
56
  let module Verifier = (val verifier : VerifierType.S) in
57

    
58
  decr Options.verbose_level;
59
  let params = Verifier.get_normalization_params () in
60
  (* Normalizing it *)
61
  let prog, dependencies = 
62
    Log.report ~level:1 (fun fmt -> fprintf fmt "@[<v 2>.. Phase 1 : Normalisation@,");
63
    try
64
      incr Options.verbose_level;
65
      decr Options.verbose_level;
66
      Compiler_stages.stage1 params prog dirname basename extension
67
    with Compiler_stages.StopPhase1 prog -> (
68
        assert false
69
    )
70
  in
71
  Log.report ~level:1 (fun fmt -> fprintf fmt "@]@,");
72
  Log.report ~level:3 (fun fmt -> fprintf fmt ".. Normalized program:@ %a@ "Printers.pp_prog prog);
73

    
74
  Log.report ~level:1 (fun fmt -> fprintf fmt "@[<v 2>.. Phase 2 : Machines generation@,");
75

    
76
  let prog, machine_code = 
77
    Compiler_stages.stage2 params prog 
78
  in
79

    
80
  Log.report ~level:1 (fun fmt -> fprintf fmt "@]@ ");
81
  Log.report ~level:3 (fun fmt -> fprintf fmt ".. Generated machines:@ %a@ "
82
                                    Machine_code_common.pp_machines machine_code);
83
  
84
  if Scopes.Plugin.show_scopes () then
85
    begin
86
      let all_scopes = Scopes.compute_scopes prog !Options.main_node in
87
      (* Printing scopes *)
88
      if !Options.verbose_level >= 1 then
89
	Format.printf "Possible scopes are:@   ";
90
      Format.printf "@[<v>%a@ @]@ @?" Scopes.print_scopes all_scopes;
91
      exit 0
92
	
93
    end;
94

    
95
  let machine_code = Plugins.refine_machine_code prog machine_code in
96

    
97
  (*assert (dependencies = []); (* Do not handle deps yet *)*)
98
  incr Options.verbose_level;
99
  Verifier.run basename prog machine_code;
100
  begin
101
    decr Options.verbose_level;
102
    Log.report ~level:1 (fun fmt -> fprintf fmt ".. done !@ ");
103
    incr Options.verbose_level;
104
    Log.report ~level:1 (fun fmt -> fprintf fmt "@]@.");
105
    (* We stop the process here *)
106
    exit 0
107
  end
108

    
109

    
110
let anonymous filename =
111
  let ok_ext, ext = List.fold_left
112
    (fun (ok, ext) ext' ->
113
      if not ok && Filename.check_suffix filename ext' then
114
	true, ext'
115
      else
116
	ok, ext)
117
    (false, "") extensions in
118
  if ok_ext then
119
    let dirname = Filename.dirname filename in
120
    let basename = Filename.chop_suffix (Filename.basename filename) ext in
121
    verify dirname basename ext
122
  else
123
    raise (Arg.Bad ("Can only compile *.lusi, *.lus or *.ec files"))
124

    
125
let _ =
126
  Global.initialize ();
127
  Corelang.add_internal_funs ();
128
  try
129
    Printexc.record_backtrace true;
130

    
131
    let options = Options_management.lustrev_options @ (Verifiers.options ()) in
132
    
133
    Arg.parse options anonymous usage
134
  with
135
  | Parse.Error _
136
    | Types.Error (_,_) | Clocks.Error (_,_) -> exit 1
137
  | Error.Error (loc , kind) (*| Task_set.Error _*) -> 
138
     Error.pp_error loc (fun fmt -> Error.pp_error_msg fmt kind);
139
     exit (Error.return_code kind)
140
  (* | Causality.Error _  -> exit (Error.return_code Error.AlgebraicLoop) *)
141
  | Sys_error msg -> (eprintf "Failure: %s@." msg); exit 1
142
  | exc -> (track_exception (); raise exc) 
143

    
144
             (* Local Variables: *)
145
             (* compile-command:"make -C .." *)
146
             (* End: *)