Project

General

Profile

Download (8.48 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
  Format.printf "Lustrec compiler, version %s (%s)@." version codename;
15
  Format.printf "Standard lib: %s@." Version.include_path;
16
  Format.printf "User provided include directory: @[<h>%a@]@."
17
    (Utils.fprintf_list ~sep:"@ " Format.pp_print_string) !include_dirs
18

    
19

    
20
let add_include_dir dir =
21
  let removed_slash_suffix =
22
    let len = String.length dir in
23
    if dir.[len-1] = '/' then
24
      String.sub dir 0 (len - 1)
25
    else
26
      dir
27
  in
28
  include_dirs := removed_slash_suffix :: !include_dirs
29

    
30

    
31
(** Solving the path of required library:
32
    If local: look in the folders described in !Options.include_dirs
33
    If non local: look first as a local, then in Version.include_path:
34
    ie. in Version.include_path::!Options.include_dirs
35
    Note that in options.ml, include folder are added as heads. One need to
36
    perform a fold_right to respect the order
37
*)
38
let search_lib_path (local, full_file_name) =
39
  let paths = (if local then !include_dirs else Version.include_path::!include_dirs) in
40
  let name =
41
    List.fold_right (fun dir res ->
42
      match res with Some _ -> res
43
      | None ->
44
	 let path_to_lib = dir ^ "/" ^ full_file_name in
45
	 if Sys.file_exists path_to_lib then
46
	   Some dir
47
	 else
48
	   None
49
    )
50
      paths
51
      None
52
  in
53
  match name with
54
  | 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
55
  | Some s -> s
56

    
57
(* Search for path of core libs (without lusic: arrow and io_frontend *)
58
let core_dependency lib_name =
59
  search_lib_path (false, lib_name ^ ".h")
60

    
61
let name_dependency (local, dep) ext =
62
  let dir = search_lib_path (false, dep ^ ext) in
63
  dir ^ "/" ^ dep
64

    
65
let set_mpfr prec =
66
  if prec > 0 then (
67
    mpfr := true;
68
    mpfr_prec := prec;
69
    real_type := "mpfr";
70
    (* salsa_enabled := false; (* We deactivate salsa *) TODO *)
71
  )
72
  else
73
    failwith "mpfr requires a positive integer"
74

    
75
let set_real_type s =
76
  match s with
77
    "mpfr" -> (
78
      mpfr := true;
79
      real_type := "mpfr";
80
    )
81
  | _ -> real_type := s
82

    
83
let set_backend s =
84
  output := s;
85
  Backends.setup ()
86

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

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

    
125
      "-c++" , Arg.Set        cpp      , "c++ backend";
126
      "-int" , Arg.Set_string int_type , "specifies the integer type (default=\"int\")";
127
      "-real", Arg.String set_real_type, "specifies the real type (default=\"double\" without mpfr option)";
128
      "-real-print-prec", Arg.Set_int print_prec_double, "specifies the number of digits to be printed for real values (default=15)";
129
      "-int_div_euclidean", Arg.Set integer_div_euclidean, "interprets integer division as Euclidean (default : C division semantics)";
130
      "-int_div_C", Arg.Clear integer_div_euclidean, "interprets integer division as C division (default)";
131

    
132
    "-mauve", Arg.String (fun node -> mauve := node; cpp := true; static_mem := false), "generates the mauve code";
133
]
134

    
135
let lustret_options =
136
  common_options @
137
  [ "-nb-mutants", Arg.Set_int nb_mutants, "\x1b[4mnumber\x1b[0m of mutants to produce <default: 1000>";
138
    "-mcdc-cond", Arg.Set gen_mcdc, "generates MC/DC coverage";
139
    "-no-mutation-suffix", Arg.Set no_mutation_suffix, "does not rename node with the _mutant suffix"
140
  ]
141

    
142
let lustrev_options =
143
   common_options @
144
  [ 
145
   "-inline", Arg.Unit (fun () -> global_inline := true; const_unfold := true), "inlines all node calls (require a main node). Implies constant unfolding";
146
    "-O", Arg.Set_int optimization, "changes optimization \x1b[4mlevel\x1b[0m <default: 2>";
147
]
148

    
149
  
150
let plugin_opt (name, activate, usage, options) =
151
  let usage () =
152
    Format.printf "@[<v 2>Plugin %s:@ %t@]@." name usage;
153
    exit 0
154
  in
155
  ( "-" ^ name , Arg.Unit activate, "activate plugin " ^ name ) ::
156
  ( "-" ^ name ^ "-help" , Arg.Unit usage, "plugin " ^ name ^ " help") ::
157
    (List.map (fun (opt, act, desc) -> "-" ^ name ^ opt, act, desc) options)
158
 
159
let verifier_opt (name, activate, options) =
160
  ( "-" ^ name , Arg.Unit activate, "run verifier " ^ name ) ::
161
    (List.map (fun (opt, act, desc) -> "-" ^ name ^ opt, act, desc) options)
162

    
163
let get_witness_dir filename =
164
  (* Make sure the directory exists *)
165
  let dir = !dest_dir ^ "/" ^ (Filename.basename filename) ^ "_witnesses" in
166
  let _ = try
167
	    if not (Sys.is_directory dir) then (
168
	      Format.eprintf "File of name %s exists. It should be a directory.@." dir;
169
	      exit 1
170
	    )
171
    with Sys_error _ -> Unix.mkdir dir 0o750
172
  in
173
  dir
(50-50/67)