Project

General

Profile

Download (8.58 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
open Options
12

    
13
let print_version () =
14
  let open Utils.Format in
15
  printf
16
    "@[<v>\
17
     Lustrec compiler, version %s (%s)@,\
18
     Standard lib: %s@,\
19
     User provided include directory: @[<h>%a@]\
20
     @]@."
21
    version codename
22
    Version.include_path
23
    (pp_print_list ~pp_sep:pp_print_space pp_print_string) !include_dirs
24

    
25
let add_include_dir dir =
26
  let removed_slash_suffix =
27
    let len = String.length dir in
28
    if dir.[len-1] = '/' then
29
      String.sub dir 0 (len - 1)
30
    else
31
      dir
32
  in
33
  include_dirs := removed_slash_suffix :: !include_dirs
34

    
35

    
36
(** Solving the path of required library:
37
    If local: look in the folders described in !Options.include_dirs
38
    If non local: look first as a local, then in Version.include_path:
39
    ie. in Version.include_path::!Options.include_dirs
40
    Note that in options.ml, include folder are added as heads. One need to
41
    perform a fold_right to respect the order
42
*)
43
let search_lib_path (local, full_file_name) =
44
  let paths = (if local then !include_dirs else Version.include_path::!include_dirs) in
45
  let name =
46
    List.fold_right (fun dir res ->
47
      match res with Some _ -> res
48
      | None ->
49
	 let path_to_lib = dir ^ "/" ^ full_file_name in
50
	 if Sys.file_exists path_to_lib then
51
	   Some dir
52
	 else
53
	   None
54
    )
55
      paths
56
      None
57
  in
58
  match name with
59
  | None ->
60
    Format.eprintf "Unable to find library %s in paths %a@.@?" full_file_name
61
      (Utils.fprintf_list ~sep:", " Format.pp_print_string) paths;
62
     raise Not_found
63
  | Some s -> s
