Project

General

Profile

Revision 1bff14ac src/options.ml

View differences:

src/options.ml
12 12
let version = Version.number
13 13
let codename = Version.codename
14 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 15

  
28 16
let main_node = ref ""
29 17
let static_mem = ref true
......
64 52
let gen_mcdc = ref false
65 53
let no_mutation_suffix = ref false
66 54

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

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

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

  
121
let set_backend s =
122
  output := s;
123
  Backends.setup s
124

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

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

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

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

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

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

  
191 57
(* Local Variables: *)
192 58
(* compile-command:"make -C .." *)

Also available in: Unified diff