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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1202 - (view) (download)

1 : jhr 1164 (* options.sml
2 :     *
3 :     * COPYRIGHT (c) 2011 The Diderot Project (http://diderot-language.cs.uchicago.edu)
4 :     * All rights reserved.
5 :     *
6 :     * Support for processing runtime options.
7 :     *)
8 :    
9 : jhr 1183 structure Options : sig
10 : jhr 1164
11 : jhr 1202 exception Usage of string
12 :    
13 :     val parseCmdLine : string list -> {
14 :     help : bool, (* "-help" specified? *)
15 : jhr 1183 log : bool, (* logging enabled? *)
16 :     defs : string list, (* input-variable definitions *)
17 : jhr 1202 target : TargetUtil.target_desc,
18 :     file : string
19 : jhr 1183 }
20 : jhr 1164
21 : jhr 1202 val usage : string -> string
22 :    
23 : jhr 1183 end = struct
24 :    
25 : jhr 1202 structure G = GetOpt
26 : jhr 1183
27 : jhr 1202 exception Usage of string
28 : jhr 1164
29 : jhr 1202 (* some option flags *)
30 :     val logFlg = ref false
31 :     val helpFlg = ref false
32 :     val debugFlg = ref false
33 :     val doubleFlg = ref false
34 :     val statsFlg = Stats.reportStats
35 :     val target = ref TargetUtil.TARGET_C
36 :     val parallel = ref false
37 : jhr 1172
38 : jhr 1202 fun setFlag (flg, value) = G.NoArg(fn () => (flg := value))
39 :    
40 : jhr 1172 fun mkFlagOption (tag, flag, desc) = let
41 :     val default = !flag
42 :     val tag = if default
43 : jhr 1202 then "disable-"^tag
44 :     else "enable-"^tag
45 :     in {
46 :     short = "", long = [tag],
47 :     desc = setFlag (flag, not default),
48 :     help = desc
49 :     } end
50 : jhr 1164
51 : jhr 1172 (* create the target option descriptor. *)
52 :     local
53 :     val desc = if Paths.cudaEnabled then [" cuda -- generate CUDA code"] else []
54 : jhr 1202 val desc = if Paths.clEnabled then " cl -- generate OpenCL code" :: desc else desc
55 : jhr 1172 val desc = " pthread -- generate parallel C code" :: desc
56 :     val desc = " c -- generate C code (default)" :: desc
57 :     val desc = "specify the target platform:" :: desc
58 : jhr 1202 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 : jhr 1172 in
68 : jhr 1202 val targetOptDesc = {
69 :     short = "",
70 :     long = ["target"],
71 :     desc = G.ReqArg(parseTargetOpt, "target"),
72 :     help = String.concatWith "\n" desc
73 :     }
74 : jhr 1172 end
75 :    
76 :     val optionList = [
77 : jhr 1202 { short = "h", long = ["help"],
78 :     desc = setFlag (helpFlg, true),
79 :     help = "print command-line options"
80 :     },
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 : jhr 1172 targetOptDesc
94 :     (* TODO: -double *)
95 :     ]
96 :     @ List.map mkFlagOption HighOptimizer.controls
97 :     @ List.map mkFlagOption MidOptimizer.controls
98 :     @ List.map mkFlagOption LowOptimizer.controls
99 : jhr 1183
100 : jhr 1202 fun parseCmdLine args = let
101 :     (* first we filter out any variable definitions *)
102 :     val (defs, rest) = List.partition Inputs.isCmdLineInput args
103 :     val (opts, files) = G.getOpt {
104 :     argOrder = G.RequireOrder,
105 :     options = optionList,
106 :     errFn = fn s => raise Fail s
107 :     } args
108 :     (* figure out target details *)
109 :     val targetDesc = {
110 :     target = !target,
111 :     parallel = !parallel,
112 :     double = !doubleFlg,
113 :     debug = !debugFlg
114 :     }
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 : jhr 1164
126 : jhr 1202 fun usage cmd = G.usageInfo {
127 :     header = concat["usage: ", cmd, " [options] file.diderot\n Options:"],
128 :     options = optionList
129 :     }
130 :    
131 : jhr 1164 end

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