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

SCM Repository

[diderot] Annotation of /branches/vis15/src/compiler/options/options.sml
ViewVC logotype

Annotation of /branches/vis15/src/compiler/options/options.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3351 - (view) (download)

1 : jhr 3351 (* options.sml
2 :     *
3 :     * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
4 :     *
5 :     * COPYRIGHT (c) 2015 The University of Chicago
6 :     * All rights reserved.
7 :     *)
8 :    
9 :     structure Options : sig
10 :    
11 :     (* raised if parsing command-line args hits an error (e.g., missing option, syntax, ...).
12 :     * The string is an error message.
13 :     *)
14 :     exception Usage of string
15 :    
16 :     (* parse the command-line args *)
17 :     val parseCmdLine : string list -> {
18 :     help : bool option, (* "-h" and "--help" ==> SOME false; "-H" ==> SOME true. *)
19 :     version : bool, (* "--version" specified? *)
20 :     defs : string list, (* input-variable definitions *)
21 :     target : Target.desc, (* collected infromation about the target *)
22 :     file : string (* source file *)
23 :     }
24 :    
25 :     (* return a usage message. The boolean controls whether all options should be
26 :     * included (true ==> long; false ==> short).
27 :     *)
28 :     val usage : string * bool -> string
29 :    
30 :     end = struct
31 :    
32 :     structure G = GetOpt
33 :     structure P = OS.Path
34 :    
35 :     exception Usage of string
36 :    
37 :     (* option flags that are set by getOpt *)
38 :     val helpFlg = ref(NONE : bool option) (* SOME false -- short help; SOME true -- long help *)
39 :     val longHelp = ref false
40 :     val versionFlg = ref false
41 :     val debugFlg = ref false
42 :     val doubleFlg = ref false
43 :     val outputOpt : string option ref = ref NONE
44 :     val standaloneFlg = ref false
45 :     val snapshotFlg = ref false
46 :     val prefix : string option ref = ref NONE
47 :     val target = ref Target.SEQUENTIAL
48 :     val bspFlg = ref false
49 :    
50 :     (* package a boolean control as a GetOpt option descriptor (NoArg) *)
51 :     (** NOTE: this function will be part of the Controls structure as of 110.80 *)
52 :     fun mkOptionFlag {ctl, short, long} = {
53 :     short = short,
54 :     long = (case long of NONE => [] | SOME opt => [opt]),
55 :     desc = G.NoArg(Controls.set' (ctl, true)),
56 :     help = #help(Controls.info ctl)
57 :     }
58 :    
59 :     (** NOTE: this function can use Controls.mkOptionFlag as of 110.80 *)
60 :     fun mkOpt ctl = let
61 :     val name = if Controls.get ctl
62 :     then "disable-" ^ Controls.name ctl
63 :     else "enable-" ^ Controls.name ctl
64 :     in
65 :     mkOptionFlag {ctl = ctl, short = "", long = SOME name}
66 :     end
67 :    
68 :     (* create the target option descriptor. *)
69 :     local
70 :     val desc = if Paths.cudaEnabled then [" cuda -- generate CUDA code"] else []
71 :     val desc = if Paths.clEnabled then " opencl -- generate OpenCL code" :: desc else desc
72 :     val desc = " parallel -- generate parallel code" :: desc
73 :     val desc = " sequential -- generate sequential code (default)" :: desc
74 :     val desc = "specify the target platform:" :: desc
75 :     fun parseTargetOpt "c" = (target := Target.SEQUENTIAL)
76 :     | parseTargetOpt "sequential" = (target := Target.SEQUENTIAL)
77 :     | parseTargetOpt "parallel" = (target := Target.PARALLEL)
78 :     | parseTargetOpt "pthread" = (target := Target.PARALLEL)
79 :     | parseTargetOpt "cl" = if Paths.clEnabled
80 :     then (target := Target.OPENCL)
81 :     else raise Usage "cl target not supported by this version"
82 :     | parseTargetOpt "opencl" = if Paths.clEnabled
83 :     then (target := Target.OPENCL)
84 :     else raise Usage "cl target not supported by this version"
85 :     | parseTargetOpt "cuda" = if Paths.cudaEnabled
86 :     then (target := Target.CUDA)
87 :     else raise Usage "cuda target not supported by this version"
88 :     | parseTargetOpt opt = raise Usage(concat["unrecognized target \"", opt, "\""])
89 :     in
90 :     val targetOptDesc = {
91 :     short = "",
92 :     long = ["target"],
93 :     desc = G.ReqArg(parseTargetOpt, "target"),
94 :     help = String.concatWith "\n" desc
95 :     }
96 :     end
97 :    
98 :     fun setFlag (flg, value) = G.NoArg(fn () => (flg := value))
99 :    
100 :     (* the short list of options, which does not include the compiler controls *)
101 :     val optionList = [
102 :     { short = "h", long = ["help"],
103 :     desc = setFlag (helpFlg, SOME false),
104 :     help = "print command-line options"
105 :     },
106 :     { short = "H", long = [],
107 :     desc = setFlag (helpFlg, SOME true),
108 :     help = "print all command-line options (including compiler controls)"
109 :     },
110 :     { short = "", long = ["version"],
111 :     desc = setFlag (versionFlg, true),
112 :     help = "show the compiler version"
113 :     },
114 :     { short = "", long = ["exec"],
115 :     desc = setFlag (standaloneFlg, true),
116 :     help = "generate a standalone executable"
117 :     },
118 :     { short = "o", long = ["output"],
119 :     desc = G.ReqArg(fn s => outputOpt := SOME s, "file"),
120 :     help = "specify the executable file name"
121 :     },
122 :     { short = "", long = ["namespace"],
123 :     desc = G.ReqArg(fn s => prefix := SOME s, "prefix"),
124 :     help = "specify namespace prefix for generated code"
125 :     },
126 :     { short = "", long = ["snapshot"],
127 :     desc = setFlag (snapshotFlg, true),
128 :     help = "generate code to get a snapshot of strand states"
129 :     },
130 :     { short = "g", long = ["debug"],
131 :     desc = setFlag (debugFlg, true),
132 :     help = "enable debugging information in executable"
133 :     },
134 :     { short = "", long = ["double"],
135 :     desc = setFlag (doubleFlg, true),
136 :     help = "use double-precision floats for reals"
137 :     },
138 :     mkOpt Ctl.enableLog,
139 :     mkOpt Ctl.collectStats,
140 :     targetOptDesc
141 :     ]
142 :    
143 :     (* create the list of options that control compiler internals *)
144 :     val ctlOptions =
145 :     { short = "", long = ["force-bsp"],
146 :     desc = setFlag (bspFlg, true),
147 :     help = "execute strands in BSP mode"
148 :     } ::
149 :     (List.map mkOpt [
150 :     Ctl.dumpAST, Ctl.dumpSimple, Ctl.dumpHighIL, Ctl.dumpMidIl, Ctl.dumpLowIL, Ctl.dumpTreeIL,
151 :     Ctl.checkAST, Ctl.checkSimple, Ctl.checkHighIL, Ctl.checkMidIl, Ctl.checkLowIL, Ctl.checkTreeIL
152 :     ])
153 :    
154 :    
155 :     fun parseCmdLine args = let
156 :     (* first we filter out any variable definitions *)
157 :     val (defs, rest) = List.partition CmdLineInputs.isCmdLineInput args
158 :     val (opts, files) = G.getOpt {
159 :     argOrder = G.RequireOrder,
160 :     options = optionList,
161 :     errFn = fn s => raise Usage s
162 :     } args
163 :     (* figure out filename pieces *)
164 :     val srcFile = if isSome(!helpFlg) orelse !versionFlg
165 :     then ""
166 :     else (case files
167 :     of [] => raise Usage "missing file argument"
168 :     | [f] => f
169 :     | _ => raise Usage "too many files"
170 :     (* end case *))
171 :     val (outDir, outBase) = (case !outputOpt
172 :     of NONE => let
173 :     val {dir, file} = P.splitDirFile srcFile
174 :     in
175 :     case P.splitBaseExt file
176 :     of {base, ext=SOME "diderot"} => (dir, base)
177 :     | _ => (dir, file)
178 :     (* end case *)
179 :     end
180 :     | SOME outFile => let
181 :     val {dir, file} = P.splitDirFile outFile
182 :     in
183 :     if !standaloneFlg
184 :     then (dir, file)
185 :     else (case P.splitBaseExt file
186 :     of {base, ext=SOME "o"} => (dir, base)
187 :     | {base, ext=SOME "obj"} => (dir, base)
188 :     | _ => (dir, file)
189 :     (* end case *))
190 :     end
191 :     (* end case *))
192 :     (* figure out target details *)
193 :     val targetDesc : Target.desc = {
194 :     version = Version.message,
195 :     srcFile = srcFile,
196 :     outDir = outDir,
197 :     outBase = outBase,
198 :     exec = !standaloneFlg,
199 :     snapshot = not(!standaloneFlg) andalso !snapshotFlg,
200 :     target = !target,
201 :     namespace = Option.getOpt(!prefix, "Diderot")^"_",
202 :     double = !doubleFlg,
203 :     longint = false, (* currently always false *)
204 :     debug = !debugFlg,
205 :     bsp = !bspFlg
206 :     }
207 :     in {
208 :     help = !helpFlg,
209 :     version = !versionFlg,
210 :     defs = defs,
211 :     target = targetDesc,
212 :     file = srcFile
213 :     } end
214 :    
215 :     fun usage (cmd, long) = G.usageInfo {
216 :     header = concat[
217 :     "usage: ", cmd, " [options] file.diderot\n",
218 :     " Version: ", Version.message, "\n",
219 :     " Options:"
220 :     ],
221 :     options = optionList
222 :     }
223 :    
224 :     end

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