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 1232 - (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 :    
27 :     exception Usage of string
28 :    
29 :     (* 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 :    
38 :     fun setFlag (flg, value) = G.NoArg(fn () => (flg := value))
39 :    
40 :     fun mkFlagOption (tag, flag, desc) = let
41 :     val default = !flag
42 :     val tag = if default
43 :     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 :    
51 :     (* create the target option descriptor. *)
52 :     local
53 :     val desc = if Paths.cudaEnabled then [" cuda -- generate CUDA code"] else []
54 :     val desc = if Paths.clEnabled then " cl -- generate OpenCL code" :: desc else desc
55 :     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 :     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 :     in
68 :     val targetOptDesc = {
69 :     short = "",
70 :     long = ["target"],
71 :     desc = G.ReqArg(parseTargetOpt, "target"),
72 :     help = String.concatWith "\n" desc
73 :     }
74 :     end
75 :    
76 :     val optionList = [
77 :     { short = "h", long = ["help"],
78 :     desc = setFlag (helpFlg, true),
79 :     help = "print command-line options"
80 :     },
81 :     { short = "g", long = ["debug"],
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 :     targetOptDesc
94 :     (* TODO: -double *)
95 :     ]
96 :     @ List.map mkFlagOption HighOptimizer.controls
97 :     @ List.map mkFlagOption MidOptimizer.controls
98 :     @ List.map mkFlagOption LowOptimizer.controls
99 :    
100 :     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 Usage 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 :    
126 :     fun usage cmd = G.usageInfo {
127 :     header = concat["usage: ", cmd, " [options] file.diderot\n Options:"],
128 :     options = optionList
129 :     }
130 :    
131 :     end

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