Skip to content

Commit 799ca17

Browse files
author
tang0th
committed
Allow override of --opt-level flag. Fixes rust-lang#7493. Add -O0, -O1, -O2
and -O3 flags.
1 parent 0299b52 commit 799ca17

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/librustc/driver/config.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use syntax::parse;
3232
use syntax::parse::token::InternedString;
3333

3434
use collections::HashSet;
35-
use getopts::{optopt, optmulti, optflag, optflagopt};
35+
use getopts::{opt, optopt, optmulti, optflag, optflagopt};
3636
use getopts;
3737
use lib::llvm::llvm;
3838
use std::cell::{RefCell};
@@ -511,9 +511,9 @@ pub fn optgroups() -> Vec<getopts::OptGroup> {
511511
optflag("", "no-trans", "Run all passes except translation; no output"),
512512
optflag("", "no-analysis",
513513
"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),
515516
optopt("o", "", "Write output to <filename>", "FILENAME"),
516-
optopt("", "opt-level", "Optimize with possible levels 0-3", "LEVEL"),
517517
optopt( "", "out-dir", "Write output to compiler-chosen filename in <dir>", "DIR"),
518518
optflag("", "parse-only", "Parse only; do not compile, assemble, or link"),
519519
optflagopt("", "pretty",
@@ -653,13 +653,13 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
653653
let opt_level = {
654654
if debugging_opts != 0 {
655655
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.
660660
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()) {
663663
None |
664664
Some("0") => No,
665665
Some("1") => Less,

0 commit comments

Comments
 (0)