Skip to content

Commit 5be8bf1

Browse files
committed
use -Z to distinguish internal debugging options
1 parent 0eef34b commit 5be8bf1

File tree

9 files changed

+98
-77
lines changed

9 files changed

+98
-77
lines changed

Makefile.in

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,11 @@ endif
9191
ifdef SAVE_TEMPS
9292
CFG_RUSTC_FLAGS += --save-temps
9393
endif
94-
ifdef ENFORCE_MUT_VARS
95-
CFG_RUSTC_FLAGS += --enforce-mut-vars
96-
endif
9794
ifdef TIME_PASSES
98-
CFG_RUSTC_FLAGS += --time-passes
95+
CFG_RUSTC_FLAGS += -Z time-passes
9996
endif
10097
ifdef TIME_LLVM_PASSES
101-
CFG_RUSTC_FLAGS += --time-llvm-passes
98+
CFG_RUSTC_FLAGS += -Z time-llvm-passes
10299
endif
103100

104101
# platform-specific auto-configuration

src/rustc/back/link.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ mod write {
5353

5454
fn run_passes(sess: session, llmod: ModuleRef, output: str) {
5555
let opts = sess.opts;
56-
if opts.time_llvm_passes { llvm::LLVMRustEnableTimePasses(); }
56+
if sess.time_llvm_passes() { llvm::LLVMRustEnableTimePasses(); }
5757
let mut pm = mk_pass_manager();
5858
let td = mk_target_data(
5959
sess.targ_cfg.target_strs.data_layout);
@@ -84,7 +84,7 @@ mod write {
8484
}
8585
}
8686
}
87-
if opts.verify { llvm::LLVMAddVerifierPass(pm.llpm); }
87+
if !sess.no_verify() { llvm::LLVMAddVerifierPass(pm.llpm); }
8888
// FIXME: This is mostly a copy of the bits of opt's -O2 that are
8989
// available in the C api.
9090
// FIXME2: We might want to add optimization levels like -O1, -O2,
@@ -125,7 +125,7 @@ mod write {
125125

126126
llvm::LLVMPassManagerBuilderDispose(MPMB);
127127
}
128-
if opts.verify { llvm::LLVMAddVerifierPass(pm.llpm); }
128+
if !sess.no_verify() { llvm::LLVMAddVerifierPass(pm.llpm); }
129129
if is_object_or_assembly_or_exe(opts.output_type) {
130130
let LLVMOptNone = 0 as c_int; // -O0
131131
let LLVMOptLess = 1 as c_int; // -O1
@@ -214,7 +214,7 @@ mod write {
214214
// Clean up and return
215215

216216
llvm::LLVMDisposeModule(llmod);
217-
if opts.time_llvm_passes { llvm::LLVMRustPrintPassTimings(); }
217+
if sess.time_llvm_passes() { llvm::LLVMRustPrintPassTimings(); }
218218
ret;
219219
}
220220

@@ -231,7 +231,7 @@ mod write {
231231
}
232232

233233
llvm::LLVMDisposeModule(llmod);
234-
if opts.time_llvm_passes { llvm::LLVMRustPrintPassTimings(); }
234+
if sess.time_llvm_passes() { llvm::LLVMRustPrintPassTimings(); }
235235
}
236236
}
237237

src/rustc/driver/driver.rs

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ fn compile_upto(sess: session, cfg: ast::crate_cfg,
129129
input: input, upto: compile_upto,
130130
outputs: option<output_filenames>)
131131
-> {crate: @ast::crate, tcx: option<ty::ctxt>} {
132-
let time_passes = sess.opts.time_passes;
132+
let time_passes = sess.time_passes();
133133
let mut crate = time(time_passes, "parsing",
134134
bind parse_input(sess, cfg, input));
135135
if upto == cu_parse { ret {crate: crate, tcx: none}; }
@@ -404,6 +404,21 @@ fn build_session_options(match: getopts::match,
404404
}
405405
};
406406

