Skip to content

Commit

Permalink
share argument implementation across executable
Browse files Browse the repository at this point in the history
This commit defines five default argument modules in
Main_args.default. Those modules provide a default implementation
for the argument of ocaml, ocamlnat, ocamlc, ocamlopt, ocamldoc,
ocamlcp, ocamloptp, and expect_test.

Grouping together those implementations allow to share as much as
possible similar implementation across executables. It should make
easier to keep synchronized the various implementation, or reuse
those implementation in alternative drivers.
  • Loading branch information
Octachron committed Sep 30, 2019
1 parent e6605d6 commit a509157
Show file tree
Hide file tree
Showing 14 changed files with 375 additions and 944 deletions.
20 changes: 4 additions & 16 deletions .depend
Original file line number Diff line number Diff line change
Expand Up @@ -5681,7 +5681,6 @@ driver/errors.cmi :
driver/main.cmo : \
utils/warnings.cmi \
utils/profile.cmi \
utils/misc.cmi \
driver/makedepend.cmi \
driver/main_args.cmi \
parsing/location.cmi \
Expand All @@ -5697,7 +5696,6 @@ driver/main.cmo : \
driver/main.cmx : \
utils/warnings.cmx \
utils/profile.cmx \
utils/misc.cmx \
driver/makedepend.cmx \
driver/main_args.cmx \
parsing/location.cmx \
Expand All @@ -5714,13 +5712,17 @@ driver/main.cmi :
driver/main_args.cmo : \
utils/warnings.cmi \
utils/profile.cmi \
utils/misc.cmi \
utils/config.cmi \
driver/compenv.cmi \
utils/clflags.cmi \
driver/main_args.cmi
driver/main_args.cmx : \
utils/warnings.cmx \
utils/profile.cmx \
utils/misc.cmx \
utils/config.cmx \
driver/compenv.cmx \
utils/clflags.cmx \
driver/main_args.cmi
driver/main_args.cmi :
Expand Down Expand Up @@ -5798,9 +5800,7 @@ driver/optmain.cmo : \
utils/warnings.cmi \
utils/profile.cmi \
asmcomp/proc.cmi \
asmcomp/printmach.cmi \
driver/optcompile.cmi \
utils/misc.cmi \
driver/makedepend.cmi \
driver/main_args.cmi \
parsing/location.cmi \
Expand All @@ -5820,9 +5820,7 @@ driver/optmain.cmx : \
utils/warnings.cmx \
utils/profile.cmx \
asmcomp/proc.cmx \
asmcomp/printmach.cmx \
driver/optcompile.cmx \
utils/misc.cmx \
driver/makedepend.cmx \
driver/main_args.cmx \
parsing/location.cmx \
Expand Down Expand Up @@ -6050,27 +6048,21 @@ toplevel/opttoploop.cmi : \
parsing/location.cmi \
typing/env.cmi
toplevel/opttopmain.cmo : \
utils/warnings.cmi \
asmcomp/printmach.cmi \
toplevel/opttoploop.cmi \
toplevel/opttopdirs.cmi \
utils/misc.cmi \
driver/main_args.cmi \
parsing/location.cmi \
driver/compmisc.cmi \
driver/compenv.cmi \
utils/clflags.cmi \
toplevel/opttopmain.cmi
toplevel/opttopmain.cmx : \
utils/warnings.cmx \
asmcomp/printmach.cmx \
toplevel/opttoploop.cmx \
toplevel/opttopdirs.cmx \
utils/misc.cmx \
driver/main_args.cmx \
parsing/location.cmx \
driver/compmisc.cmx \
driver/compenv.cmx \
utils/clflags.cmx \
toplevel/opttopmain.cmi
toplevel/opttopmain.cmi :
Expand Down Expand Up @@ -6234,10 +6226,8 @@ toplevel/toploop.cmi : \
parsing/location.cmi \
typing/env.cmi
toplevel/topmain.cmo : \
utils/warnings.cmi \
toplevel/toploop.cmi \
toplevel/topdirs.cmi \
utils/profile.cmi \
utils/misc.cmi \
driver/main_args.cmi \
parsing/location.cmi \
Expand All @@ -6246,10 +6236,8 @@ toplevel/topmain.cmo : \
utils/clflags.cmi \
toplevel/topmain.cmi
toplevel/topmain.cmx : \
utils/warnings.cmx \
toplevel/toploop.cmx \
toplevel/topdirs.cmx \
utils/profile.cmx \
utils/misc.cmx \
driver/main_args.cmx \
parsing/location.cmx \
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ COMP=\
bytecomp/meta.cmo bytecomp/opcodes.cmo \
bytecomp/bytesections.cmo bytecomp/dll.cmo \
bytecomp/symtable.cmo \
driver/pparse.cmo driver/main_args.cmo \
driver/compenv.cmo driver/compmisc.cmo \
driver/pparse.cmo driver/compenv.cmo \
driver/main_args.cmo driver/compmisc.cmo \
driver/makedepend.cmo \
driver/compile_common.cmo

Expand Down
130 changes: 1 addition & 129 deletions driver/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -21,135 +21,7 @@ let usage = "Usage: ocamlc <options> <files>\nOptions are:"
(* Error messages to standard error formatter *)
let ppf = Format.err_formatter

