@@ -32,7 +32,7 @@ use syntax::parse;
32
32
use syntax:: parse:: token:: InternedString ;
33
33
34
34
use collections:: HashSet ;
35
- use getopts:: { optopt, optmulti, optflag, optflagopt} ;
35
+ use getopts:: { opt , optopt, optmulti, optflag, optflagopt} ;
36
36
use getopts;
37
37
use lib:: llvm:: llvm;
38
38
use std:: cell:: { RefCell } ;
@@ -511,9 +511,9 @@ pub fn optgroups() -> Vec<getopts::OptGroup> {
511
511
optflag( "" , "no-trans" , "Run all passes except translation; no output" ) ,
512
512
optflag( "" , "no-analysis" ,
513
513
"Parse and expand the source, but run no analysis and produce no output" ) ,
514
- optflag( "O" , "" , "Equivalent to --opt-level=2" ) ,
514
+ opt( "O" , "opt-level" , "Optimize with possible levels 0-3" , "LEVEL" , getopts:: Maybe ,
515
+ getopts:: Multi ) ,
515
516
optopt( "o" , "" , "Write output to <filename>" , "FILENAME" ) ,
516
- optopt( "" , "opt-level" , "Optimize with possible levels 0-3" , "LEVEL" ) ,
517
517
optopt( "" , "out-dir" , "Write output to compiler-chosen filename in <dir>" , "DIR" ) ,
518
518
optflag( "" , "parse-only" , "Parse only; do not compile, assemble, or link" ) ,
519
519
optflagopt( "" , "pretty" ,
@@ -653,13 +653,13 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
653
653
let opt_level = {
654
654
if debugging_opts != 0 {
655
655
No
656
- } else if matches. opt_present ( "O" ) {
657
- if matches . opt_present ( "opt-level" ) {
658
- early_error ( " -O and --opt-level both provided" ) ;
659
- }
656
+ } else if ( matches. opt_count ( "O" ) == 1 ) && ( matches . opt_strs ( "O" ) . len ( ) == 0 ) {
657
+ // FIXME: This is hack to support -O defaulting to -O2 if it is the only -O or
658
+ // --opt-level arg. Consider removing -O or moving it to another flag. If this
659
+ // is done then change type of -O flag to optmulti.
660
660
Default
661
- } else if matches. opt_present ( "opt-level " ) {
662
- match matches. opt_str ( "opt-level" ) . as_ref ( ) . map ( |s| s. as_slice ( ) ) {
661
+ } else if matches. opt_present ( "O " ) {
662
+ match matches. opt_strs ( "O" ) . last ( ) . as_ref ( ) . map ( |s| s. as_slice ( ) ) {
663
663
None |
664
664
Some ( "0" ) => No ,
665
665
Some ( "1" ) => Less ,
0 commit comments