diff options
Diffstat (limited to 'driver')
-rw-r--r-- | driver/Commandline.ml | 11 | ||||
-rw-r--r-- | driver/Commandline.mli | 3 | ||||
-rw-r--r-- | driver/Configuration.ml | 11 | ||||
-rw-r--r-- | driver/Driver.ml | 54 |
4 files changed, 46 insertions, 33 deletions
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/Configuration.ml b/driver/Configuration.ml index 1956b151..e73125f7 100644 --- a/driver/Configuration.ml +++ b/driver/Configuration.ml @@ -23,7 +23,7 @@ let _ = open_in env_file with Not_found -> let dir = Sys.getcwd () - and name = Sys.argv.(0) in + and name = Sys.executable_name in let dirname = if Filename.is_relative name then Filename.dirname (Filename.concat dir name) else @@ -58,8 +58,6 @@ let get_config key = let bad_config key v = Printf.eprintf "Invalid value `%s' for configuation option `%s'\n" v key; exit 2 -let stdlib_path = get_config "stdlib_path" - let prepro = get_config "prepro" let asm = get_config "asm" let linker = get_config "linker" @@ -81,6 +79,13 @@ let has_runtime_lib = | "false" -> false | v -> bad_config "has_runtime_lib" v + +let stdlib_path = + if has_runtime_lib then + get_config "stdlib_path" + else + "" + let asm_supports_cfi = match get_config "asm_supports_cfi" with | "true" -> true diff --git a/driver/Driver.ml b/driver/Driver.ml index f2a98f81..5d4c2f9c 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,26 +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 are also object files *) - _Regexp ".*\\.o\\.", 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; @@ -559,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 @@ -576,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"; |