From 87ada41360ec47118e3847637b6c746060e60be8 Mon Sep 17 00:00:00 2001 From: xleroy Date: Wed, 27 Jan 2010 16:31:25 +0000 Subject: Revised handling of #pragma section and small data areas git-svn-id: https://yquem.inria.fr/compcert/svn/compcert/trunk@1235 fca1b0fc-160b-0410-b1d3-a4f43f01ea2e --- driver/Clflags.ml | 6 +++ driver/Driver.ml | 158 +++++++++++++++++++++++++++--------------------------- 2 files changed, 85 insertions(+), 79 deletions(-) (limited to 'driver') diff --git a/driver/Clflags.ml b/driver/Clflags.ml index c6f6e8f..ddcfaac 100644 --- a/driver/Clflags.ml +++ b/driver/Clflags.ml @@ -24,3 +24,9 @@ let option_E = ref false let option_S = ref false let option_c = ref false let option_v = ref false +let option_small_data = + ref (if Configuration.arch = "powerpc" + && Configuration.variant = "eabi" + && Configuration.system = "diab" + then 8 else 0) +let option_small_const = ref (!option_small_data) diff --git a/driver/Driver.ml b/driver/Driver.ml index b818680..aed0221 100644 --- a/driver/Driver.ml +++ b/driver/Driver.ml @@ -247,10 +247,6 @@ let process_cminor_file sourcename = (* Command-line parsing *) -let starts_with s1 s2 = - String.length s1 >= String.length s2 && - String.sub s1 0 (String.length s2) = s2 - let usage_string = "ccomp [options] Recognized source files: @@ -269,6 +265,8 @@ Preprocessing options: Compilation options: -flonglong Treat 'long long' as 'long' and 'long double' as 'double' -fmadd Use fused multiply-add and multiply-sub instructions + -fsmall-data Set maximal size for allocation in small data area + -fsmall-const Set maximal size for allocation in small constant area -dcil Save CIL-processed source in .cil.c -dclight Save generated Clight in .light.c -dasm Save generated assembly in .s @@ -281,86 +279,88 @@ General options: -v Print external commands before invoking them " -let rec parse_cmdline i = - if i < Array.length Sys.argv then begin - let s = Sys.argv.(i) in - if starts_with s "-I" || starts_with s "-D" || starts_with s "-U" - then begin - prepro_options := s :: !prepro_options; - parse_cmdline (i + 1) - end else - if starts_with s "-l" || starts_with s "-L" then begin - linker_options := s :: !linker_options; - parse_cmdline (i + 1) - end else - if s = "-o" && i + 1 < Array.length Sys.argv then begin - exe_name := Sys.argv.(i + 1); - parse_cmdline (i + 2) - end else - if s = "-stdlib" && i + 1 < Array.length Sys.argv then begin - stdlib_path := Sys.argv.(i + 1); - parse_cmdline (i + 2) - end else - if s = "-flonglong" then begin - option_flonglong := true; - parse_cmdline (i + 1) - end else - if s = "-fmadd" then begin - option_fmadd := true; - parse_cmdline (i + 1) - end else - if s = "-dcil" then begin - option_dcil := true; - parse_cmdline (i + 1) - end else - if s = "-dclight" then begin - option_dclight := true; - parse_cmdline (i + 1) - end else - if s = "-dasm" then begin - option_dasm := true; - parse_cmdline (i + 1) - end else - if s = "-E" then begin - option_E := true; - parse_cmdline (i + 1) - end else - if s = "-S" then begin - option_S := true; - parse_cmdline (i + 1) - end else - if s = "-c" then begin - option_c := true; - parse_cmdline (i + 1) - end else - if s = "-v" then begin - option_v := true; - parse_cmdline (i + 1) - end else - if Filename.check_suffix s ".c" then begin +type action = + | Set of bool ref + | Self of (string -> unit) + | String of (string -> unit) + | Integer of (int -> unit) + +let rec find_action s = function + | [] -> None + | (re, act) :: rem -> + if Str.string_match re s 0 then Some act else find_action s rem + +let parse_cmdline spec usage = + let acts = List.map (fun (pat, act) -> (Str.regexp pat, act)) spec in + let error () = + eprintf "Usage: %s" usage; + exit 2 in + let rec parse i = + if i < Array.length Sys.argv then begin + let s = Sys.argv.(i) in + match find_action s acts with + | None -> + if s <> "-help" && s <> "--help" + then eprintf "Unknown argument `%s'\n" s; + error () + | Some(Set r) -> + r := true; parse (i+1) + | Some(Self fn) -> + fn s; parse (i+1) + | Some(String fn) -> + if i + 1 < Array.length Sys.argv then begin + fn Sys.argv.(i+1); parse (i+2) + end else begin + eprintf "Option `%s' expects an argument\n" s; error() + end + | Some(Integer fn) -> + if i + 1 < Array.length Sys.argv then begin + let n = + try + int_of_string Sys.argv.(i+1) + with Failure _ -> + eprintf "Argument to option `%s' must be an integer\n" s; + error() + in + fn n; parse (i+2) + end else begin + eprintf "Option `%s' expects an argument\n" s; error() + end + end + in parse 1 + +let cmdline_actions = [ + "-[IDU].", Self(fun s -> prepro_options := s :: !prepro_options); + "-[lL].", Self(fun s -> linker_options := s :: !linker_options); + "-o$", String(fun s -> exe_name := s); + "-stdlib$", String(fun s -> stdlib_path := s); + "-flonglong$", Set option_flonglong; + "-fmadd$", Set option_fmadd; + "-fsmall-data$", Integer(fun n -> option_small_data := n); + "-fsmall-const$", Integer(fun n -> option_small_const := n); + "-dcil$", Set option_dcil; + "-dclight$", Set option_dclight; + "-dasm$", Set option_dasm; + "-E$", Set option_E; + "-S$", Set option_S; + "-c$", Set option_c; + "-v$", Set option_v; + ".*\\.c$", Self (fun s -> let objfile = process_c_file s in - linker_options := objfile :: !linker_options; - parse_cmdline (i + 1) - end else - if Filename.check_suffix s ".cm" then begin + linker_options := objfile :: !linker_options); + ".*\\.cm$", Self (fun s -> let objfile = process_cminor_file s in - linker_options := objfile :: !linker_options; - parse_cmdline (i + 1) - end else - if Filename.check_suffix s ".o" || Filename.check_suffix s ".a" then begin - linker_options := s :: !linker_options; - parse_cmdline (i + 1) - end else begin - eprintf "Unknown argument `%s'\n" s; - eprintf "Usage: %s" usage_string; - exit 2 - end - end + linker_options := objfile :: !linker_options); + ".*\\.[oa]$", Self (fun s -> + linker_options := s :: !linker_options) +] let _ = Cil.initCIL(); CPragmas.initialize(); - parse_cmdline 1; - if not (!option_c || !option_S || !option_E) then begin + parse_cmdline cmdline_actions usage_string; + if !linker_options <> [] + && not (!option_c || !option_S || !option_E) + then begin linker !exe_name !linker_options end -- cgit v1.2.3