Project

General

Profile

Download (5.45 KB) Statistics
| Branch: | Tag: | Revision:
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 Compiler_common
14

    
15
open Utils
16

    
17

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

    
20
let extensions = [".ec"; ".lus"; ".lusi"]
21

    
22

    
23
(* verify a .lus source file 
24

    
25
we have multiple "backends"
26
- 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
27

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

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

    
48
  (* Parsing source *)
49
  let prog = parse source_name extension in
50

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

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

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

    
79
  let prog, machine_code = 
80
    Compiler_stages.stage2 params prog 
81
  in
82

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

    
98
  let machine_code = Plugins.refine_machine_code prog machine_code in
99

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

    
112

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

    
128
let _ =
129
  Global.initialize ();
130
  Corelang.add_internal_funs ();
131
  try
132
    Printexc.record_backtrace true;
133

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

    
147
             (* Local Variables: *)
148
             (* compile-command:"make -C .." *)
149
             (* End: *)
(37-37/63)