407+
let mut debugging_opts = 0u;
408+
let debug_flags = getopts::opt_strs(match, "Z");
409+
let debug_map = session::debugging_opts_map();
410+
for debug_flags.each { |debug_flag|
411+
let mut this_bit = 0u;
412+
for debug_map.each { |pair|
413+
let (name, _, bit) = pair;
414+
if name == debug_flag { this_bit = bit; break; }
415+
}
416+
if this_bit == 0u {
417+
early_error(demitter, #fmt("unknown debug flag: %s", debug_flag))
418+
}
419+
debugging_opts |= this_bit;
420+
}
421+
407422
let output_type =
408423
if parse_only || no_trans {
409424
link::output_type_none
@@ -416,18 +431,11 @@ fn build_session_options(match: getopts::match,
416431
} else if opt_present(match, "emit-llvm") {
417432
link::output_type_bitcode
418433
} else { link::output_type_exe };
419-
let verify = !opt_present(match, "no-verify");
420-
let save_temps = opt_present(match, "save-temps");
421434
let extra_debuginfo = opt_present(match, "xg");
422435
let debuginfo = opt_present(match, "g") || extra_debuginfo;
423-
let stats = opt_present(match, "stats");
424-
let time_passes = opt_present(match, "time-passes");
425-
let time_llvm_passes = opt_present(match, "time-llvm-passes");
426-
let count_llvm_insns = opt_present(match, "count-llvm-insns");
427436
let sysroot_opt = getopts::opt_maybe_str(match, "sysroot");
428437
let target_opt = getopts::opt_maybe_str(match, "target");
429-
let mut no_asm_comments = getopts::opt_present(match, "no-asm-comments");
430-
let debug_rustc = getopts::opt_present(match, "debug-rustc");
438+
let save_temps = getopts::opt_present(match, "save-temps");
431439
let borrowck = alt getopts::opt_maybe_str(match, "borrowck") {
432440
none { 0u }
433441
some("warn") { 1u }
@@ -439,7 +447,7 @@ fn build_session_options(match: getopts::match,
439447
alt output_type {
440448
// unless we're emitting huamn-readable assembly, omit comments.
441449
link::output_type_llvm_assembly | link::output_type_assembly {}
442-
_ { no_asm_comments = true; }
450+
_ { debugging_opts |= session::no_asm_comments; }
443451
}
444452
let opt_level: uint =
445453
if opt_present(match, "O") {
@@ -474,13 +482,8 @@ fn build_session_options(match: getopts::match,
474482
optimize: opt_level,
475483
debuginfo: debuginfo,
476484
extra_debuginfo: extra_debuginfo,
477-
verify: verify,
478485
lint_opts: lint_opts,
479486
save_temps: save_temps,
480-
stats: stats,
481-
time_passes: time_passes,
482-
count_llvm_insns: count_llvm_insns,
483-
time_llvm_passes: time_llvm_passes,
484487
output_type: output_type,
485488
addl_lib_search_paths: addl_lib_search_paths,
486489
maybe_sysroot: sysroot_opt,
@@ -489,8 +492,7 @@ fn build_session_options(match: getopts::match,
489492
test: test,
490493
parse_only: parse_only,
491494
no_trans: no_trans,
492-
no_asm_comments: no_asm_comments,
493-
debug_rustc: debug_rustc,
495+
debugging_opts: debugging_opts,
494496
borrowck: borrowck};
495497
ret sopts;
496498
}
@@ -559,17 +561,14 @@ fn opts() -> [getopts::opt] {
559561
optflag("O"), optopt("opt-level"), optmulti("L"), optflag("S"),
560562
optopt("o"), optopt("out-dir"), optflag("xg"),
561563
optflag("c"), optflag("g"), optflag("save-temps"),
562-
optopt("sysroot"), optopt("target"), optflag("stats"),
563-
optflag("time-passes"), optflag("time-llvm-passes"),
564-
optflag("count-llvm-insns"),
565-
optflag("no-verify"),
564+
optopt("sysroot"), optopt("target"),
566565

567566
optmulti("W"), optmulti("warn"),
568567

568+
optmulti("Z"),
569+
569570
optmulti("cfg"), optflag("test"),
570571
optflag("lib"), optflag("bin"), optflag("static"), optflag("gc"),
571-
optflag("no-asm-comments"),
572-
optflag("debug-rustc"),
573572
optopt("borrowck")];
574573
}
575574

src/rustc/driver/rustc.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import std::map::hashmap;
1414
import getopts::{opt_present};
1515
import rustc::driver::driver::*;
1616
import syntax::codemap;
17-
import rustc::driver::diagnostic;
17+
import rustc::driver::{diagnostic, session};
1818
import rustc::middle::lint;
1919
import io::reader_util;
2020

@@ -41,10 +41,7 @@ Options:
4141
-L <path> Add a directory to the library search path
4242
--lib Compile a library crate
4343
--ls List the symbols defined by a compiled library crate
44-
--no-asm-comments Do not add comments into the assembly source
4544
--no-trans Run all passes except translation; no output
46-
--no-verify Suppress LLVM verification step (slight speedup)
47-
(see http://llvm.org/docs/Passes.html for detail)
4845
-O Equivalent to --opt-level=2
4946
-o <filename> Write output to <filename>
5047
--opt-level <lvl> Optimize with possible levels 0-3
@@ -66,18 +63,13 @@ Options:
6663
(default: host triple)
6764
(see http://sources.redhat.com/autobook/autobook/
6865
autobook_17.html for detail)
69-
--debug-rustc enables different output that helps in debugging rustc,
70-
but may be less clear for normal use
7166
7267
-W <foo> enable warning <foo>
7368
-W no-<foo> disable warning <foo>
7469
-W err-<foo> enable warning <foo> as an error
75-
7670
-W help Print available warnings and default settings
7771
78-
--time-passes Time the individual phases of the compiler
79-
--time-llvm-passes Time the individual phases of the LLVM backend
80-
--count-llvm-insns Count and categorize generated LLVM instructions
72+
-Z help list internal options for debugging rustc
8173
8274
-v --version Print version info and exit
8375
");
@@ -107,6 +99,14 @@ fn describe_warnings() {
10799
io::println("");
108100
}
109101

102+
fn describe_debug_flags() {
103+
io::println(#fmt("\nAvailable debug options:\n"));
104+
for session::debugging_opts_map().each { |pair|
105+
let (name, desc, _) = pair;
106+
io::println(#fmt(" -Z%-20s -- %s", name, desc));
107+
}
108+
}
109+
110110
fn run_compiler(args: [str], demitter: diagnostic::emitter) {
111111
// Don't display log spew by default. Can override with RUST_LOG.
112112
logging::console_off();
@@ -136,6 +136,11 @@ fn run_compiler(args: [str], demitter: diagnostic::emitter) {
136136
ret;
137137
}
138138

139+
if getopts::opt_strs(match, "Z").contains("help") {
140+
describe_debug_flags();
141+
ret;
142+
}
143+
139144
if opt_present(match, "v") || opt_present(match, "version") {
140145
version(binary);
141146
ret;

src/rustc/driver/session.rs

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,26 @@ type config =
2323
uint_type: uint_ty,
2424
float_type: float_ty};
2525

26+
const ppregions: uint = 1u;
27+
const time_passes: uint = 2u;
28+
const count_llvm_insns: uint = 4u;
29+
const time_llvm_passes: uint = 8u;
30+
const stats: uint = 16u;
31+
const no_asm_comments: uint = 32u;
32+
const no_verify: uint = 64u;
33+
34+
fn debugging_opts_map() -> [(str, str, uint)] {
35+
[("ppregions", "prettyprint regions with \
36+
internal repr details", ppregions),
37+
("time-passes", "measure time of each rustc pass", time_passes),
38+
("count-llvm-insns", "count where LLVM \
39+
instrs originate", count_llvm_insns),
40+
("time-llvm-passes", "measure time of each LLVM pass", time_llvm_passes),
41+
("stats", "gather trans statistics", stats),
42+
("no-asm-comments", "omit comments when using -S", no_asm_comments),
43+
("no-verify", "skip LLVM verification", no_verify)]
44+
}
45+
2646
type options =
2747
// The crate config requested for the session, which may be combined
2848
// with additional crate configurations during the compile process
@@ -31,13 +51,8 @@ type options =
3151
optimize: uint,
3252
debuginfo: bool,
3353
extra_debuginfo: bool,
34-
verify: bool,
3554
lint_opts: [(lint::lint, lint::level)],
3655
save_temps: bool,
37-
stats: bool,
38-
time_passes: bool,
39-
count_llvm_insns: bool,
40-
time_llvm_passes: bool,
4156
output_type: back::link::output_type,
4257
addl_lib_search_paths: [str],
4358
maybe_sysroot: option<str>,
@@ -46,8 +61,8 @@ type options =
4661
test: bool,
4762
parse_only: bool,
4863
no_trans: bool,
49-
no_asm_comments: bool,
50-
debug_rustc: bool,
64+
65+
debugging_opts: uint,
5166

5267
// temporary hack: 0=off,1=warn,2=err --> if 2, alias is disabled
5368
borrowck: uint,
@@ -116,6 +131,16 @@ impl session for session {
116131
fn diagnostic() -> diagnostic::span_handler {
117132
self.span_diagnostic
118133
}
134+
fn debugging_opt(opt: uint) -> bool {
135+
(self.opts.debugging_opts & opt) != 0u
136+
}
137+
fn ppregions() -> bool { self.debugging_opt(ppregions) }
138+
fn time_passes() -> bool { self.debugging_opt(time_passes) }
139+
fn count_llvm_insns() -> bool { self.debugging_opt(count_llvm_insns) }
140+
fn time_llvm_passes() -> bool { self.debugging_opt(time_llvm_passes) }
141+
fn stats() -> bool { self.debugging_opt(stats) }
142+
fn no_asm_comments() -> bool { self.debugging_opt(no_asm_comments) }
143+
fn no_verify() -> bool { self.debugging_opt(no_verify) }
119144
}
120145

121146
#[doc = "Some reasonable defaults"]
@@ -126,13 +151,8 @@ fn basic_options() -> @options {
126151
optimize: 0u,
127152
debuginfo: false,
128153
extra_debuginfo: false,
129-
verify: false,
130154
lint_opts: [],
131155
save_temps: false,
132-
stats: false,
133-
time_passes: false,
134-
count_llvm_insns: false,
135-
time_llvm_passes: false,
136156
output_type: link::output_type_exe,
137157
addl_lib_search_paths: [],
138158
maybe_sysroot: none,
@@ -141,8 +161,7 @@ fn basic_options() -> @options {
141161
test: false,
142162
parse_only: false,
143163
no_trans: false,
144-
no_asm_comments: false,
145-
debug_rustc: false,
164+
debugging_opts: 0u,
146165
borrowck: 0u,
147166
}
148167
}

0 commit comments

Comments
 (0)