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

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