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

SCM Repository

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

Annotation of /branches/vis12/src/compiler/driver/options.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2078 - (view) (download)

1 : jhr 1232 (* 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 :     structure Options : sig
10 :    
11 :     exception Usage of string
12 :    
13 :     val parseCmdLine : string list -> {
14 :     help : bool, (* "-help" specified? *)
15 :     log : bool, (* logging enabled? *)
16 :     defs : string list, (* input-variable definitions *)
17 :     target : TargetUtil.target_desc,
18 :     file : string
19 :     }
20 :    
21 :     val usage : string -> string
22 :    
23 :     end = struct
24 :    
25 :     structure G = GetOpt
26 : jhr 1705 structure P = OS.Path
27 : jhr 1232
28 :     exception Usage of string
29 :    
30 :     (* some option flags *)
31 :     val helpFlg = ref false
32 :     val debugFlg = ref false
33 :     val doubleFlg = ref false
34 : jhr 1570 val outputOpt : string option ref = ref NONE
35 : jhr 1693 val standaloneFlg = ref false
36 : jhr 1912 val snapshotFlg = ref false
37 : jhr 1705 val prefix : string option ref = ref NONE
38 : jhr 1570 val logFlg = ref false
39 : jhr 1232 val statsFlg = Stats.reportStats
40 :     val target = ref TargetUtil.TARGET_C
41 :     val parallel = ref false
42 : jhr 2078 val bspFlg = ref false
43 : jhr 1232
44 :     fun setFlag (flg, value) = G.NoArg(fn () => (flg := value))
45 :    
46 :     fun mkFlagOption (tag, flag, desc) = let
47 :     val default = !flag
48 :     val tag = if default
49 :     then "disable-"^tag
50 :     else "enable-"^tag
51 :     in {
52 :     short = "", long = [tag],
53 :     desc = setFlag (flag, not default),
54 :     help = desc
55 :     } end
56 :    
57 :     (* create the target option descriptor. *)
58 :     local
59 :     val desc = if Paths.cudaEnabled then [" cuda -- generate CUDA code"] else []
60 :     val desc = if Paths.clEnabled then " cl -- generate OpenCL code" :: desc else desc
61 :     val desc = " pthread -- generate parallel C code" :: desc
62 :     val desc = " c -- generate C code (default)" :: desc
63 :     val desc = "specify the target platform:" :: desc
64 :     fun parseTargetOpt "c" = (target := TargetUtil.TARGET_C)
65 :     | parseTargetOpt "cl" = if Paths.clEnabled
66 :     then (target := TargetUtil.TARGET_CL)
67 :     else raise Usage "cl target not supported by this version"
68 :     | parseTargetOpt "cuda" = if Paths.cudaEnabled
69 :     then (target := TargetUtil.TARGET_CUDA)
70 :     else raise Usage "cuda target not supported by this version"
71 :     | parseTargetOpt "pthread" = (target := TargetUtil.TARGET_C; parallel := true)
72 :     | parseTargetOpt opt = raise Usage(concat["unrecognized target \"", opt, "\""])
73 :     in
74 :     val targetOptDesc = {
75 :     short = "",
76 :     long = ["target"],
77 :     desc = G.ReqArg(parseTargetOpt, "target"),
78 :     help = String.concatWith "\n" desc
79 :     }
80 :     end
81 :    
82 :     val optionList = [
83 :     { short = "h", long = ["help"],
84 :     desc = setFlag (helpFlg, true),
85 :     help = "print command-line options"
86 :     },
87 : jhr 1693 { short = "", long = ["exec"],
88 :     desc = setFlag (standaloneFlg, true),
89 :     help = "generate a standalone executable"
90 :     },
91 : jhr 1570 { short = "o", long = ["output"],
92 :     desc = G.ReqArg(fn s => outputOpt := SOME s, "file"),
93 :     help = "specify the executable file name"
94 :     },
95 : jhr 1705 { short = "", long = ["namespace"],
96 :     desc = G.ReqArg(fn s => prefix := SOME s, "prefix"),
97 :     help = "specify namespace prefix for generated code"
98 :     },
99 : jhr 1912 { short = "", long = ["snapshot"],
100 :     desc = setFlag (snapshotFlg, true),
101 :     help = "generate code to get a snapshot of strand states"
102 :     },
103 : jhr 1232 { short = "g", long = ["debug"],
104 :     desc = setFlag (debugFlg, true),
105 :     help = "enable debugging information in executable"
106 :     },
107 : jhr 1640 { short = "", long = ["double"],
108 :     desc = setFlag (doubleFlg, true),
109 :     help = "use double-precision floats for reals"
110 :     },
111 : jhr 1232 { short = "", long = ["log"],
112 :     desc = setFlag (logFlg, true),
113 :     help = "generate compiler debugging log"
114 :     },
115 :     { short = "", long = ["stats"],
116 :     desc = setFlag (statsFlg, true),
117 :     help = "report optimization statistics"
118 :     },
119 : jhr 2078 targetOptDesc,
120 :     { short = "", long = ["force-bsp"],
121 :     desc = setFlag (bspFlg, true),
122 :     help = "execute strands in BSP mode"
123 :     }
124 : jhr 1232 ]
125 :     @ List.map mkFlagOption HighOptimizer.controls
126 :     @ List.map mkFlagOption MidOptimizer.controls
127 :     @ List.map mkFlagOption LowOptimizer.controls
128 :    
129 :     fun parseCmdLine args = let
130 :     (* first we filter out any variable definitions *)
131 : jhr 2012 val (defs, rest) = List.partition CmdLineInputs.isCmdLineInput args
132 : jhr 1232 val (opts, files) = G.getOpt {
133 :     argOrder = G.RequireOrder,
134 :     options = optionList,
135 :     errFn = fn s => raise Usage s
136 :     } args
137 : jhr 1705 (* figure out filename pieces *)
138 :     val srcFile = (case files
139 :     of [] => if !helpFlg then "" else raise Usage "missing file argument"
140 :     | [f] => f
141 :     | _ => raise Usage "too many files"
142 :     (* end case *))
143 :     val (outDir, outBase) = (case !outputOpt
144 :     of NONE => let
145 :     val {dir, file} = P.splitDirFile srcFile
146 :     in
147 :     case P.splitBaseExt file
148 :     of {base, ext=SOME "diderot"} => (dir, base)
149 :     | _ => (dir, file)
150 :     (* end case *)
151 :     end
152 :     | SOME outFile => let
153 :     val {dir, file} = P.splitDirFile outFile
154 :     in
155 :     if !standaloneFlg
156 :     then (dir, file)
157 :     else (case P.splitBaseExt file
158 :     of {base, ext=SOME "o"} => (dir, base)
159 :     | {base, ext=SOME "obj"} => (dir, base)
160 :     | _ => (dir, file)
161 :     (* end case *))
162 :     end
163 :     (* end case *))
164 : jhr 1232 (* figure out target details *)
165 : jhr 1705 val targetDesc : TargetUtil.target_desc = {
166 :     srcFile = srcFile,
167 :     outDir = outDir,
168 :     outBase = outBase,
169 : jhr 1704 exec = !standaloneFlg,
170 : jhr 1912 snapshot = not(!standaloneFlg) andalso !snapshotFlg,
171 : jhr 1232 target = !target,
172 : jhr 1713 namespace = Option.getOpt(!prefix, "Diderot")^"_",
173 : jhr 1232 parallel = !parallel,
174 :     double = !doubleFlg,
175 : jhr 1706 longint = false, (* currently always false *)
176 : jhr 2078 debug = !debugFlg,
177 :     bsp = !bspFlg
178 : jhr 1232 }
179 :     in {
180 :     help = !helpFlg,
181 :     log = !logFlg,
182 :     defs = defs,
183 :     target = targetDesc,
184 : jhr 1705 file = srcFile
185 : jhr 1232 } end
186 :    
187 :     fun usage cmd = G.usageInfo {
188 :     header = concat["usage: ", cmd, " [options] file.diderot\n Options:"],
189 :     options = optionList
190 :     }
191 :    
192 :     end

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