From 31d65453d47f243635ea17563db6b2c1127e9836 Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Thu, 19 May 2011 12:46:10 -0700 Subject: OptLevel changes. Accepts levels 0 to 3 only. '-O' is synonym for --OptLevel=2. --- src/comp/driver/rustc.rs | 45 +++++++++++++++++++++++++++++++++++++++------ src/comp/driver/session.rs | 2 +- 2 files changed, 40 insertions(+), 7 deletions(-) (limited to 'src/comp/driver') diff --git a/src/comp/driver/rustc.rs b/src/comp/driver/rustc.rs index 456cb0faa4c..0ce20eb2f15 100644 --- a/src/comp/driver/rustc.rs +++ b/src/comp/driver/rustc.rs @@ -165,7 +165,8 @@ options: --depend print dependencies, in makefile-rule form --parse-only parse only; do not compile, assemble, or link -g produce debug info - -O optimize + --OptLevel= optimize with possible levels 0-3 + -O equivalent to --OptLevel=2 -S compile only; do not assemble or link -c compile and assemble, but do not link --emit-llvm produce an LLVM bitcode file @@ -228,8 +229,9 @@ fn main(vec[str] args) { optflag("glue"), optflag("emit-llvm"), optflag("pretty"), optflag("typed-pretty"), optflag("ls"), optflag("parse-only"), - optflag("O"), optflag("shared"), optmulti("L"), - optflag("S"), optflag("c"), optopt("o"), optflag("g"), + optflag("O"), optopt("OptLevel"), + optflag("shared"), optmulti("L"), + optflag("S"), optflag("c"), optopt("o"), optopt("g"), optflag("save-temps"), optopt("sysroot"), optflag("stats"), optflag("time-passes"), optflag("time-llvm-passes"), @@ -276,8 +278,6 @@ fn main(vec[str] args) { auto verify = !opt_present(match, "noverify"); auto save_temps = opt_present(match, "save-temps"); - // FIXME: Maybe we should support -O0, -O1, -Os, etc - auto optimize = opt_present(match, "O"); auto debuginfo = opt_present(match, "g"); auto stats = opt_present(match, "stats"); auto time_passes = opt_present(match, "time-passes"); @@ -285,6 +285,39 @@ fn main(vec[str] args) { auto run_typestate = !opt_present(match, "no-typestate"); auto sysroot_opt = getopts::opt_maybe_str(match, "sysroot"); + let uint optLevel = 0u; + if (opt_present(match, "O")) { + optLevel = 2u; + if (opt_present(match, "OptLevel")) { + log + ("error: -O and --OptLevel both provided"); + fail; + } + } + + if (opt_present(match, "OptLevel")) { + auto opt = getopts::opt_maybe_str(match, "OptLevel"); + alt (opt) { + case (some[str](?s)) { + alt (s) { + case ("0") { optLevel = 0u; } + case ("1") { optLevel = 1u; } + case ("2") { optLevel = 2u; } + case ("3") { optLevel = 3u; } + case (_) { + log + ("error: optimization level needs to be between 0-3"); + fail; + } + } + } + case (none[str]) { + log("error: expected optimization level after --OptLevel="); + fail; + } + } + } + auto sysroot; alt (sysroot_opt) { case (none[str]) { sysroot = get_default_sysroot(binary); } @@ -293,7 +326,7 @@ fn main(vec[str] args) { let @session::options sopts = @rec(shared = shared, - optimize = optimize, + optimize = optLevel, debuginfo = debuginfo, verify = verify, run_typestate = run_typestate, diff --git a/src/comp/driver/session.rs b/src/comp/driver/session.rs index 88d0fcfb6c7..d943c151c6d 100644 --- a/src/comp/driver/session.rs +++ b/src/comp/driver/session.rs @@ -26,7 +26,7 @@ type config = rec(os os, ty_mach float_type); type options = rec(bool shared, - bool optimize, + uint optimize, bool debuginfo, bool verify, bool run_typestate, -- cgit 1.4.1-3-g733a5