Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Diff of /branches/pure-cfg/src/compiler/driver/options.sml
ViewVC logotype

Diff of /branches/pure-cfg/src/compiler/driver/options.sml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1201, Thu May 12 17:14:24 2011 UTC revision 1202, Thu May 12 18:49:23 2011 UTC
# Line 8  Line 8 
8    
9  structure Options : sig  structure Options : sig
10    
11      val doOptions : string list -> {      exception Usage of string
12    
13        val parseCmdLine : string list -> {
14                help : bool,                        (* "-help" specified? *)
15              log : bool,                         (* logging enabled? *)              log : bool,                         (* logging enabled? *)
16              defs : string list,                 (* input-variable definitions *)              defs : string list,                 (* input-variable definitions *)
17              target : TargetUtil.target_desc              target : TargetUtil.target_desc,
18                file : string
19            }            }
20    
21        val usage : string -> string
22    
23    end = struct    end = struct
24    
25      datatype arg_desc      structure G = GetOpt
26        = NoArg of unit -> unit  
27        | ReqArg of string * (string -> unit)      exception Usage of string
28        | OptArg of string * (string option -> unit)  
29      (* some option flags *)
30      type option = (      val logFlg = ref false
31          string *                (* the option, including leading "-" *)      val helpFlg = ref false
32          arg_desc *              (* argument description *)      val debugFlg = ref false
33          string list             (* description; each string is printed on a separate *)      val doubleFlg = ref false
34                                  (* line when listing the options *)      val statsFlg = Stats.reportStats
35        )      val target = ref TargetUtil.TARGET_C
36        val parallel = ref false
37    
38      fun setFlag (flg, value) = NoArg(fn () => (flg := value))      fun setFlag (flg, value) = G.NoArg(fn () => (flg := value))
39    
40      fun mkFlagOption (tag, flag, desc) = let      fun mkFlagOption (tag, flag, desc) = let
41            val default = !flag            val default = !flag
42            val tag = if default            val tag = if default
43                  then "-disable-"^tag                  then "disable-"^tag
44                  else "-enable-"^tag                  else "enable-"^tag
45            in            in {
46              (tag, setFlag (flg, not default), desc)              short = "", long = [tag],
47            end              desc = setFlag (flag, not default),
48                help = desc
49              } end
50    
51    (* create the target option descriptor. *)    (* create the target option descriptor. *)
52      local      local
53        val desc = if Paths.cudaEnabled then ["  cuda    -- generate CUDA code"] else []        val desc = if Paths.cudaEnabled then ["  cuda    -- generate CUDA code"] else []
54        val desc = if Paths.cudaEnabled then  "  cl      -- generate OpenCL code" :: desc else desc        val desc = if Paths.clEnabled then  "  cl      -- generate OpenCL code" :: desc else desc
55        val desc = "  pthread -- generate parallel C code" :: desc        val desc = "  pthread -- generate parallel C code" :: desc
56        val desc = "  c       -- generate C code (default)" :: desc        val desc = "  c       -- generate C code (default)" :: desc
57        val desc = "specify the target platform:" :: desc        val desc = "specify the target platform:" :: desc
58          fun parseTargetOpt "c" = (target := TargetUtil.TARGET_C)
59            | parseTargetOpt "cl" = if Paths.clEnabled
60                then (target := TargetUtil.TARGET_CL)
61                else raise Usage "cl target not supported by this version"
62            | parseTargetOpt "cuda" = if Paths.cudaEnabled
63                then (target := TargetUtil.TARGET_CUDA)
64                else raise Usage "cuda target not supported by this version"
65            | parseTargetOpt "pthread" = (target := TargetUtil.TARGET_C; parallel := true)
66            | parseTargetOpt opt = raise Usage(concat["unrecognized target \"", opt, "\""])
67      in      in
68      val targetOptDesc = ( "-target", ReqArg, parseTargetOpt, desc )      val targetOptDesc = {
69                short = "",
70                long = ["target"],
71                desc = G.ReqArg(parseTargetOpt, "target"),
72                help = String.concatWith "\n" desc
73              }
74      end      end
75    
     local  
       val statsFlg = Stats.reportStats  
     in  
76      val optionList = [      val optionList = [
77              ( "-help",  setFlag helpFlg true, ["print command-line options"] ),              { short = "h", long = ["help"],
78              ( "-g",     setFlag debugFlg true, ["enable debugging information in executable"] ),                desc = setFlag (helpFlg, true),
79              ( "-log",   setFlag logFlg true, ["generate compiler debugging log"] ),                help = "print command-line options"
80              ( "-stats", setFlag statsFlg true, ["report optimization statistics"] ),              },
81                { short = "g", long = [],
82                  desc = setFlag (debugFlg, true),
83                  help = "enable debugging information in executable"
84                },
85                { short = "", long = ["log"],
86                  desc = setFlag (logFlg, true),
87                  help = "generate compiler debugging log"
88                },
89                { short = "", long = ["stats"],
90                  desc = setFlag (statsFlg, true),
91                  help = "report optimization statistics"
92                },
93              targetOptDesc              targetOptDesc
94  (* TODO: -double *)  (* TODO: -double *)
95            ]            ]
96            @ List.map mkFlagOption HighOptimizer.controls            @ List.map mkFlagOption HighOptimizer.controls
97            @ List.map mkFlagOption MidOptimizer.controls            @ List.map mkFlagOption MidOptimizer.controls
98            @ List.map mkFlagOption LowOptimizer.controls            @ List.map mkFlagOption LowOptimizer.controls
     end  
99    
100  (*      fun parseCmdLine args = let
101      fun doOptions args = let          (* first we filter out any variable definitions *)
102            val log = ref false            val (defs, rest) = List.partition Inputs.isCmdLineInput args
103            val defs = ref []            val (opts, files) = G.getOpt {
104            fun doOpts [file] = {log = !log, defs = !defs, file = file}                    argOrder = G.RequireOrder,
105              | doOpts ("-log"::r) = (log := true; doOpts r)                    options = optionList,
106              | doOpts (opt::r) =                    errFn = fn s => raise Fail s
107                  if Inputs.isCmdLineInput opt                  } args
108                    then (defs := opt :: !defs; doOpts r)          (* figure out target details *)
109                    else (            val targetDesc = {
110                      err(concat["invalid command-line input \"", opt, "\"\n"]);                    target = !target,
111                      raise ERROR)                    parallel = !parallel,
112            in                    double = !doubleFlg,
113              doOpts args                    debug = !debugFlg
114            end                  }
115  *)            in {
116                help = !helpFlg,
117                log = !logFlg,
118                defs = defs,
119                target = targetDesc,
120                file = (case files
121                   of [] => if !helpFlg then "" else raise Usage "missing file argument"
122                    | f::_ => f
123                  (* end case *))
124              } end
125    
126        fun usage cmd = G.usageInfo {
127                header = concat["usage: ", cmd, " [options] file.diderot\n  Options:"],
128                options = optionList
129              }
130    
131    end    end

Legend:
Removed from v.1201  
changed lines
  Added in v.1202

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0