From 334be23a90a700f3b62806e1178603a28c6ba3bb Mon Sep 17 00:00:00 2001 From: Xavier Leroy Date: Fri, 2 Jan 2015 13:26:05 +0100 Subject: PR#14: recognize ".so" arguments as files to pass to the linker. --- driver/Driver.ml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'driver') diff --git a/driver/Driver.ml b/driver/Driver.ml index fec87420..fb0124ac 100644 --- a/driver/Driver.ml +++ b/driver/Driver.ml @@ -476,8 +476,9 @@ let cmdline_actions = push_action process_S_file s; incr num_source_files); Suffix ".o", Self push_linker_arg; Suffix ".a", Self push_linker_arg; - (* GCC compatibility: .o.ext files are also object files *) + (* GCC compatibility: .o.ext files and .so files are also object files *) _Regexp ".*\\.o\\.", Self push_linker_arg; + Suffix ".so", Self push_linker_arg; (* GCC compatibility: .h files can be preprocessed with -E *) Suffix ".h", Self (fun s -> push_action process_h_file s; incr num_source_files); -- cgit From 1278e187ddc2aa3623002b1af2dc402eb735eb16 Mon Sep 17 00:00:00 2001 From: Xavier Leroy Date: Sat, 3 Jan 2015 09:28:41 +0100 Subject: PR#16: give option rules precedence over file pattern rules. Plus: simplify handling of -help and --help. Plus: error on unrecognized "-xxx" options so that "-foo.c" is not treated as a source file. --- driver/Commandline.ml | 11 ++++------ driver/Commandline.mli | 3 +-- driver/Driver.ml | 55 ++++++++++++++++++++++++++++++-------------------- 3 files changed, 38 insertions(+), 31 deletions(-) (limited to 'driver') diff --git a/driver/Commandline.ml b/driver/Commandline.ml index bc095af6..0a2c8fca 100644 --- a/driver/Commandline.ml +++ b/driver/Commandline.ml @@ -52,7 +52,7 @@ let rec find_action text = function | (pat, act) :: rem -> if match_pattern text pat then Some act else find_action text rem -let parse_array spec usage argv first last = +let parse_array spec argv first last = (* Split the spec into Exact patterns (in a hashtable) and other patterns *) let exact_cases = (Hashtbl.create 29 : (string, action) Hashtbl.t) in let rec split_spec = function @@ -69,10 +69,7 @@ let parse_array spec usage argv first last = with Not_found -> find_action s inexact_cases in match optact with | None -> - if s <> "-help" && s <> "--help" - then eprintf "Unknown argument `%s'\n" s - else printf "%s" usage; - exit 2 + eprintf "Unknown argument `%s'\n" s; exit 2 | Some(Set r) -> r := true; parse (i+1) | Some(Unset r) -> @@ -101,5 +98,5 @@ let parse_array spec usage argv first last = end in parse first -let parse_cmdline spec usage = - parse_array spec usage Sys.argv 1 (Array.length Sys.argv - 1) +let parse_cmdline spec = + parse_array spec Sys.argv 1 (Array.length Sys.argv - 1) diff --git a/driver/Commandline.mli b/driver/Commandline.mli index 7a18905f..79786678 100644 --- a/driver/Commandline.mli +++ b/driver/Commandline.mli @@ -34,8 +34,7 @@ type action = | String of (string -> unit) (** read next arg as a string, call function *) | Integer of (int -> unit) (** read next arg as an int, call function *) -val parse_cmdline: - (pattern * action) list -> string (* usage string *) -> unit +val parse_cmdline: (pattern * action) list -> unit (* Note on precedence: [Exact] patterns are tried first, then the other patterns are tried in the order in which they appear in the list. *) diff --git a/driver/Driver.ml b/driver/Driver.ml index fb0124ac..b6224c32 100644 --- a/driver/Driver.ml +++ b/driver/Driver.ml @@ -442,6 +442,9 @@ Interpreter mode: -all Simulate all possible execution orders " +let print_usage_and_exit _ = + printf "%s" usage_string; exit 0 + let language_support_options = [ option_fbitfields; option_flongdouble; option_fstruct_return; option_fvararg_calls; option_funprototyped; @@ -461,27 +464,9 @@ let cmdline_actions = let f_opt name ref = [Exact("-f" ^ name), Set ref; Exact("-fno-" ^ name), Unset ref] in [ -(* File arguments *) - Suffix ".c", Self (fun s -> - push_action process_c_file s; incr num_source_files); - Suffix ".i", Self (fun s -> - push_action process_i_file s; incr num_source_files); - Suffix ".p", Self (fun s -> - push_action process_i_file s; incr num_source_files); - Suffix ".cm", Self (fun s -> - push_action process_cminor_file s; incr num_source_files); - Suffix ".s", Self (fun s -> - push_action process_s_file s; incr num_source_files); - Suffix ".S", Self (fun s -> - push_action process_S_file s; incr num_source_files); - Suffix ".o", Self push_linker_arg; - Suffix ".a", Self push_linker_arg; - (* GCC compatibility: .o.ext files and .so files are also object files *) - _Regexp ".*\\.o\\.", Self push_linker_arg; - Suffix ".so", Self push_linker_arg; - (* GCC compatibility: .h files can be preprocessed with -E *) - Suffix ".h", Self (fun s -> - push_action process_h_file s; incr num_source_files); +(* Getting help *) + Exact "-help", Self print_usage_and_exit; + Exact "--help", Self print_usage_and_exit; (* Processing options *) Exact "-c", Set option_c; Exact "-E", Set option_E; @@ -560,6 +545,32 @@ let cmdline_actions = (* Code generation options *) @ f_opt "fpu" option_ffpu @ f_opt "sse" option_ffpu (* backward compatibility *) + @ [ +(* Catch options that are not handled *) + Prefix "-", Self (fun s -> + eprintf "Unknown option `%s'\n" s; exit 2); +(* File arguments *) + Suffix ".c", Self (fun s -> + push_action process_c_file s; incr num_source_files); + Suffix ".i", Self (fun s -> + push_action process_i_file s; incr num_source_files); + Suffix ".p", Self (fun s -> + push_action process_i_file s; incr num_source_files); + Suffix ".cm", Self (fun s -> + push_action process_cminor_file s; incr num_source_files); + Suffix ".s", Self (fun s -> + push_action process_s_file s; incr num_source_files); + Suffix ".S", Self (fun s -> + push_action process_S_file s; incr num_source_files); + Suffix ".o", Self push_linker_arg; + Suffix ".a", Self push_linker_arg; + (* GCC compatibility: .o.ext files and .so files are also object files *) + _Regexp ".*\\.o\\.", Self push_linker_arg; + Suffix ".so", Self push_linker_arg; + (* GCC compatibility: .h files can be preprocessed with -E *) + Suffix ".h", Self (fun s -> + push_action process_h_file s; incr num_source_files); + ] let _ = try @@ -577,7 +588,7 @@ let _ = end; Builtins.set C2C.builtins; CPragmas.initialize(); - parse_cmdline cmdline_actions usage_string; + parse_cmdline cmdline_actions; let nolink = !option_c || !option_S || !option_E || !option_interp in if nolink && !option_o <> None && !num_source_files >= 2 then begin eprintf "Ambiguous '-o' option (multiple source files)\n"; -- cgit