Skip to content

Commit 6aee1e2

Browse files
committed
Tidy ups for code gen options help
Remove duplication code gen options and updated help to reflect changes.
1 parent 87ed467 commit 6aee1e2

File tree

3 files changed

+38
-28
lines changed

3 files changed

+38
-28
lines changed

src/librustc/session/config.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -604,9 +604,9 @@ options! {CodegenOptions, CodegenSetter, basic_codegen_options,
604604
lto: bool = (false, parse_bool,
605605
"perform LLVM link-time optimizations"),
606606
target_cpu: Option<String> = (None, parse_opt_string,
607-
"select target processor (llc -mcpu=help for details)"),
607+
"select target processor (rustc --print target-cpus for details)"),
608608
target_feature: String = ("".to_string(), parse_string,
609-
"target specific attributes (llc -mattr=help for details)"),
609+
"target specific attributes (rustc --print target-features for details)"),
610610
passes: Vec<String> = (Vec::new(), parse_list,
611611
"a list of extra LLVM passes to run (space separated)"),
612612
llvm_args: Vec<String> = (Vec::new(), parse_list,
@@ -630,9 +630,9 @@ options! {CodegenOptions, CodegenSetter, basic_codegen_options,
630630
no_redzone: Option<bool> = (None, parse_opt_bool,
631631
"disable the use of the redzone"),
632632
relocation_model: Option<String> = (None, parse_opt_string,
633-
"choose the relocation model to use (llc -relocation-model for details)"),
633+
"choose the relocation model to use (rustc --print relocation-models for details)"),
634634
code_model: Option<String> = (None, parse_opt_string,
635-
"choose the code model to use (llc -code-model for details)"),
635+
"choose the code model to use (rustc --print code-models for details)"),
636636
metadata: Vec<String> = (Vec::new(), parse_list,
637637
"metadata to mangle symbol names with"),
638638
extra_filename: String = ("".to_string(), parse_string,
@@ -993,7 +993,8 @@ pub fn rustc_short_optgroups() -> Vec<RustcOptGroup> {
993993
"[asm|llvm-bc|llvm-ir|obj|link|dep-info]"),
994994
opt::multi_s("", "print", "Comma separated list of compiler information to \
995995
print on stdout",
996-
"[crate-name|file-names|sysroot|cfg|target-list]"),
996+
"[crate-name|file-names|sysroot|cfg|target-list|target-cpus|\
997+
target-features|relocation-models|code-models]"),
997998
opt::flagmulti_s("g", "", "Equivalent to -C debuginfo=2"),
998999
opt::flagmulti_s("O", "", "Equivalent to -C opt-level=2"),
9991000
opt::opt_s("o", "", "Write output to <filename>", "FILENAME"),

src/librustc_driver/lib.rs

+11-12
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ use pretty::{PpMode, UserIdentifiedItem};
6969
use rustc_resolve as resolve;
7070
use rustc_save_analysis as save;
7171
use rustc_trans::back::link;
72-
use rustc_trans::back::write::create_target_machine;
72+
use rustc_trans::back::write::{create_target_machine, RELOC_MODEL_ARGS, CODE_GEN_MODEL_ARGS};
7373
use rustc::dep_graph::DepGraph;
7474
use rustc::session::{self, config, Session, build_session, CompileResult};
7575
use rustc::session::config::{Input, PrintRequest, OutputType, ErrorOutputType};
@@ -676,19 +676,18 @@ impl RustcDefaultCalls {
676676
unsafe { llvm::LLVMRustPrintTargetFeatures(tm); }
677677
}
678678
PrintRequest::RelocationModels => {
679-
println!("Available relocation models:\n");
680-
println!(" pic");
681-
println!(" static");
682-
println!(" default");
683-
println!(" dynamic-no-pic\n");
679+
println!("Available relocation models:");
680+
for &(name, _) in RELOC_MODEL_ARGS.iter() {
681+
println!(" {}", name);
682+
}
683+
println!("");
684684
}
685685
PrintRequest::CodeModels => {
686-
println!("Available code models:\n");
687-
println!(" default");
688-
println!(" small");
689-
println!(" kernel");
690-
println!(" medium");
691-
println!(" large\n");
686+
println!("Available code models:");
687+
for &(name, _) in CODE_GEN_MODEL_ARGS.iter(){
688+
println!(" {}", name);
689+
}
690+
println!("");
692691
}
693692
}
694693
}

src/librustc_trans/back/write.rs

+21-11
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,21 @@ use std::sync::mpsc::channel;
3333
use std::thread;
3434
use libc::{c_uint, c_void};
3535

36+
pub const RELOC_MODEL_ARGS : [(&'static str, llvm::RelocMode); 4] = [
37+
("pic", llvm::RelocPIC),
38+
("static", llvm::RelocStatic),
39+
("default", llvm::RelocDefault),
40+
("dynamic-no-pic", llvm::RelocDynamicNoPic),
41+
];
42+
43+
pub const CODE_GEN_MODEL_ARGS : [(&'static str, llvm::CodeGenModel); 5] = [
44+
("default", llvm::CodeModelDefault),
45+
("small", llvm::CodeModelSmall),
46+
("kernel", llvm::CodeModelKernel),
47+
("medium", llvm::CodeModelMedium),
48+
("large", llvm::CodeModelLarge),
49+
];
50+
3651
pub fn llvm_err(handler: &errors::Handler, msg: String) -> ! {
3752
match llvm::last_error() {
3853
Some(err) => panic!(handler.fatal(&format!("{}: {}", msg, err))),
@@ -156,11 +171,9 @@ pub fn create_target_machine(sess: &Session) -> TargetMachineRef {
156171
Some(ref s) => &s[..],
157172
None => &sess.target.target.options.relocation_model[..],
158173
};
159-
let reloc_model = match reloc_model_arg {
160-
"pic" => llvm::RelocPIC,
161-
"static" => llvm::RelocStatic,
162-
"default" => llvm::RelocDefault,
163-
"dynamic-no-pic" => llvm::RelocDynamicNoPic,
174+
let reloc_model = match RELOC_MODEL_ARGS.iter().find(
175+
|&&arg| arg.0 == reloc_model_arg) {
176+
Some(x) => x.1,
164177
_ => {
165178
sess.err(&format!("{:?} is not a valid relocation mode",
166179
sess.opts
@@ -186,12 +199,9 @@ pub fn create_target_machine(sess: &Session) -> TargetMachineRef {
186199
None => &sess.target.target.options.code_model[..],
187200
};
188201

189-
let code_model = match code_model_arg {
190-
"default" => llvm::CodeModelDefault,
191-
"small" => llvm::CodeModelSmall,
192-
"kernel" => llvm::CodeModelKernel,
193-
"medium" => llvm::CodeModelMedium,
194-
"large" => llvm::CodeModelLarge,
202+
let code_model = match CODE_GEN_MODEL_ARGS.iter().find(
203+
|&&arg| arg.0 == code_model_arg) {
204+
Some(x) => x.1,
195205
_ => {
196206
sess.err(&format!("{:?} is not a valid code model",
197207
sess.opts

0 commit comments

Comments
 (0)