Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

lustrec / src / options.ml @ f7caf067

History | View | Annotate | Download (8 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
let version = Version.number
13
let codename = Version.codename
14
let include_dirs = ref ["."]
15
(* let include_path = *)
16
(* if (!include_dir <> ".") then Version.prefix ^ !include_dir *)
17
(* else Version.include_path *)
18

    
19

    
20

    
21

    
22
let print_version () =
23
  Format.printf "Lustrec compiler, version %s (%s)@." version codename;
24
  Format.printf "Standard lib: %s@." Version.include_path;
25
  Format.printf "User provided include directory: @[<h>%a@]@."
26
    (Utils.fprintf_list ~sep:"@ " Format.pp_print_string) !include_dirs
27

    
28
let main_node = ref ""
29
let static_mem = ref true
30
let print_types = ref true
31
let print_clocks = ref true
32
let delay_calculus = ref true
33
let track_exceptions = ref true
34
let ansi = ref false
35
let check = ref false
36
let spec = ref "acsl"
37
let output = ref "C"
38
let dest_dir = ref "."
39
let verbose_level = ref 1
40
let global_inline = ref false
41
let witnesses = ref false
42
let optimization = ref 2
43
let lusi = ref false
44
let print_reuse = ref false
45
let const_unfold = ref false
46
let mpfr = ref false
47
let mpfr_prec = ref 0
48

    
49
let traces = ref false
50
let horn_cex = ref false
51
let horn_query = ref true
52

    
53
let cpp       = ref false
54
let int_type  = ref "int"
55
let real_type = ref "double"
56

    
57
let sfunction = ref ""
58

    
59
let mauve = ref ""
60
(* test generation options *)
61
let nb_mutants = ref 1000
62
let gen_mcdc = ref false
63
let no_mutation_suffix = ref false
64

    
65
let add_include_dir dir =
66
  let removed_slash_suffix =
67
    let len = String.length dir in
68
    if dir.[len-1] = '/' then
69
      String.sub dir 0 (len - 1) 
70
    else
71
      dir
72
  in
73
  include_dirs := removed_slash_suffix :: !include_dirs
74

    
75
    
76
(** Solving the path of required library:
77
    If local: look in the folders described in !Options.include_dirs
78
    If non local: look first as a local, then in Version.include_path:
79
    ie. in Version.include_path::!Options.include_dirs
80
    Note that in options.ml, include folder are added as heads. One need to
81
    perform a fold_right to respect the order
82
*)
83
let search_lib_path (local, full_file_name) =
84
  let paths = (if local then !include_dirs else Version.include_path::!include_dirs) in
85
  let name =
86
    List.fold_right (fun dir res ->
87
      match res with Some _ -> res
88
      | None ->
89
	 let path_to_lib = dir ^ "/" ^ full_file_name in 
90
	 if Sys.file_exists path_to_lib then
91
	   Some dir
92
	 else
93
	   None
94
    )
95
      paths
96
      None
97
  in
98
  match name with
99
  | None -> Format.eprintf "Unable to find library %s in paths %a@.@?" full_file_name (Utils.fprintf_list ~sep:", " Format.pp_print_string) paths;raise Not_found
100
  | Some s -> s
101

    
102
(* Search for path of core libs (without lusic: arrow and io_frontend *)
103
let core_dependency lib_name =
104
  search_lib_path (false, lib_name ^ ".h")
105
    
106
let name_dependency (local, dep) =
107
  let dir = search_lib_path (false, dep ^ ".lusic") in
108
  dir ^ "/" ^ dep
109
  
110
let set_mpfr prec =
111
  if prec > 0 then (
112
    mpfr := true;
113
    mpfr_prec := prec;
114
    (* salsa_enabled := false; (* We deactivate salsa *) TODO *)
115
  )
116
  else
117
    failwith "mpfr requires a positive integer"
118

    
119
let set_backend s =
120
  output := s;
121
  Backends.setup s
122

    
123
let common_options =
124
  [ "-d", Arg.Set_string dest_dir, "uses the specified \x1b[4mdirectory\x1b[0m as root for generated/imported object and C files <default: .>";
125
    "-I", Arg.String add_include_dir, "sets include \x1b[4mdirectory\x1b[0m";
126
    "-node", Arg.Set_string main_node, "specifies the \x1b[4mmain\x1b[0m node";
127
    "-print-types", Arg.Set print_types, "prints node types";
128
    "-print-clocks", Arg.Set print_clocks, "prints node clocks";
129
    "-verbose", Arg.Set_int verbose_level, "changes verbose \x1b[4mlevel\x1b[0m <default: 1>";
130
    "-version", Arg.Unit print_version, " displays the version";
131
  ]
132

    
133
let lustrec_options =
134
   common_options @
135
  [ 
136
    "-init", Arg.Set delay_calculus, "performs an initialisation analysis for Lustre nodes <default: no analysis>";
137
    "-dynamic", Arg.Clear static_mem, "specifies a dynamic allocation scheme for main Lustre node <default: static>";
138
    "-check-access", Arg.Set check, "checks at runtime that array accesses always lie within bounds <default: no check>";
139
    "-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>";
140
    "-lusi", Arg.Set lusi, "only generates a .lusi interface source file from a Lustre source <default: no generation>";
141
    "-no-spec", Arg.Unit (fun () -> spec := "no"), "do not generate any specification";
142
    "-acsl-spec", Arg.Unit (fun () -> spec := "acsl"), "generates an ACSL encoding of the specification. Only meaningful for the C backend <default>";
143
    "-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";
144
    (* "-java", Arg.Unit (fun () -> output := "java"), "generates Java output instead of C"; *)
145
    "-horn", Arg.Unit (fun () -> set_backend "horn"), "generates Horn clauses encoding output instead of C";
146
    "-horn-traces", Arg.Unit (fun () -> set_backend "horn"; traces:=true), "produce traceability file for Horn backend. Enable the horn backend.";
147
    "-horn-cex", Arg.Unit (fun () -> set_backend "horn"; horn_cex:=true), "generate cex enumeration. Enable the horn backend (work in progress)";
148
    "-horn-query", Arg.Unit (fun () -> set_backend "horn"; horn_query:=true), "generate queries in generated Horn file. Enable the horn backend (work in progress)";
149
    "-horn-sfunction", Arg.Set_string sfunction, "Gets the endpoint predicate of the \x1b[4msfunction\x1b[0m";
150
    "-print-reuse", Arg.Set print_reuse, "prints variable reuse policy";
151
    "-lustre", Arg.Unit (fun () -> output := "lustre"), "generates Lustre output, performing all active optimizations";
152
   "-emf", Arg.Unit (fun () -> set_backend "emf"), "generates EMF output, to be used by CocoSim";
153
   "-inline", Arg.Unit (fun () -> global_inline := true; const_unfold := true), "inlines all node calls (require a main node). Implies constant unfolding";
154
    "-witnesses", Arg.Set witnesses, "enables production of witnesses during compilation";
155
    "-O", Arg.Set_int optimization, "changes optimization \x1b[4mlevel\x1b[0m <default: 2>";
156
    
157
    "-c++" , Arg.Set        cpp      , "c++ backend";
158
    "-int" , Arg.Set_string int_type , "specifies the integer type (default=\"int\")";
159
    "-real", Arg.Set_string real_type, "specifies the real type (default=\"double\" without mpfr option)";
160

    
161
    "-mauve", Arg.String (fun node -> mauve := node; cpp := true; static_mem := false), "generates the mauve code";
162
]
163

    
164
let lustret_options =
165
  common_options @
166
  [ "-nb-mutants", Arg.Set_int nb_mutants, "\x1b[4mnumber\x1b[0m of mutants to produce <default: 1000>";
167
    "-mcdc-cond", Arg.Set gen_mcdc, "generates MC/DC coverage";
168
    "-no-mutation-suffix", Arg.Set no_mutation_suffix, "does not rename node with the _mutant suffix"
169
  ]
170

    
171
let plugin_opt (name, activate, options) =
172
  ( "-" ^ name , Arg.Unit activate, "activate plugin " ^ name ) ::
173
    (List.map (fun (opt, act, desc) -> "-" ^ name ^ opt, act, desc) options)
174
 
175

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

    
188
(* Local Variables: *)
189
(* compile-command:"make -C .." *)
190
(* End: *)