SCM Repository
View of /trunk/src/compiler/driver/options.sml
Parent Directory
|
Revision Log
Revision 2473 -
(download)
(annotate)
Sat Oct 12 14:35:40 2013 UTC (8 years, 7 months ago) by jhr
File size: 4375 byte(s)
Sat Oct 12 14:35:40 2013 UTC (8 years, 7 months ago) by jhr
File size: 4375 byte(s)
merging in more changes from stage
(* options.sml * * COPYRIGHT (c) 2011 The Diderot Project (http://diderot-language.cs.uchicago.edu) * All rights reserved. * * Support for processing runtime options. *) structure Options : sig exception Usage of string val parseCmdLine : string list -> { help : bool, (* "-help" specified? *) log : bool, (* logging enabled? *) defs : string list, (* input-variable definitions *) target : TargetUtil.target_desc, output : string option, (* "-o" specified file *) file : string } val usage : string -> string end = struct structure G = GetOpt exception Usage of string (* some option flags *) val helpFlg = ref false val debugFlg = ref false val doubleFlg = ref false val outputOpt : string option ref = ref NONE val logFlg = ref false val statsFlg = Stats.reportStats val target = ref TargetUtil.TARGET_C val parallel = ref false fun setFlag (flg, value) = G.NoArg(fn () => (flg := value)) fun mkFlagOption (tag, flag, desc) = let val default = !flag val tag = if default then "disable-"^tag else "enable-"^tag in { short = "", long = [tag], desc = setFlag (flag, not default), help = desc } end (* create the target option descriptor. *) local val desc = if Paths.cudaEnabled then [" cuda -- generate CUDA code"] else [] val desc = if Paths.clEnabled then " cl -- generate OpenCL code" :: desc else desc val desc = " pthread -- generate parallel C code" :: desc val desc = " c -- generate C code (default)" :: desc val desc = "specify the target platform:" :: desc fun parseTargetOpt "c" = (target := TargetUtil.TARGET_C) | parseTargetOpt "cl" = if Paths.clEnabled then (target := TargetUtil.TARGET_CL) else raise Usage "cl target not supported by this version" | parseTargetOpt "cuda" = if Paths.cudaEnabled then (target := TargetUtil.TARGET_CUDA) else raise Usage "cuda target not supported by this version" | parseTargetOpt "pthread" = (target := TargetUtil.TARGET_C; parallel := true) | parseTargetOpt opt = raise Usage(concat["unrecognized target \"", opt, "\""]) in val targetOptDesc = { short = "", long = ["target"], desc = G.ReqArg(parseTargetOpt, "target"), help = String.concatWith "\n" desc } end val optionList = [ { short = "h", long = ["help"], desc = setFlag (helpFlg, true), help = "print command-line options" }, { short = "o", long = ["output"], desc = G.ReqArg(fn s => outputOpt := SOME s, "file"), help = "specify the executable file name" }, { short = "g", long = ["debug"], desc = setFlag (debugFlg, true), help = "enable debugging information in executable" }, { short = "", long = ["double"], desc = setFlag (doubleFlg, true), help = "use double-precision floats for reals" }, { short = "", long = ["log"], desc = setFlag (logFlg, true), help = "generate compiler debugging log" }, { short = "", long = ["stats"], desc = setFlag (statsFlg, true), help = "report optimization statistics" }, targetOptDesc (* TODO: -double *) ] @ List.map mkFlagOption HighOptimizer.controls @ List.map mkFlagOption MidOptimizer.controls @ List.map mkFlagOption LowOptimizer.controls fun parseCmdLine args = let (* first we filter out any variable definitions *) val (defs, rest) = List.partition CmdLineInputs.isCmdLineInput args val (opts, files) = G.getOpt { argOrder = G.RequireOrder, options = optionList, errFn = fn s => raise Usage s } args (* figure out target details *) val targetDesc = { target = !target, parallel = !parallel, double = !doubleFlg, debug = !debugFlg } in { help = !helpFlg, log = !logFlg, defs = defs, target = targetDesc, output = !outputOpt, file = (case files of [] => if !helpFlg then "" else raise Usage "missing file argument" | f::_ => f (* end case *)) } end fun usage cmd = G.usageInfo { header = concat["usage: ", cmd, " [options] file.diderot\n Options:"], options = optionList } end
root@smlnj-gforge.cs.uchicago.edu | ViewVC Help |
Powered by ViewVC 1.0.0 |