Debian Codegraph @

toplevel/coqc.ml

raw symbols SCIP
1 (************************************************************************)
2 (* * The Rocq Prover / The Rocq Development Team *)
3 (* v * Copyright INRIA, CNRS and contributors *)
4 (* <O___,, * (see version control and CREDITS file for authors & dates) *)
5 (* \VV/ **************************************************************)
6 (* // * This file is distributed under the terms of the *)
7 (* * GNU Lesser General Public License Version 2.1 *)
8 (* * (see LICENSE file for the text of the license) *)
9 (************************************************************************)
10
11 let coqc_init ((_,color_mode),_) injections ~opts =
12 Flags.quiet := true;
13 System.trust_file_cache := true;
14 Colors.init_color color_mode;
15 DebugHook.Intf.(set
16 { read_cmd = Coqtop.ltac_debug_parse
17 ; submit_answer = Coqtop.ltac_debug_answer
18 ; isTerminal = true
19 });
20 injections
21
22 let coqc_specific_usage = Boot.Usage.{
23 executable_name = "rocq compile";
24 extra_args = "file...";
25 extra_options = "\n\
26 rocq compile specific options:\
27 \n -o f.vo use f.vo as the output file name\
28 \n -verbose compile and output the input file\
29 \n -noglob do not dump globalizations\
30 \n -dump-glob f dump globalizations in file f (to be used by coqdoc)\
31 \n -vos process statements but ignore opaque proofs, and produce a .vos file\
32 \n -vok process the file by loading .vos instead of .vo files for\
33 \n dependencies, and produce an empty .vok file on success\
34 \n"
35 }
36
37 let coqc_main ((copts,_),stm_opts) injections ~opts =
38 Topfmt.(in_phase ~phase:CompilationPhase)
39 Ccompile.compile_file opts stm_opts copts injections;
40
41 flush_all();
42
43 if copts.Coqcargs.output_context then begin
44 let sigma, env = let e = Global.env () in Evd.from_env e, e in
45 let access = Library.indirect_accessor[@@warning "-3"] in
46 Feedback.msg_notice Pp.(
47 Prettyp.print_full_pure_context access env sigma ++ fnl ())
48 end;
49 ()
50
51 let coqc_run copts ~opts injections =
52 let _feeder = Feedback.add_feeder Coqloop.coqloop_feed in
53 try
54 coqc_main ~opts copts injections;
55 exit 0
56 with exn ->
57 flush_all();
58 Topfmt.print_err_exn exn;
59 flush_all();
60 let exit_code = CErrors.exit_code exn in
61 exit exit_code
62
63 let fix_stm_opts opts stm_opts = match opts.Coqcargs.compilation_mode with
64 | BuildVos ->
65 (* We need to disable error resiliency, otherwise some errors
66 will be ignored in batch mode. c.f. #6707
67
68 This is not necessary in the vo case as it fully checks the
69 document anyways. *)
70 let open Stm.AsyncOpts in
71 { stm_opts with
72 async_proofs_mode = APon;
73 async_proofs_n_workers = 0;
74 async_proofs_cmd_error_resilience = false;
75 async_proofs_tac_error_resilience = FNone;
76 }
77 | BuildVo | BuildVok -> stm_opts
78
79 let custom_coqc : ((Coqcargs.t * Colors.color) * Stm.AsyncOpts.stm_opt, 'b) Coqtop.custom_toplevel
80 = Coqtop.{
81 parse_extra = (fun opts extras ->
82 let color_mode, extras = Colors.parse_extra_colors ~emacs:opts.config.print_emacs extras in
83 let stm_opts, extras = Stmargs.parse_args opts extras in
84 let coqc_opts = Coqcargs.parse extras in
85 let stm_opts = fix_stm_opts coqc_opts stm_opts in
86 ((coqc_opts, color_mode), stm_opts), []);
87 usage = coqc_specific_usage;
88 init_extra = coqc_init;
89 run = coqc_run;
90 initial_args = Coqargs.default;
91 }
92
93 let main args =
94 let () = Memtrace_init.init () in
95 Coqtop.start_coq custom_coqc args