Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

lustrec / src / options.ml @ 990210f3

History | View | Annotate | Download (7.93 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 common_options =
120
  [ "-d", Arg.Set_string dest_dir, "uses the specified \x1b[4mdirectory\x1b[0m as root for generated/imported object and C files <default: .>";
121
    "-I", Arg.String add_include_dir, "sets include \x1b[4mdirectory\x1b[0m";
122
    "-node", Arg.Set_string main_node, "specifies the \x1b[4mmain\x1b[0m node";
123
    "-print-types", Arg.Set print_types, "prints node types";
124
    "-print-clocks", Arg.Set print_clocks, "prints node clocks";
125
    "-verbose", Arg.Set_int verbose_level, "changes verbose \x1b[4mlevel\x1b[0m <default: 1>";
126
    "-version", Arg.Unit print_version, " displays the version";
127
  ]
128

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

    
157
    "-mauve", Arg.String (fun node -> mauve := node; cpp := true; static_mem := false), "generates the mauve code";
158
]
159

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

    
167
let plugin_opt (name, activate, options) =
168
  ( "-" ^ name , Arg.Unit activate, "activate plugin " ^ name ) ::
169
    (List.map (fun (opt, act, desc) -> "-" ^ name ^ opt, act, desc) options)
170
 
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
183

    
184
(* Local Variables: *)
185
(* compile-command:"make -C .." *)
186
(* End: *)