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

SCM Repository

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

Annotation of /trunk/src/compiler/driver/options.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1640 - (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 : jhr 1570 output : string option, (* "-o" specified file *)
19 : jhr 1232 file : string
20 :     }
21 :    
22 :     val usage : string -> string
23 :    
24 :     end = struct
25 :    
26 :     structure G = GetOpt
27 :    
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 :     val logFlg = ref false
36 : jhr 1232 val statsFlg = Stats.reportStats
37 :     val target = ref TargetUtil.TARGET_C
38 :     val parallel = ref false
39 :    
40 :     fun setFlag (flg, value) = G.NoArg(fn () => (flg := value))
41 :    
42 :     fun mkFlagOption (tag, flag, desc) = let
43 :     val default = !flag
44 :     val tag = if default
45 :     then "disable-"^tag
46 :     else "enable-"^tag
47 :     in {
48 :     short = "", long = [tag],
49 :     desc = setFlag (flag, not default),
50 :     help = desc
51 :     } end
52 :    
53 :     (* create the target option descriptor. *)
54 :     local
55 :     val desc = if Paths.cudaEnabled then [" cuda -- generate CUDA code"] else []
56 :     val desc = if Paths.clEnabled then " cl -- generate OpenCL code" :: desc else desc
57 :     val desc = " pthread -- generate parallel C code" :: desc
58 :     val desc = " c -- generate C code (default)" :: desc
59 :     val desc = "specify the target platform:" :: desc
60 :     fun parseTargetOpt "c" = (target := TargetUtil.TARGET_C)
61 :     | parseTargetOpt "cl" = if Paths.clEnabled
62 :     then (target := TargetUtil.TARGET_CL)
63 :     else raise Usage "cl target not supported by this version"
64 :     | parseTargetOpt "cuda" = if Paths.cudaEnabled
65 :     then (target := TargetUtil.TARGET_CUDA)
66 :     else raise Usage "cuda target not supported by this version"
67 :     | parseTargetOpt "pthread" = (target := TargetUtil.TARGET_C; parallel := true)
68 :     | parseTargetOpt opt = raise Usage(concat["unrecognized target \"", opt, "\""])
69 :     in
70 :     val targetOptDesc = {
71 :     short = "",
72 :     long = ["target"],
73 :     desc = G.ReqArg(parseTargetOpt, "target"),
74 :     help = String.concatWith "\n" desc
75 :     }
76 :     end
77 :    
78 :     val optionList = [
79 :     { short = "h", long = ["help"],
80 :     desc = setFlag (helpFlg, true),
81 :     help = "print command-line options"
82 :     },
83 : jhr 1570 { short = "o", long = ["output"],
84 :     desc = G.ReqArg(fn s => outputOpt := SOME s, "file"),
85 :     help = "specify the executable file name"
86 :     },
87 : jhr 1232 { short = "g", long = ["debug"],
88 :     desc = setFlag (debugFlg, true),
89 :     help = "enable debugging information in executable"
90 :     },
91 : jhr 1640 { short = "", long = ["double"],
92 :     desc = setFlag (doubleFlg, true),
93 :     help = "use double-precision floats for reals"
94 :     },
95 : jhr 1232 { short = "", long = ["log"],
96 :     desc = setFlag (logFlg, true),
97 :     help = "generate compiler debugging log"
98 :     },
99 :     { short = "", long = ["stats"],
100 :     desc = setFlag (statsFlg, true),
101 :     help = "report optimization statistics"
102 :     },
103 :     targetOptDesc
104 :     (* TODO: -double *)
105 :     ]
106 :     @ List.map mkFlagOption HighOptimizer.controls
107 :     @ List.map mkFlagOption MidOptimizer.controls
108 :     @ List.map mkFlagOption LowOptimizer.controls
109 :    
110 :     fun parseCmdLine args = let
111 :     (* first we filter out any variable definitions *)
112 :     val (defs, rest) = List.partition Inputs.isCmdLineInput args
113 :     val (opts, files) = G.getOpt {
114 :     argOrder = G.RequireOrder,
115 :     options = optionList,
116 :     errFn = fn s => raise Usage s
117 :     } args
118 :     (* figure out target details *)
119 :     val targetDesc = {
120 :     target = !target,
121 :     parallel = !parallel,
122 :     double = !doubleFlg,
123 :     debug = !debugFlg
124 :     }
125 :     in {
126 :     help = !helpFlg,
127 :     log = !logFlg,
128 :     defs = defs,
129 :     target = targetDesc,
130 : jhr 1570 output = !outputOpt,
131 : jhr 1232 file = (case files
132 :     of [] => if !helpFlg then "" else raise Usage "missing file argument"
133 :     | f::_ => f
134 :     (* end case *))
135 :     } end
136 :    
137 :     fun usage cmd = G.usageInfo {
138 :     header = concat["usage: ", cmd, " [options] file.diderot\n Options:"],
139 :     options = optionList
140 :     }
141 :    
142 :     end

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