@@ -165,7 +165,8 @@ options:
165
165
--depend print dependencies, in makefile-rule form
166
166
--parse-only parse only; do not compile, assemble, or link
167
167
-g produce debug info
168
- -O optimize
168
+ --OptLevel= optimize with possible levels 0-3
169
+ -O equivalent to --OptLevel=2
169
170
-S compile only; do not assemble or link
170
171
-c compile and assemble, but do not link
171
172
--emit-llvm produce an LLVM bitcode file
@@ -228,8 +229,9 @@ fn main(vec[str] args) {
228
229
optflag ( "glue" ) , optflag ( "emit-llvm" ) ,
229
230
optflag ( "pretty" ) , optflag ( "typed-pretty" ) ,
230
231
optflag ( "ls" ) , optflag ( "parse-only" ) ,
231
- optflag ( "O" ) , optflag ( "shared" ) , optmulti ( "L" ) ,
232
- optflag ( "S" ) , optflag ( "c" ) , optopt ( "o" ) , optflag ( "g" ) ,
232
+ optflag ( "O" ) , optopt ( "OptLevel" ) ,
233
+ optflag ( "shared" ) , optmulti ( "L" ) ,
234
+ optflag ( "S" ) , optflag ( "c" ) , optopt ( "o" ) , optopt ( "g" ) ,
233
235
optflag ( "save-temps" ) , optopt ( "sysroot" ) ,
234
236
optflag ( "stats" ) ,
235
237
optflag ( "time-passes" ) , optflag ( "time-llvm-passes" ) ,
@@ -276,15 +278,46 @@ fn main(vec[str] args) {
276
278
277
279
auto verify = !opt_present( match , "noverify" ) ;
278
280
auto save_temps = opt_present( match , "save-temps" ) ;
279
- // FIXME: Maybe we should support -O0, -O1, -Os, etc
280
- auto optimize = opt_present( match , "O" ) ;
281
281
auto debuginfo = opt_present( match , "g" ) ;
282
282
auto stats = opt_present( match , "stats" ) ;
283
283
auto time_passes = opt_present( match , "time-passes" ) ;
284
284
auto time_llvm_passes = opt_present( match , "time-llvm-passes" ) ;
285
285
auto run_typestate = !opt_present( match , "no-typestate" ) ;
286
286
auto sysroot_opt = getopts:: opt_maybe_str( match , "sysroot" ) ;
287
287
288
+ let uint optLevel = 0 u;
289
+ if ( opt_present ( match , "O" ) ) {
290
+ optLevel = 2 u;
291
+ if ( opt_present ( match , "OptLevel" ) ) {
292
+ log
293
+ ( "error: -O and --OptLevel both provided" ) ;
294
+ fail;
295
+ }
296
+ }
297
+
298
+ if ( opt_present ( match , "OptLevel" ) ) {
299
+ auto opt = getopts:: opt_maybe_str ( match , "OptLevel" ) ;
300
+ alt ( opt) {
301
+ case ( some[ str] ( ?s) ) {
302
+ alt ( s) {
303
+ case ( "0" ) { optLevel = 0 u; }
304
+ case ( "1" ) { optLevel = 1 u; }
305
+ case ( "2" ) { optLevel = 2 u; }
306
+ case ( "3" ) { optLevel = 3 u; }
307
+ case ( _) {
308
+ log
309
+ ( "error: optimization level needs to be between 0-3" ) ;
310
+ fail;
311
+ }
312
+ }
313
+ }
314
+ case ( none[ str] ) {
315
+ log( "error: expected optimization level after --OptLevel=" ) ;
316
+ fail;
317
+ }
318
+ }
319
+ }
320
+
288
321
auto sysroot;
289
322
alt ( sysroot_opt) {
290
323
case ( none[ str] ) { sysroot = get_default_sysroot( binary) ; }
@@ -293,7 +326,7 @@ fn main(vec[str] args) {
293
326
294
327
let @session:: options sopts =
295
328
@rec ( shared = shared,
296
- optimize = optimize ,
329
+ optimize = optLevel ,
297
330
debuginfo = debuginfo,
298
331
verify = verify,
299
332
run_typestate = run_typestate,
0 commit comments