| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
let fatal_error exn = |
| 12 |
Topfmt.(in_phase ~phase:ParsingCommandLine print_err_exn exn); |
| 13 |
let exit_code = CErrors.exit_code exn in |
| 14 |
exit exit_code |
| 15 |
|
| 16 |
let set_worker_id opt s = |
| 17 |
assert (s <> "master"); |
| 18 |
Flags.async_proofs_worker_id := s |
| 19 |
|
| 20 |
let get_host_port opt s = |
| 21 |
match String.split_on_char ':' s with |
| 22 |
| [host; portr; portw] -> |
| 23 |
Some (Spawned.Socket(host, int_of_string portr, int_of_string portw)) |
| 24 |
| ["stdfds"] -> Some Spawned.AnonPipe |
| 25 |
| _ -> |
| 26 |
Coqargs.error_wrong_arg ("Error: host:portr:portw or stdfds expected after option "^opt) |
| 27 |
|
| 28 |
let get_error_resilience opt = function |
| 29 |
| "on" | "all" | "yes" -> Stm.AsyncOpts.FAll |
| 30 |
| "off" | "no" -> Stm.AsyncOpts.FNone |
| 31 |
| s -> Stm.AsyncOpts.FOnly (String.split_on_char ',' s) |
| 32 |
|
| 33 |
let get_priority opt s = |
| 34 |
try CoqworkmgrApi.priority_of_string s |
| 35 |
with Invalid_argument _ -> |
| 36 |
Coqargs.error_wrong_arg ("Error: low/high expected after "^opt) |
| 37 |
|
| 38 |
let get_async_proofs_mode opt = let open Stm.AsyncOpts in function |
| 39 |
| "no" | "off" -> APoff |
| 40 |
| "yes" | "on" -> APon |
| 41 |
| "lazy" -> APonLazy |
| 42 |
| _ -> |
| 43 |
Coqargs.error_wrong_arg ("Error: on/off/lazy expected after "^opt) |
| 44 |
|
| 45 |
let get_cache opt = function |
| 46 |
| "force" -> Some Stm.AsyncOpts.Force |
| 47 |
| _ -> |
| 48 |
Coqargs.error_wrong_arg ("Error: force expected after "^opt) |
| 49 |
|
| 50 |
let spawn_args (opts:Coqargs.t) = |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
let output_dir = match opts.config.output_directory with |
| 66 |
| None -> [] |
| 67 |
| Some dir -> ["-output-directory";dir] |
| 68 |
in |
| 69 |
let test_mode = if opts.config.test_mode then ["-test-mode"] else [] in |
| 70 |
let native_output = ["-native-output-dir"; opts.config.native_output_dir] in |
| 71 |
let native_include ni = ["-nI";ni] in |
| 72 |
let native_includes = CList.concat_map native_include opts.config.native_include_dirs in |
| 73 |
let ml_include i = ["-I"; i] in |
| 74 |
let ml_includes = CList.concat_map ml_include opts.pre.ml_includes in |
| 75 |
let boot = if opts.pre.boot then ["-boot"] else [] in |
| 76 |
List.concat [ |
| 77 |
output_dir; |
| 78 |
test_mode; |
| 79 |
native_output; |
| 80 |
native_includes; |
| 81 |
ml_includes; |
| 82 |
boot; |
| 83 |
["-q"; "-noinit"] |
| 84 |
] |
| 85 |
|
| 86 |
|
| 87 |
let parse_args opts arglist : Stm.AsyncOpts.stm_opt * string list = |
| 88 |
let init = Stm.AsyncOpts.default_opts ~spawn_args:(spawn_args opts) in |
| 89 |
let args = ref arglist in |
| 90 |
let extras = ref [] in |
| 91 |
let rec parse oval = match !args with |
| 92 |
| [] -> |
| 93 |
(oval, List.rev !extras) |
| 94 |
| opt :: rem -> |
| 95 |
args := rem; |
| 96 |
let next () = match !args with |
| 97 |
| x::rem -> args := rem; x |
| 98 |
| [] -> Coqargs.error_missing_arg opt |
| 99 |
in |
| 100 |
let noval = begin match opt with |
| 101 |
|
| 102 |
|"-async-proofs" -> |
| 103 |
{ oval with |
| 104 |
Stm.AsyncOpts.async_proofs_mode = get_async_proofs_mode opt (next()) |
| 105 |
} |
| 106 |
|"-async-proofs-j" -> |
| 107 |
{ oval with |
| 108 |
Stm.AsyncOpts.async_proofs_n_workers = (Coqargs.get_int ~opt (next ())) |
| 109 |
} |
| 110 |
|"-async-proofs-cache" -> |
| 111 |
{ oval with |
| 112 |
Stm.AsyncOpts.async_proofs_cache = get_cache opt (next ()) |
| 113 |
} |
| 114 |
|
| 115 |
|"-async-proofs-tac-j" -> |
| 116 |
let j = Coqargs.get_int ~opt (next ()) in |
| 117 |
if j < 0 then begin |
| 118 |
Coqargs.error_wrong_arg ("Error: -async-proofs-tac-j only accepts values greater than or equal to 0") |
| 119 |
end; |
| 120 |
{ oval with |
| 121 |
Stm.AsyncOpts.async_proofs_n_tacworkers = j |
| 122 |
} |
| 123 |
|
| 124 |
|"-async-proofs-worker-priority" -> |
| 125 |
{ oval with |
| 126 |
Stm.AsyncOpts.async_proofs_worker_priority = get_priority opt (next ()) |
| 127 |
} |
| 128 |
|
| 129 |
|"-async-proofs-private-flags" -> |
| 130 |
{ oval with |
| 131 |
Stm.AsyncOpts.async_proofs_private_flags = Some (next ()); |
| 132 |
} |
| 133 |
|
| 134 |
|"-async-proofs-tactic-error-resilience" -> |
| 135 |
{ oval with |
| 136 |
Stm.AsyncOpts.async_proofs_tac_error_resilience = get_error_resilience opt (next ()) |
| 137 |
} |
| 138 |
|
| 139 |
|"-async-proofs-command-error-resilience" -> |
| 140 |
{ oval with |
| 141 |
Stm.AsyncOpts.async_proofs_cmd_error_resilience = Coqargs.get_bool ~opt (next ()) |
| 142 |
} |
| 143 |
|
| 144 |
|"-async-proofs-delegation-threshold" -> |
| 145 |
{ oval with |
| 146 |
Stm.AsyncOpts.async_proofs_delegation_threshold = Coqargs.get_float ~opt (next ()) |
| 147 |
} |
| 148 |
|
| 149 |
|"-worker-id" -> set_worker_id opt (next ()); oval |
| 150 |
|
| 151 |
|"-main-channel" -> |
| 152 |
let ch = next () in |
| 153 |
Spawned.main_channel := get_host_port opt ch; |
| 154 |
{ oval with spawn_args = opt :: ch :: oval.spawn_args } |
| 155 |
|
| 156 |
|"-control-channel" -> |
| 157 |
let ch = next () in |
| 158 |
Spawned.control_channel := get_host_port opt ch; |
| 159 |
{ oval with spawn_args = opt :: ch :: oval.spawn_args } |
| 160 |
|
| 161 |
|
| 162 |
|"-async-queries-always-delegate" |
| 163 |
|"-async-proofs-always-delegate" |
| 164 |
|"-async-proofs-never-reopen-branch" -> |
| 165 |
{ oval with |
| 166 |
Stm.AsyncOpts.async_proofs_never_reopen_branch = true; |
| 167 |
spawn_args = opt :: oval.spawn_args; |
| 168 |
} |
| 169 |
|"-stm-debug" -> Stm.stm_debug := true; { oval with spawn_args = opt :: oval.spawn_args } |
| 170 |
|
| 171 |
| s -> |
| 172 |
extras := s :: !extras; |
| 173 |
oval |
| 174 |
end in |
| 175 |
parse noval |
| 176 |
in |
| 177 |
try |
| 178 |
parse init |
| 179 |
with any -> fatal_error any |
| 180 |
|
| 181 |
let usage = "\ |
| 182 |
\n -stm-debug STM debug mode (will trace every transaction)\ |
| 183 |
" |