let vmthread_removed_message = "\
The -vmthread argument of ocamlc is no longer supported\n\
since OCaml 4.09.0. Please switch to system threads, which have the\n\
same API. Lightweight threads with VM-level scheduling are provided by\n\
third-party libraries such as Lwt, but with a different API."

module Options = Main_args.Make_bytecomp_options (struct
let set r () = r := true
let unset r () = r := false
let _a = set make_archive
let _absname = set Clflags.absname
let _alert = Warnings.parse_alert_option
let _annot = set annotations
let _binannot = set binary_annotations
let _c = set compile_only
let _cc s = c_compiler := Some s
let _cclib s = Compenv.defer (ProcessObjects (Misc.rev_split_words s))
let _ccopt s = first_ccopts := s :: !first_ccopts
let _compat_32 = set bytecode_compatible_32
let _config = Misc.show_config_and_exit
let _config_var = Misc.show_config_variable_and_exit
let _custom = set custom_runtime
let _no_check_prims = set no_check_prims
let _dllib s = defer (ProcessDLLs (Misc.rev_split_words s))
let _dllpath s = dllpaths := !dllpaths @ [s]
let _for_pack s = for_package := Some s
let _g = set debug
let _i () =
print_types := true;
compile_only := true;
stop_after := Some Compiler_pass.Typing;
()
let _stop_after pass =
let module P = Compiler_pass in
begin match P.of_string pass with
| None -> () (* this should not occur as we use Arg.Symbol *)
| Some pass ->
stop_after := Some pass;
begin match pass with
| P.Parsing | P.Typing ->
compile_only := true
end;
end
let _I s = include_dirs := s :: !include_dirs
let _impl = impl
let _intf = intf
let _intf_suffix s = Config.interface_suffix := s
let _keep_docs = set keep_docs
let _no_keep_docs = unset keep_docs
let _keep_locs = set keep_locs
let _no_keep_locs = unset keep_locs
let _labels = unset classic
let _linkall = set link_everything
let _make_runtime () =
custom_runtime := true; make_runtime := true; link_everything := true
let _alias_deps = unset transparent_modules
let _no_alias_deps = set transparent_modules
let _app_funct = set applicative_functors
let _no_app_funct = unset applicative_functors
let _noassert = set noassert
let _nolabels = set classic
let _noautolink = set no_auto_link
let _nostdlib = set no_std_include
let _o s = output_name := Some s
let _opaque = set opaque
let _open s = open_modules := s :: !open_modules
let _output_obj () = output_c_object := true; custom_runtime := true
let _output_complete_obj () =
output_c_object := true;
output_complete_object := true;
custom_runtime := true
let _output_complete_exe () =
_output_complete_obj ();
output_complete_executable := true
let _pack = set make_package
let _pp s = preprocessor := Some s
let _ppx s = first_ppx := s :: !first_ppx
let _plugin _p = plugin := true
let _principal = set principal
let _no_principal = unset principal
let _rectypes = set recursive_types
let _no_rectypes = unset recursive_types
let _runtime_variant s = runtime_variant := s
let _with_runtime = set with_runtime
let _without_runtime = unset with_runtime
let _safe_string = unset unsafe_string
let _short_paths = unset real_paths
let _strict_sequence = set strict_sequence
let _no_strict_sequence = unset strict_sequence
let _strict_formats = set strict_formats
let _no_strict_formats = unset strict_formats
let _thread = set use_threads
let _vmthread = fun () -> fatal vmthread_removed_message
let _unboxed_types = set unboxed_types
let _no_unboxed_types = unset unboxed_types
let _unsafe = set unsafe
let _unsafe_string = set unsafe_string
let _use_prims s = use_prims := s
let _use_runtime s = use_runtime := s
let _v () = print_version_and_library "compiler"
let _version = print_version_string
let _vnum = print_version_string
let _w = (Warnings.parse_options false)
let _warn_error = (Warnings.parse_options true)
let _warn_help = Warnings.help_warnings
let _color = Misc.set_or_ignore color_reader.parse color
let _error_style = Misc.set_or_ignore error_style_reader.parse error_style
let _where = print_standard_library
let _verbose = set verbose
let _nopervasives = set nopervasives
let _match_context_rows n = match_context_rows := n
let _dump_into_file = set dump_into_file
let _dno_unique_ids = unset unique_ids
let _dunique_ids = set unique_ids
let _dsource = set dump_source
let _dparsetree = set dump_parsetree
let _dtypedtree = set dump_typedtree
let _drawlambda = set dump_rawlambda
let _dlambda = set dump_lambda
let _dinstr = set dump_instr
let _dcamlprimc = set keep_camlprimc_file
let _dtimings () = profile_columns := [ `Time ]
let _dprofile () = profile_columns := Profile.all_columns

let _args = Arg.read_arg
let _args0 = Arg.read_arg0

let anonymous = anonymous
end)
module Options = Main_args.Make_bytecomp_options (Main_args.Default.Main)

let main () =
Clflags.add_arguments __LOC__ Options.list;
Expand Down
Loading

0 comments on commit a509157

Please sign in to comment.