Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

lustrec / src / options.ml @ b6d37e71

History | View | Annotate | Download (8.06 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 options =
124
[ "-d", Arg.Set_string dest_dir,
125
"uses the specified directory \x1b[4mdir\x1b[0m as root for generated/imported object and C files <default: .>";
126
"-I", Arg.Set_string include_dir, "Include directory";
127
    "-node", Arg.Set_string main_node, "specifies the \x1b[4mmain\x1b[0m node";
128
    "-print-types", Arg.Set print_types, "prints node types";
129
    "-print-clocks", Arg.Set print_clocks, "prints node clocks";
130
    "-verbose", Arg.Set_int verbose_level, "changes verbose \x1b[4mlevel\x1b[0m <default: 1>";
131
    "-version", Arg.Unit print_version, " displays the version";
132
  ]
133

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

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

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

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

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

    
190
(* Local Variables: *)
191
(* compile-command:"make -C .." *)
192
(* End: *)