64

    
65
(* Search for path of core libs (without lusic: arrow and io_frontend *)
66
let core_dependency lib_name =
67
  search_lib_path (false, lib_name ^ ".h")
68

    
69
let name_dependency (_, dep) ext =
70
  let dir = search_lib_path (false, dep ^ ext) in
71
  dir ^ "/" ^ dep
72

    
73
let set_mpfr prec =
74
  if prec > 0 then (
75
    mpfr := true;
76
    mpfr_prec := prec;
77
    real_type := "mpfr";
78
    (* salsa_enabled := false; (* We deactivate salsa *) TODO *)
79
  )
80
  else
81
    failwith "mpfr requires a positive integer"
82

    
83
let set_real_type s =
84
  match s with
85
    "mpfr" -> (
86
      mpfr := true;
87
      real_type := "mpfr";
88
    )
89
  | _ -> real_type := s
90

    
91
let set_backend s =
92
  output := s;
93
  Backends.setup ()
94

    
95
let common_options =
96
  [ "-d", Arg.Set_string dest_dir, "uses the specified \x1b[4mdirectory\x1b[0m as root for generated/imported object and C files <default: .>";
97
    "-I", Arg.String add_include_dir, "sets include \x1b[4mdirectory\x1b[0m";
98
    "-node", Arg.Set_string main_node, "specifies the \x1b[4mmain\x1b[0m node";
99
    "-print-types", Arg.Set print_types, "prints node types";
100
    "-print-clocks", Arg.Set print_clocks, "prints node clocks";
101
    "-print-nodes",  Arg.Set print_nodes, "prints node list";
102
    "-algebraic-loop-solve", Arg.Set solve_al, "try to solve algebraic loops";
103
    "-algebraic-loop-max", Arg.Set_int al_nb_max, "try to solve \x1b[4mnb\x1b[0m number of algebraic loops  <default: 15>";
104
    "-kind2", Arg.Set kind2_print, "active kind2 output";
105
    "-verbose", Arg.Set_int verbose_level, "changes verbose \x1b[4mlevel\x1b[0m <default: 1>";
106
    "-version", Arg.Unit print_version, " displays the version";
107
  ]
108

    
109
let lustrec_options =
110
  common_options @
111
    [
112
      "-init", Arg.Set delay_calculus, "performs an initialisation analysis for Lustre nodes <default: no analysis>";
113
      "-dynamic", Arg.Clear static_mem, "specifies a dynamic allocation scheme for main Lustre node <default: static>";
114
      "-check-access", Arg.Set check, "checks at runtime that array accesses always lie within bounds <default: no check>";
115
      "-mpfr", Arg.Int set_mpfr, "replaces FP numbers by the MPFR library multiple precision numbers with a precision of \x1b[4mprec\x1b[0m bits <default: keep FP numbers>";
116
      "-lusi", Arg.Set lusi, "only generates a .lusi interface source file from a Lustre source <default: no generation>";
117
      "-no-spec", Arg.Unit (fun () -> spec := "no"), "do not generate any specification";
118
      "-acsl-spec", Arg.Unit (fun () -> spec := "acsl"), "generates an ACSL encoding of the specification. Only meaningful for the C backend <default>";
119
      "-c-spec", Arg.Unit (fun () -> spec := "c"), "generates a C encoding of the specification instead of ACSL contracts and annotations. Only meaningful for the C backend";
120
      (* "-java", Arg.Unit (fun () -> output := "java"), "generates Java output instead of C"; *)
121
      "-ada", Arg.Unit (fun () -> set_backend "Ada"), "generates Ada encoding output instead of C";
122
      "-horn", Arg.Unit (fun () -> set_backend "horn"), "generates Horn clauses encoding output instead of C";
123
      "-horn-traces", Arg.Unit (fun () -> set_backend "horn"; traces:=true), "produce traceability file for Horn backend. Enable the horn backend.";
124
      "-horn-cex", Arg.Unit (fun () -> set_backend "horn"; horn_cex:=true), "generate cex enumeration. Enable the horn backend (work in progress)";
125
      "-horn-query", Arg.Unit (fun () -> set_backend "horn"; horn_query:=true), "generate queries in generated Horn file. Enable the horn backend (work in progress)";
126
      "-horn-sfunction", Arg.Set_string sfunction, "Gets the endpoint predicate of the \x1b[4msfunction\x1b[0m";
127
      "-print-reuse", Arg.Set print_reuse, "prints variable reuse policy";
128
      "-lustre", Arg.Unit (fun () -> output := "lustre"), "generates Lustre output, performing all active optimizations";
129
      "-emf", Arg.Unit (fun () -> set_backend "emf"), "generates EMF output, to be used by CocoSim";
130
      "-inline", Arg.Unit (fun () -> global_inline := true; const_unfold := true), "inlines all node calls (require a main node). Implies constant unfolding";
131
      "-witnesses", Arg.Set witnesses, "enables production of witnesses during compilation";
132
      "-O", Arg.Set_int optimization, "changes optimization \x1b[4mlevel\x1b[0m <default: 2>";
133

    
134
      "-c++" , Arg.Set        cpp      , "c++ backend";
135
      "-int" , Arg.Set_string int_type , "specifies the integer type (default=\"int\")";
136
      "-real", Arg.String set_real_type, "specifies the real type (default=\"double\" without mpfr option)";
137
      "-real-print-prec", Arg.Set_int print_prec_double, "specifies the number of digits to be printed for real values (default=15)";
138
      "-int_div_euclidean", Arg.Set integer_div_euclidean, "interprets integer division as Euclidean (default : C division semantics)";
139
      "-int_div_C", Arg.Clear integer_div_euclidean, "interprets integer division as C division (default)";
140

    
141
    "-mauve", Arg.String (fun node -> mauve := node; cpp := true; static_mem := false), "generates the mauve code";
142
]
143

    
144
let lustret_options =
145
  common_options @
146
  [ "-nb-mutants", Arg.Set_int nb_mutants, "\x1b[4mnumber\x1b[0m of mutants to produce <default: 1000>";
147
    "-mcdc-cond", Arg.Set gen_mcdc, "generates MC/DC coverage";
148
    "-no-mutation-suffix", Arg.Set no_mutation_suffix, "does not rename node with the _mutant suffix"
149
  ]
150

    
151
let lustrev_options =
152
   common_options @
153
  [ 
154
   "-inline", Arg.Unit (fun () -> global_inline := true; const_unfold := true), "inlines all node calls (require a main node). Implies constant unfolding";
155
    "-O", Arg.Set_int optimization, "changes optimization \x1b[4mlevel\x1b[0m <default: 2>";
156
]
157

    
158
  
159
let plugin_opt (name, activate, usage, options) =
160
  let usage () =
161
    Format.printf "@[<v 2>Plugin %s:@ %t@]@." name usage;
162
    exit 0
163
  in
164
  ( "-" ^ name , Arg.Unit activate, "activate plugin " ^ name ) ::
165
  ( "-" ^ name ^ "-help" , Arg.Unit usage, "plugin " ^ name ^ " help") ::
166
    (List.map (fun (opt, act, desc) -> "-" ^ name ^ opt, act, desc) options)
167
 
168
let verifier_opt (name, activate, options) =
169
  ( "-" ^ name , Arg.Unit activate, "run verifier " ^ name ) ::
170
    (List.map (fun (opt, act, desc) -> "-" ^ name ^ opt, act, desc) options)
171

    
172
let get_witness_dir filename =
173
  (* Make sure the directory exists *)
174
  let dir = !dest_dir ^ "/" ^ (Filename.basename filename) ^ "_witnesses" in
175
  let _ = try
176
	    if not (Sys.is_directory dir) then (
177
	      Format.eprintf "File of name %s exists. It should be a directory.@." dir;
178
	      exit 1
179
	    )
180
    with Sys_error _ -> Unix.mkdir dir 0o750
181
  in
182
  dir
(47-47/63)