diff --git a/ir-calcul b/ir-calcul
index f521842dc..7af2b787a 160000
--- a/ir-calcul
+++ b/ir-calcul
@@ -1 +1 @@
-Subproject commit f521842dcf83dea33df43f1068c13d24b90b9bd9
+Subproject commit 7af2b787ac8aba998c5da59b6f1e7cc76320227c
diff --git a/src/mlang/backend_compilers/bir_to_dgfip_c.ml b/src/mlang/backend_compilers/bir_to_dgfip_c.ml
index a93067c2a..ee9aed24e 100644
--- a/src/mlang/backend_compilers/bir_to_dgfip_c.ml
+++ b/src/mlang/backend_compilers/bir_to_dgfip_c.ml
@@ -16,7 +16,6 @@
module D = DecoupledExpr
module VID = Dgfip_varid
-module Dgfip_options = Config.Dgfip_options
type scope =
| Id of string (* The identifier of a given scope *)
diff --git a/src/mlang/backend_compilers/bir_to_dgfip_c.mli b/src/mlang/backend_compilers/bir_to_dgfip_c.mli
index d543309f2..6a6fa57d6 100644
--- a/src/mlang/backend_compilers/bir_to_dgfip_c.mli
+++ b/src/mlang/backend_compilers/bir_to_dgfip_c.mli
@@ -21,4 +21,4 @@
of the output, is built in {!DecoupledExpr}. *)
val generate_c_program :
- Config.Dgfip_options.flags -> Mir.program -> (* filename *) string -> unit
+ Dgfip_options.flags -> Mir.program -> (* filename *) string -> unit
diff --git a/src/mlang/backend_compilers/decoupledExpr.ml b/src/mlang/backend_compilers/decoupledExpr.ml
index af8b26fd5..7cbcfaa9c 100644
--- a/src/mlang/backend_compilers/decoupledExpr.ml
+++ b/src/mlang/backend_compilers/decoupledExpr.ml
@@ -1,5 +1,4 @@
module VID = Dgfip_varid
-module Dgfip_options = Config.Dgfip_options
let generate_variable ?(def_flag = false) ?(trace_flag = false)
(m_sp_opt : Com.var_space) (var : Com.Var.t) : string =
diff --git a/src/mlang/backend_compilers/decoupledExpr.mli b/src/mlang/backend_compilers/decoupledExpr.mli
index a6056117d..1ba26a603 100644
--- a/src/mlang/backend_compilers/decoupledExpr.mli
+++ b/src/mlang/backend_compilers/decoupledExpr.mli
@@ -155,10 +155,7 @@ val build_expression :
val format_local_declarations : Format.formatter -> local_decls -> unit
val format_assign :
- Config.Dgfip_options.flags -> string -> Format.formatter -> t -> unit
+ Dgfip_options.flags -> string -> Format.formatter -> t -> unit
val format_set_vars :
- Config.Dgfip_options.flags ->
- Format.formatter ->
- (dflag * string * t) list ->
- unit
+ Dgfip_options.flags -> Format.formatter -> (dflag * string * t) list -> unit
diff --git a/src/mlang/backend_compilers/dgfip_compir_files.ml b/src/mlang/backend_compilers/dgfip_compir_files.ml
index 4b0212234..d47ba2d90 100644
--- a/src/mlang/backend_compilers/dgfip_compir_files.ml
+++ b/src/mlang/backend_compilers/dgfip_compir_files.ml
@@ -14,8 +14,6 @@
You should have received a copy of the GNU General Public License along with
this program. If not, see . *)
-module Dgfip_options = Config.Dgfip_options
-
let open_file filename =
let folder = Filename.dirname !Config.output_file in
let oc = open_out (Filename.concat folder filename) in
diff --git a/src/mlang/backend_compilers/dgfip_gen_files.ml b/src/mlang/backend_compilers/dgfip_gen_files.ml
index bce56572a..140f40194 100644
--- a/src/mlang/backend_compilers/dgfip_gen_files.ml
+++ b/src/mlang/backend_compilers/dgfip_gen_files.ml
@@ -14,8 +14,6 @@
You should have received a copy of the GNU General Public License along with
this program. If not, see . *)
-module Dgfip_options = Config.Dgfip_options
-
let open_file filename =
let folder = Filename.dirname !Config.output_file in
let oc = open_out (Filename.concat folder filename) in
diff --git a/src/mlang/driver.ml b/src/mlang/driver.ml
index 08da19851..dccc47c20 100644
--- a/src/mlang/driver.ml
+++ b/src/mlang/driver.ml
@@ -23,33 +23,11 @@ open Mlexer
exception Exit
-let process_dgfip_options (backend : Config.backend)
- ~(application_names : string list) (dgfip_options : string list option) =
- match backend with
- | Dgfip_c -> begin
- match dgfip_options with
- | None ->
- Cli.error_print
- "when using the DGFiP backend, DGFiP options MUST be provided";
- raise Exit
- | Some options -> begin
- match
- Dgfip_options.process_dgfip_options ~application_names options
- with
- | None ->
- Cli.error_print "parsing of DGFiP options failed, aborting";
- raise Exit
- | Some flags -> flags
- end
- end
- | UnknownBackend -> Config.Dgfip_options.default_flags
-
(* The legacy compiler plays a nasty trick on us, that we have to reproduce:
rule 1 is modified to add assignments to APPLI_XXX variables according to the
target application (OCEANS, BATCH and ILIAD). *)
-let patch_rule_1 (backend : Config.backend)
- (dgfip_flags : Config.Dgfip_options.flags) (program : Mast.program) :
- Mast.program =
+let patch_rule_1 (backend : Config.backend) (dgfip_flags : Dgfip_options.flags)
+ (program : Mast.program) : Mast.program =
let open Mast in
let var_exists name =
List.exists
@@ -152,84 +130,6 @@ let parse () =
finish "completed!";
m_program
-(** Entry function for the executable. Returns a negative number in case of
- error. *)
-
-let set_opts (files : string list) (application_names : string list)
- (without_dgfip_m : bool) (debug : bool) (var_info_debug : string list)
- (display_time : bool) (print_cycles : bool) (backend : string option)
- (output : string option) (run_tests : string option)
- (dgfip_test_filter : bool) (run_test : string option)
- (mpp_function : string) (optimize_unsafe_float : bool)
- (precision : string option) (roundops : string option)
- (comparison_error_margin : float option) (income_year : int)
- (m_clean_calls : bool) (dgfip_options : string list option) =
- let value_sort =
- let precision = Option.get precision in
- if precision = "double" then Config.RegularFloat
- else
- let mpfr_regex = Re.Pcre.regexp "^mpfr(\\d+)$" in
- if Re.Pcre.pmatch ~rex:mpfr_regex precision then
- let mpfr_prec =
- Re.Pcre.get_substring (Re.Pcre.exec ~rex:mpfr_regex precision) 1
- in
- Config.MPFR (int_of_string mpfr_prec)
- else if precision = "interval" then Config.Interval
- else
- let bigint_regex = Re.Pcre.regexp "^fixed(\\d+)$" in
- if Re.Pcre.pmatch ~rex:bigint_regex precision then
- let fixpoint_prec =
- Re.Pcre.get_substring (Re.Pcre.exec ~rex:bigint_regex precision) 1
- in
- Config.BigInt (int_of_string fixpoint_prec)
- else if precision = "mpq" then Config.Rational
- else
- Errors.raise_error
- (Format.asprintf "Unkown precision option: %s" precision)
- in
- let round_ops =
- match roundops with
- | Some "default" -> Config.RODefault
- | Some "multi" -> Config.ROMulti
- | Some roundops ->
- let mf_regex = Re.Pcre.regexp "^mainframe(\\d+)$" in
- if Re.Pcre.pmatch ~rex:mf_regex roundops then
- let mf_long_size =
- Re.Pcre.get_substring (Re.Pcre.exec ~rex:mf_regex roundops) 1
- in
- match int_of_string mf_long_size with
- | (32 | 64) as sz -> Config.ROMainframe sz
- | _ ->
- Errors.raise_error
- (Format.asprintf "Invalid long size for mainframe: %s"
- mf_long_size)
- else
- Errors.raise_error
- (Format.asprintf "Unknown roundops option: %s" roundops)
- | None -> Errors.raise_error @@ Format.asprintf "Unspecified roundops@."
- in
- let backend =
- match backend with Some "dgfip_c" -> Config.Dgfip_c | _ -> UnknownBackend
- in
- let execution_mode =
- match (run_tests, run_test) with
- | Some s, _ -> Config.MultipleTests s
- | None, Some s -> Config.SingleTest s
- | None, None -> Config.Extraction
- in
- let files =
- match List.length files with
- | 0 -> Errors.raise_error "please provide at least one M source file"
- | _ -> Config.NonEmpty files
- in
- let dgfip_flags =
- process_dgfip_options backend ~application_names dgfip_options
- in
- Config.set_all_arg_refs files application_names without_dgfip_m debug
- var_info_debug display_time print_cycles output optimize_unsafe_float
- m_clean_calls comparison_error_margin income_year value_sort round_ops
- backend dgfip_test_filter mpp_function dgfip_flags execution_mode
-
let run_single_test m_program test =
Mir_interpreter.repl_debug := true;
Test_interpreter.check_one_test m_program test !Config.value_sort
@@ -277,8 +177,38 @@ let driver () =
(match kont with None -> () | Some kont -> kont ());
raise e
+let set_opts (files : string list) (application_names : string list)
+ (without_dgfip_m : bool) (debug : bool) (var_info_debug : string list)
+ (display_time : bool) (print_cycles : bool) (backend : string option)
+ (output : string option) (run_tests : string option)
+ (dgfip_test_filter : bool) (run_test : string option)
+ (mpp_function : string option) (optimize_unsafe_float : bool)
+ (precision : string option) (roundops : string option)
+ (comparison_error_margin : float option) (income_year : int)
+ (m_clean_calls : bool) (dgfip_options : string list option) =
+ Config.set_opts ~files ~application_names ~without_dgfip_m ~debug
+ ~var_info_debug ~display_time ~print_cycles ~backend ~output ~run_tests
+ ~dgfip_test_filter ~run_test ~mpp_function ~optimize_unsafe_float ~precision
+ ~roundops ~comparison_error_margin ~income_year ~m_clean_calls
+ ~dgfip_options
+
+let run () =
+ let eval_cli =
+ Cmdliner.Cmd.eval_value @@ Cmdliner.Cmd.v Cli.info (Cli.mlang_t set_opts)
+ in
+ match eval_cli with
+ | Ok `Help | Ok `Version | Ok (`Ok `Displayed_dgfip_help) -> ()
+ | Ok (`Ok `Run) -> driver ()
+ | Ok (`Ok (`Error m)) -> Errors.raise_error m
+ | Error `Exn ->
+ Errors.raise_error
+ "Uncaught exception while reading command line arguments"
+ | Error `Parse -> Errors.raise_error "Parsing command line arguments failed"
+ | Error `Term -> Errors.raise_error "Term evaluation error"
+
let main () =
- let opt_code =
- Cmdliner.Cmd.eval @@ Cmdliner.Cmd.v Cli.info (Cli.mlang_t set_opts)
- in
- match opt_code with 0 -> driver () | i -> exit i
+ try run ()
+ with Errors.StructuredError (msg, pos_list, kont) as e ->
+ Cli.error_print "%a" Errors.format_structured_error (msg, pos_list);
+ (match kont with None -> () | Some kont -> kont ());
+ raise e
diff --git a/src/mlang/utils/cli.ml b/src/mlang/utils/cli.ml
index 4c0a05ec8..d181e6d8c 100644
--- a/src/mlang/utils/cli.ml
+++ b/src/mlang/utils/cli.ml
@@ -30,12 +30,11 @@ module ANSITerminal = ANSITerminal
let files =
Arg.(
- non_empty & pos_all file []
+ value & pos_all file []
& info [] ~docv:"FILES" ~doc:"M files to be compiled")
let applications =
- Arg.(
- non_empty & opt (list string) [] & info [ "A" ] ~doc:"Application name(s)")
+ Arg.(value & opt (list string) [] & info [ "A" ] ~doc:"Application name(s)")
let without_dgfip_m =
Arg.(
@@ -77,7 +76,7 @@ let backend =
let mpp_function =
Arg.(
- required
+ value
& opt (some string) None
& info [ "mpp_function" ] ~docv:"MPP_FUNCTION" ~doc:"M++ file main function")
diff --git a/src/mlang/utils/cli.mli b/src/mlang/utils/cli.mli
index bfeb9c31d..d7d252271 100644
--- a/src/mlang/utils/cli.mli
+++ b/src/mlang/utils/cli.mli
@@ -31,7 +31,7 @@ val mlang_t :
string option ->
bool ->
string option ->
- string ->
+ string option ->
bool ->
string option ->
string option ->
diff --git a/src/mlang/utils/config.ml b/src/mlang/utils/config.ml
index b608140e7..10b9e38e3 100644
--- a/src/mlang/utils/config.ml
+++ b/src/mlang/utils/config.ml
@@ -1,70 +1,3 @@
-module Dgfip_options = struct
- type flags = {
- (* -m *) annee_revenu : int;
- (* -P *) flg_correctif : bool;
- (* flg_correctif true by default, -P makes it false *)
- (* -R *) flg_iliad : bool;
- (* also implied by "iliad" in !Cli.application_names; disabled by -U *)
- (* -R *) flg_pro : bool;
- (* also implied by "pro" in !Cli.application_names; disabled by -U *)
- (* -U *) flg_cfir : bool;
- (* disabled by -R *)
- (* -b *) flg_gcos : bool;
- (* -b0 and -b1 ; disabled by -U and -R *)
- (* -b *) flg_tri_ebcdic : bool;
- (* -b1 only *)
- (* -s *) flg_short : bool;
- (* -r *) flg_register : bool;
- (* -O *) flg_optim_min_max : bool;
- (* -X *) flg_extraction : bool;
- (* -D *) flg_genere_libelle_restituee : bool;
- (* -S *) flg_controle_separe : bool;
- (* -I *) flg_controle_immediat : bool;
- (* unused *)
- (* -o *) flg_overlays : bool;
- (* -Z *) flg_colors : bool;
- (* -L *) flg_ticket : bool;
- (* -t *) flg_trace : bool;
- (* -g *) flg_debug : bool;
- (* also implied by -t *)
- (* -k *) nb_debug_c : int;
- (* -x *)
- xflg : bool;
- (* Flags to deal with in a particular way : -c compilation mode -l link
- mode -v specify the variable file (tgv.m) -e specify the error file
- (err.m) *)
- (* Other flags, not used in makefiles -h dir_var_h -i flg_ident
- -K flg_optim_cte -G flg_listing (+genere_cre = FALSE) -p
- flag_phase -f flg_ench_init -E cvt_file -g flg_debug -a flg_api -T
- flg_trace_irdata *)
- }
-
- let default_flags =
- {
- annee_revenu = 1991;
- flg_correctif = true;
- flg_iliad = false;
- flg_pro = false;
- flg_cfir = false;
- flg_gcos = false;
- flg_tri_ebcdic = false;
- flg_short = false;
- flg_register = false;
- flg_optim_min_max = false;
- flg_extraction = false;
- flg_genere_libelle_restituee = false;
- flg_controle_separe = false;
- flg_controle_immediat = false;
- flg_overlays = false;
- flg_colors = false;
- flg_ticket = false;
- flg_trace = false;
- flg_debug = false;
- nb_debug_c = 0;
- xflg = false;
- }
-end
-
type value_sort =
| RegularFloat
| MPFR of int (* bitsize of the floats *)
@@ -168,3 +101,113 @@ let set_all_arg_refs (files_ : files) applications_ (without_dgfip_m_ : bool)
match comparison_error_margin_ with
| None -> ()
| Some m -> comparison_error_margin := m)
+
+let process_dgfip_options (backend : backend) ~(application_names : string list)
+ (dgfip_options : string list option) =
+ (* Parsing dgfip options even if we don't need them, because we may be in the case
+ --dgfip_options=--help. *)
+ let opts =
+ Option.map
+ (Dgfip_options.process_dgfip_options ~application_names)
+ dgfip_options
+ in
+ match (backend, opts) with
+ | Dgfip_c, None ->
+ `Error "When using the DGFiP backend, DGFiP options MUST be provided."
+ | Dgfip_c, Some (Ok (`Ok v)) -> `Dgfip_options v
+ | UnknownBackend, None -> `Dgfip_options Dgfip_options.default_flags
+ | UnknownBackend, Some (Ok (`Ok _)) ->
+ (* warning_print "Backend unknown, discarding dgfip_options."; *)
+ `Dgfip_options Dgfip_options.default_flags
+ | _, Some (Ok `Help) | _, Some (Ok `Version) -> `Dgfip_options_version
+ | _, Some (Error `Term) -> `Error "Invalid term in --dgfip_options"
+ | _, Some (Error `Parse) -> `Error "Failed parsing of --dgfip_options"
+ | _, Some (Error `Exn) ->
+ `Error "Uncaught exception while reading --dgfip_options"
+
+let set_opts ~(files : string list) ~(application_names : string list)
+ ~(without_dgfip_m : bool) ~(debug : bool) ~(var_info_debug : string list)
+ ~(display_time : bool) ~(print_cycles : bool) ~(backend : string option)
+ ~(output : string option) ~(run_tests : string option)
+ ~(dgfip_test_filter : bool) ~(run_test : string option)
+ ~(mpp_function : string option) ~(optimize_unsafe_float : bool)
+ ~(precision : string option) ~(roundops : string option)
+ ~(comparison_error_margin : float option) ~(income_year : int)
+ ~(m_clean_calls : bool) ~(dgfip_options : string list option) :
+ [ `Run | `Displayed_dgfip_help | `Error of string ] =
+ let exception INTERNAL_FAIL of string in
+ let exception DGFIP_HELP in
+ let err m = Format.kasprintf (fun s -> raise (INTERNAL_FAIL s)) m in
+ try
+ (* Reading backend first because we need it for parsing dgfip_flags *)
+ let backend =
+ match backend with Some "dgfip_c" -> Dgfip_c | _ -> UnknownBackend
+ in
+ let dgfip_flags =
+ match process_dgfip_options backend ~application_names dgfip_options with
+ | `Dgfip_options_help -> raise DGFIP_HELP
+ | `Dgfip_options_version -> raise DGFIP_HELP
+ | `Error m -> err "%s" m
+ | `Dgfip_options f -> f
+ in
+ let mpp_function =
+ match mpp_function with
+ | None -> err "Option --mpp_function required"
+ | Some m -> m
+ in
+ let value_sort =
+ let precision = Option.get precision in
+ if precision = "double" then RegularFloat
+ else
+ let mpfr_regex = Re.Pcre.regexp "^mpfr(\\d+)$" in
+ if Re.Pcre.pmatch ~rex:mpfr_regex precision then
+ let mpfr_prec =
+ Re.Pcre.get_substring (Re.Pcre.exec ~rex:mpfr_regex precision) 1
+ in
+ MPFR (int_of_string mpfr_prec)
+ else if precision = "interval" then Interval
+ else
+ let bigint_regex = Re.Pcre.regexp "^fixed(\\d+)$" in
+ if Re.Pcre.pmatch ~rex:bigint_regex precision then
+ let fixpoint_prec =
+ Re.Pcre.get_substring (Re.Pcre.exec ~rex:bigint_regex precision) 1
+ in
+ BigInt (int_of_string fixpoint_prec)
+ else if precision = "mpq" then Rational
+ else err "Unkown precision option: %s" precision
+ in
+ let round_ops =
+ match roundops with
+ | Some "default" -> RODefault
+ | Some "multi" -> ROMulti
+ | Some roundops ->
+ let mf_regex = Re.Pcre.regexp "^mainframe(\\d+)$" in
+ if Re.Pcre.pmatch ~rex:mf_regex roundops then
+ let mf_long_size =
+ Re.Pcre.get_substring (Re.Pcre.exec ~rex:mf_regex roundops) 1
+ in
+ match int_of_string mf_long_size with
+ | (32 | 64) as sz -> ROMainframe sz
+ | _ -> err "Invalid long size for mainframe: %s" mf_long_size
+ else err "Unknown roundops option: %s" roundops
+ | None -> err "Unspecified roundops@."
+ in
+ let execution_mode =
+ match (run_tests, run_test) with
+ | Some s, _ -> MultipleTests s
+ | None, Some s -> SingleTest s
+ | None, None -> Extraction
+ in
+ let files =
+ match List.length files with
+ | 0 -> err "please provide at least one M source file"
+ | _ -> NonEmpty files
+ in
+ set_all_arg_refs files application_names without_dgfip_m debug
+ var_info_debug display_time print_cycles output optimize_unsafe_float
+ m_clean_calls comparison_error_margin income_year value_sort round_ops
+ backend dgfip_test_filter mpp_function dgfip_flags execution_mode;
+ `Run
+ with
+ | INTERNAL_FAIL m -> `Error m
+ | DGFIP_HELP -> `Displayed_dgfip_help
diff --git a/src/mlang/utils/config.mli b/src/mlang/utils/config.mli
index 0599477bf..42a1b38bf 100644
--- a/src/mlang/utils/config.mli
+++ b/src/mlang/utils/config.mli
@@ -1,35 +1,3 @@
-(**{2 Flags and parameters}*)
-
-(** Special dgfip options for the compirateur *)
-
-module Dgfip_options : sig
- type flags = {
- annee_revenu : int;
- flg_correctif : bool;
- flg_iliad : bool;
- flg_pro : bool;
- flg_cfir : bool;
- flg_gcos : bool;
- flg_tri_ebcdic : bool;
- flg_short : bool;
- flg_register : bool;
- flg_optim_min_max : bool;
- flg_extraction : bool;
- flg_genere_libelle_restituee : bool;
- flg_controle_separe : bool;
- flg_controle_immediat : bool;
- flg_overlays : bool;
- flg_colors : bool;
- flg_ticket : bool;
- flg_trace : bool;
- flg_debug : bool;
- nb_debug_c : int;
- xflg : bool;
- }
-
- val default_flags : flags
-end
-
(** According on the [value_sort], a specific interpreter will be called with
the right kind of floating-point value *)
type value_sort =
@@ -42,7 +10,7 @@ type value_sort =
(** Rounding operations to use in the interpreter. They correspond to the
rounding operations used by the DGFiP calculator in different execution
contexts.
-
+
- RODefault: rounding operations used in the PC/single-thread context
- ROMulti: rouding operations used in the PC/multi-thread context
- ROMainframe rounding operations used in the mainframe context *)
@@ -79,8 +47,8 @@ val var_info_flag : bool ref
(** Print infomation about variables declared, defined ou used incorrectly *)
val var_info_debug : string list ref
-(** Prints even more information but only about some variables members of a list
-*)
+(** Prints even more information but only about some variables members of a
+ list *)
val warning_flag : bool ref
(** Print warning info *)
@@ -118,24 +86,25 @@ val dgfip_flags : Dgfip_options.flags ref
val execution_mode : execution_mode ref
-val set_all_arg_refs :
- (* files *) files ->
- (* applications *) string list ->
- (* without_dgfip_m *) bool ->
- (* debug *) bool ->
- (* var_info_debug *) string list ->
- (* display_time *) bool ->
- (* prints_cycles *) bool ->
- (* output_file *) string option ->
- (* optimize_unsafe_float *) bool ->
- (* m_clean_call *) bool ->
- (* comparison_error_margin*) float option ->
- (* income_year *) int ->
- value_sort ->
- round_ops ->
- backend ->
- (* dgfip_test_filter *) bool ->
- (* mpp_function *) string ->
- (* dgfip_flags *) Dgfip_options.flags ->
- (* execution_mode *) execution_mode ->
- unit
+val set_opts :
+ files:string list ->
+ application_names:string list ->
+ without_dgfip_m:bool ->
+ debug:bool ->
+ var_info_debug:string list ->
+ display_time:bool ->
+ print_cycles:bool ->
+ backend:string option ->
+ output:string option ->
+ run_tests:string option ->
+ dgfip_test_filter:bool ->
+ run_test:string option ->
+ mpp_function:string option ->
+ optimize_unsafe_float:bool ->
+ precision:string option ->
+ roundops:string option ->
+ comparison_error_margin:float option ->
+ income_year:int ->
+ m_clean_calls:bool ->
+ dgfip_options:string list option ->
+ [ `Displayed_dgfip_help | `Error of string | `Run ]
diff --git a/src/mlang/utils/dgfip_options.ml b/src/mlang/utils/dgfip_options.ml
index 6e02ec4d1..1f92e0862 100644
--- a/src/mlang/utils/dgfip_options.ml
+++ b/src/mlang/utils/dgfip_options.ml
@@ -11,6 +11,71 @@
open Cmdliner
+type flags = {
+ (* -m *) annee_revenu : int;
+ (* -P *) flg_correctif : bool;
+ (* flg_correctif true by default, -P makes it false *)
+ (* -R *) flg_iliad : bool;
+ (* also implied by "iliad" in !Cli.application_names; disabled by -U *)
+ (* -R *) flg_pro : bool;
+ (* also implied by "pro" in !Cli.application_names; disabled by -U *)
+ (* -U *) flg_cfir : bool;
+ (* disabled by -R *)
+ (* -b *) flg_gcos : bool;
+ (* -b0 and -b1 ; disabled by -U and -R *)
+ (* -b *) flg_tri_ebcdic : bool;
+ (* -b1 only *)
+ (* -s *) flg_short : bool;
+ (* -r *) flg_register : bool;
+ (* -O *) flg_optim_min_max : bool;
+ (* -X *) flg_extraction : bool;
+ (* -D *) flg_genere_libelle_restituee : bool;
+ (* -S *) flg_controle_separe : bool;
+ (* -I *) flg_controle_immediat : bool;
+ (* unused *)
+ (* -o *) flg_overlays : bool;
+ (* -Z *) flg_colors : bool;
+ (* -L *) flg_ticket : bool;
+ (* -t *) flg_trace : bool;
+ (* -g *) flg_debug : bool;
+ (* also implied by -t *)
+ (* -k *) nb_debug_c : int;
+ (* -x *)
+ xflg : bool;
+ (* Flags to deal with in a particular way : -c compilation mode -l link
+ mode -v specify the variable file (tgv.m) -e specify the error file
+ (err.m) *)
+ (* Other flags, not used in makefiles -h dir_var_h -i flg_ident
+ -K flg_optim_cte -G flg_listing (+genere_cre = FALSE) -p
+ flag_phase -f flg_ench_init -E cvt_file -g flg_debug -a flg_api -T
+ flg_trace_irdata *)
+}
+
+let default_flags =
+ {
+ annee_revenu = 1991;
+ flg_correctif = true;
+ flg_iliad = false;
+ flg_pro = false;
+ flg_cfir = false;
+ flg_gcos = false;
+ flg_tri_ebcdic = false;
+ flg_short = false;
+ flg_register = false;
+ flg_optim_min_max = false;
+ flg_extraction = false;
+ flg_genere_libelle_restituee = false;
+ flg_controle_separe = false;
+ flg_controle_immediat = false;
+ flg_overlays = false;
+ flg_colors = false;
+ flg_ticket = false;
+ flg_trace = false;
+ flg_debug = false;
+ nb_debug_c = 0;
+ xflg = false;
+ }
+
let income_year = Arg.(value & opt int 1991 & info [ "m" ] ~doc:"Income year")
let iliad_pro =
@@ -103,40 +168,36 @@ let handler ~(application_names : string list) (income_year : int)
(immediate_controls : bool) (overlays : bool) (optim_min_max : bool)
(register : bool) (short : bool) (output_labels : bool) (debug : bool)
(nb_debug_c : int) (trace : bool) (ticket : bool) (colored_output : bool)
- (cross_references : bool) : Config.Dgfip_options.flags =
+ (cross_references : bool) : flags =
let has_iliad = List.mem "iliad" application_names in
let has_pro = List.mem "pro" application_names in
- Config.Dgfip_options.
- {
- (* iliad, pro, (GP) *)
- annee_revenu = income_year;
- flg_correctif = not primitive_only;
- flg_iliad =
- ((iliad_pro && not cfir) || has_iliad) && not (Option.is_some batch);
- flg_pro = (has_pro || iliad_pro) && not cfir;
- flg_cfir = cfir && not iliad_pro;
- flg_gcos = Option.is_some batch && (not iliad_pro) && not cfir;
- flg_tri_ebcdic = (match batch with Some 1 -> true | _ -> false);
- flg_short = short;
- flg_register = register;
- flg_optim_min_max = optim_min_max;
- flg_extraction = extraction;
- flg_genere_libelle_restituee = output_labels;
- flg_controle_separe = separate_controls;
- flg_controle_immediat = immediate_controls;
- flg_overlays = overlays;
- flg_colors = colored_output;
- flg_ticket = ticket;
- flg_trace = trace;
- flg_debug = debug || trace;
- nb_debug_c;
- xflg = cross_references;
- }
+ {
+ (* iliad, pro, (GP) *)
+ annee_revenu = income_year;
+ flg_correctif = not primitive_only;
+ flg_iliad =
+ ((iliad_pro && not cfir) || has_iliad) && not (Option.is_some batch);
+ flg_pro = (has_pro || iliad_pro) && not cfir;
+ flg_cfir = cfir && not iliad_pro;
+ flg_gcos = Option.is_some batch && (not iliad_pro) && not cfir;
+ flg_tri_ebcdic = (match batch with Some 1 -> true | _ -> false);
+ flg_short = short;
+ flg_register = register;
+ flg_optim_min_max = optim_min_max;
+ flg_extraction = extraction;
+ flg_genere_libelle_restituee = output_labels;
+ flg_controle_separe = separate_controls;
+ flg_controle_immediat = immediate_controls;
+ flg_overlays = overlays;
+ flg_colors = colored_output;
+ flg_ticket = ticket;
+ flg_trace = trace;
+ flg_debug = debug || trace;
+ nb_debug_c;
+ xflg = cross_references;
+ }
let process_dgfip_options ~application_names options =
let options = Array.of_list ("mlang" :: options) in
let cmd = Cmd.v info (dgfip_t (handler ~application_names)) in
- let res = Cmd.eval_value ~argv:options cmd in
- match res with
- | Ok res -> ( match res with `Ok res -> Some res | _ -> None)
- | _ -> None
+ Cmd.eval_value ~argv:options cmd
diff --git a/src/mlang/utils/dgfip_options.mli b/src/mlang/utils/dgfip_options.mli
index 697d2da75..82572d664 100644
--- a/src/mlang/utils/dgfip_options.mli
+++ b/src/mlang/utils/dgfip_options.mli
@@ -1,3 +1,29 @@
+type flags = {
+ annee_revenu : int;
+ flg_correctif : bool;
+ flg_iliad : bool;
+ flg_pro : bool;
+ flg_cfir : bool;
+ flg_gcos : bool;
+ flg_tri_ebcdic : bool;
+ flg_short : bool;
+ flg_register : bool;
+ flg_optim_min_max : bool;
+ flg_extraction : bool;
+ flg_genere_libelle_restituee : bool;
+ flg_controle_separe : bool;
+ flg_controle_immediat : bool;
+ flg_overlays : bool;
+ flg_colors : bool;
+ flg_ticket : bool;
+ flg_trace : bool;
+ flg_debug : bool;
+ nb_debug_c : int;
+ xflg : bool;
+}
+
+val default_flags : flags
+
val handler :
application_names:string list ->
int ->
@@ -19,9 +45,9 @@ val handler :
bool ->
bool ->
bool ->
- Config.Dgfip_options.flags
+ flags
val process_dgfip_options :
application_names:string list ->
string list ->
- Config.Dgfip_options.flags option
+ (flags Cmdliner.Cmd.eval_ok, Cmdliner.Cmd.eval_error) result
diff --git a/src/mlang/utils/dune b/src/mlang/utils/dune
index 26ee72c84..7300f8e7f 100644
--- a/src/mlang/utils/dune
+++ b/src/mlang/utils/dune
@@ -1,4 +1,4 @@
(library
(public_name mlang.utils)
(name utils)
- (libraries ANSITerminal cmdliner dune-build-info threads))
+ (libraries re ANSITerminal cmdliner dune-build-info threads))