let run () =
if Jessie_config.jessie_local then begin
let whylib = String.escaped (Filename.concat Config.datadir "why") in
(try ignore (Unix.getenv "WHYLIB")
with Not_found ->
apply_if_dir_exist whylib (Unix.putenv "WHYLIB"));
end;
Jessie_options.feedback "Starting Jessie translation";
let prj =
File.create_project_from_visitor "jessie"
(fun prj -> new Visitor.frama_c_copy prj)
in
Project.copy ~only:(Plugin.get_selection ()) prj;
Project.set_current prj;
let file = Ast.get () in
try
if file.globals = [] then
Jessie_options.abort "Nothing to process. There was probably an error before.";
ignore (Common.malloc_function ());
ignore (Common.free_function ());
!Db.Properties.Interp.from_range_to_comprehension
(Cil.inplace_visit ()) (Project.current ()) file;
if checking then check_types file;
Rewrite.rewrite file;
if checking then check_types file;
if Jessie_options.debug_atleast 1 then print_to_stdout file;
Norm.normalize file;
Retype.retype file;
if checking then check_types file;
!Db.Properties.Interp.from_comprehension_to_range
(Cil.inplace_visit ()) (Project.current ()) file;
if Jessie_options.debug_atleast 1 then print_to_stdout file;
let pragmas = Interp.pragmas file in
let pfile = Interp.file file in
let sys_command cmd =
if Sys.command cmd <> 0 then
(Jessie_options.error "Jessie subprocess failed: %s" cmd; raise Exit)
in
let projname = Jessie_options.ProjectName.get () in
let projname =
if projname <> "" then projname else
match Parameters.Files.get() with
| [f] ->
(try
Filename.chop_extension f
with Invalid_argument _ -> f)
| _ ->
"wholeprogram"
in
let jessie_subdir = projname ^ ".jessie" in
Lib.mkdir_p jessie_subdir;
Jessie_options.feedback "Producing Jessie files in subdir %s" jessie_subdir;
let basename = Filename.basename projname in
let filename = basename ^ ".jc" in
let () = Pp.print_in_file
(fun fmt ->
Jc_output.print_decls fmt pragmas;
Format.fprintf fmt "%a" Jc_poutput.pdecls pfile)
(Filename.concat jessie_subdir filename)
in
Jessie_options.feedback "File %s/%s written." jessie_subdir filename;
let locname = basename ^ ".cloc" in
Pp.print_in_file Output.print_pos (Filename.concat jessie_subdir locname);
Jessie_options.feedback "File %s/%s written." jessie_subdir locname;
if Jessie_options.GenOnly.get () then () else
let why_opt =
Jessie_options.WhyOpt.fold
(fun opt acc -> " -why-opt \"" ^ opt ^ "\" " ^ acc) ""
in
let jc_opt =
StringSet.fold (fun opt acc -> " " ^ opt ^ " " ^ acc)
(Jessie_options.JcOpt.get ()) ""
in
let debug_opt = if Jessie_options.debug_atleast 1 then " -d " else " " in
let behav_opt =
if Jessie_options.Behavior.get () <> "" then
"-behavior " ^ Jessie_options.Behavior.get ()
else ""
in
let verbose_opt =
if Jessie_options.verbose_atleast 1 then " -v " else " "
in
let env_opt =
if Jessie_options.debug_atleast 1 then
"OCAMLRUNPARAM=bt"
else ""
in
let jessie_cmd =
try Sys.getenv "JESSIEEXEC"
with Not_found ->
if Jessie_options.debug_atleast 1 then
" jessie.byte "
else " jessie "
in
let cpulimit_opt =
if Jessie_options.CpuLimit.get () <> 0 then
"why-cpulimit " ^ (string_of_int (Jessie_options.CpuLimit.get ()))
else ""
in
let rec make_command = function
| [] -> ""
| [ a ] -> a
| a::cmd -> a ^ " " ^ make_command cmd
in
Jessie_options.feedback "Calling Jessie tool in subdir %s" jessie_subdir;
Sys.chdir jessie_subdir;
let cmd =
make_command
[ env_opt; cpulimit_opt; jessie_cmd; "-why-opt -split-user-conj";
verbose_opt; why_opt; jc_opt; debug_opt; behav_opt;
"-locs"; locname; filename ]
in
sys_command cmd;
let makefile = basename ^ ".makefile" in
Jessie_options.feedback "Calling VCs generator.";
sys_command ("make -f " ^ makefile ^ " " ^ (Jessie_options.Atp.get ()));
flush_all ()
with Exit -> ()