123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138(************************************************************************)(* * The Rocq Prover / The Rocq Development Team *)(* v * Copyright INRIA, CNRS and contributors *)(* <O___,, * (see version control and CREDITS file for authors & dates) *)(* \VV/ **************************************************************)(* // * This file is distributed under the terms of the *)(* * GNU Lesser General Public License Version 2.1 *)(* * (see LICENSE file for the text of the license) *)(************************************************************************)typecompilation_mode=BuildVo|BuildVos|BuildVoktypet={compilation_mode:compilation_mode;compile_file:(string*bool)option(* bool is verbosity *);compilation_output_name:stringoption;echo:bool;glob_out:Dumpglob.glob_output;output_context:bool}letdefault={compilation_mode=BuildVo;compile_file=None;compilation_output_name=None;echo=false;glob_out=Dumpglob.MultFiles;output_context=false}letdepropt=Feedback.msg_warningPp.(seq[str"Option ";stropt;str" is a noop and deprecated"])(* XXX Remove this duplication with Coqargs *)letfatal_errorexn=Topfmt.(in_phase~phase:ParsingCommandLineprint_err_exnexn);letexit_code=if(CErrors.is_anomalyexn)then129else1inexitexit_codeleterror_missing_args=prerr_endline("Error: extra argument expected after option "^s);prerr_endline"See -help for the syntax of supported options";exit1letarg_errormsg=CErrors.user_errmsgletis_dash_arguments=String.lengths>0&&s.[0]='-'letadd_compile?echocoptss=ifis_dash_argumentsthenarg_errorPp.(str"Unknown option "++strs);(* make the file name explicit; needed not to break up Rocq loadpath stuff. *)letecho=Option.defaultcopts.echoechoinlets=letopenFilenameinifis_implicitsthenconcatcurrent_dir_nameselsesin{coptswithcompile_file=Some(s,echo)}letadd_compile?echocoptsv_file=matchcopts.compile_filewith|Some(first,_)->arg_errorPp.(str"More than one file to compile: "++strfirst++spc()++str"and "++strv_file)|None->add_compile?echocoptsv_fileletparsearglist:t=letecho=reffalseinletargs=refarglistinletextras=ref[]inletrecparse(oval:t)=match!argswith|[]->(oval,List.rev!extras)|opt::rem->args:=rem;letnext()=match!argswith|x::rem->args:=rem;x|[]->error_missing_argoptinletnoval:t=beginmatchoptwith(* Deprecated options *)|"-opt"|"-byte"asopt->depropt;oval|"-image"asopt->depropt;let_=next()inoval(* Non deprecated options *)|"-output-context"->{ovalwithoutput_context=true}(* Verbose == echo mode *)|"-verbose"->echo:=true;oval(* Output filename *)|"-o"->{ovalwithcompilation_output_name=Some(next())}|"-vos"->Flags.load_vos_libraries:=true;{ovalwithcompilation_mode=BuildVos}|"-vok"->Flags.load_vos_libraries:=true;{ovalwithcompilation_mode=BuildVok}(* Glob options *)|"-no-glob"|"-noglob"->{ovalwithglob_out=Dumpglob.NoGlob}|"-dump-glob"->letfile=next()in{ovalwithglob_out=Dumpglob.Filefile}(* Rest *)|s->extras:=s::!extras;ovalendinparsenovalintryletopts,extra=parsedefaultinletargs=List.fold_leftadd_compileoptsextrainargswithany->fatal_errorany