Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

lustrec / src / main_lustre_verifier.ml @ 2fb97ad4

History | View | Annotate | Download (4.84 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

    
47
  Log.report ~level:1 (fun fmt -> fprintf fmt "@[<v 0>");
48

    
49
  (* Parsing source *)
50
  let prog = parse_source source_name in
51

    
52
  (* Checking which solver is active *)
53
  let verifier = Verifiers.get_active () in
54
  let module Verifier = (val verifier : VerifierType.S) in
55

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

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

    
72
  let machine_code = 
73
    Compiler_stages.stage2 prog 
74
  in
75

    
76
  Log.report ~level:1 (fun fmt -> fprintf fmt "@]@ ");
77
  Log.report ~level:3 (fun fmt -> fprintf fmt ".. Generated machines:@ %a@ "Machine_code_common.pp_machines machine_code);
78

    
79
  if Scopes.Plugin.show_scopes () then
80
    begin
81
      let all_scopes = Scopes.compute_scopes prog !Options.main_node in
82
      (* Printing scopes *)
83
      if !Options.verbose_level >= 1 then
84
	Format.printf "Possible scopes are:@   ";
85
      Format.printf "@[<v>%a@ @]@ @?" Scopes.print_scopes all_scopes;
86
      exit 0
87
	
88
    end;
89

    
90
  let machine_code = Plugins.refine_machine_code prog machine_code in
91

    
92
  assert (dependencies = []); (* Do not handle deps yet *)
93
  Verifier.run basename prog machine_code;
94
  begin
95
    Log.report ~level:1 (fun fmt -> fprintf fmt ".. done !@ @]@.");
96
    (* We stop the process here *)
97
    exit 0
98
  end
99

    
100

    
101
let anonymous filename =
102
  let ok_ext, ext = List.fold_left
103
    (fun (ok, ext) ext' ->
104
      if not ok && Filename.check_suffix filename ext' then
105
	true, ext'
106
      else
107
	ok, ext)
108
    (false, "") extensions in
109
  if ok_ext then
110
    let dirname = Filename.dirname filename in
111
    let basename = Filename.chop_suffix (Filename.basename filename) ext in
112
    verify dirname basename ext
113
  else
114
    raise (Arg.Bad ("Can only compile *.lusi, *.lus or *.ec files"))
115

    
116
let _ =
117
  Global.initialize ();
118
  Corelang.add_internal_funs ();
119
  try
120
    Printexc.record_backtrace true;
121

    
122
    let options = Options_management.lustrev_options @ (Verifiers.options ()) in
123
    
124
    Arg.parse options anonymous usage
125
  with
126
  | Parse.Error _
127
  | Types.Error (_,_) | Clocks.Error (_,_) -> exit 1
128
  | Corelang.Error (_ (* loc *), kind) (*| Task_set.Error _*) -> exit (Error.return_code kind)
129
  (* | Causality.Error _  -> exit (Error.return_code Error.AlgebraicLoop) *)
130
  | Sys_error msg -> (eprintf "Failure: %s@." msg); exit 1
131
  | exc -> (track_exception (); raise exc) 
132

    
133
(* Local Variables: *)
134
(* compile-command:"make -C .." *)
135
(* End: *)