From 6aee1e2a67d0608257a1087477e11e5b37e48d87 Mon Sep 17 00:00:00 2001 From: Cameron Hart Date: Sun, 24 Jul 2016 17:27:23 +1000 Subject: [PATCH] Tidy ups for code gen options help Remove duplication code gen options and updated help to reflect changes. --- src/librustc/session/config.rs | 11 ++++++----- src/librustc_driver/lib.rs | 23 +++++++++++------------ src/librustc_trans/back/write.rs | 32 +++++++++++++++++++++----------- 3 files changed, 38 insertions(+), 28 deletions(-) diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index 2e511e345084..ed14c1e64172 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -604,9 +604,9 @@ options! {CodegenOptions, CodegenSetter, basic_codegen_options, lto: bool = (false, parse_bool, "perform LLVM link-time optimizations"), target_cpu: Option = (None, parse_opt_string, - "select target processor (llc -mcpu=help for details)"), + "select target processor (rustc --print target-cpus for details)"), target_feature: String = ("".to_string(), parse_string, - "target specific attributes (llc -mattr=help for details)"), + "target specific attributes (rustc --print target-features for details)"), passes: Vec = (Vec::new(), parse_list, "a list of extra LLVM passes to run (space separated)"), llvm_args: Vec = (Vec::new(), parse_list, @@ -630,9 +630,9 @@ options! {CodegenOptions, CodegenSetter, basic_codegen_options, no_redzone: Option = (None, parse_opt_bool, "disable the use of the redzone"), relocation_model: Option = (None, parse_opt_string, - "choose the relocation model to use (llc -relocation-model for details)"), + "choose the relocation model to use (rustc --print relocation-models for details)"), code_model: Option = (None, parse_opt_string, - "choose the code model to use (llc -code-model for details)"), + "choose the code model to use (rustc --print code-models for details)"), metadata: Vec = (Vec::new(), parse_list, "metadata to mangle symbol names with"), extra_filename: String = ("".to_string(), parse_string, @@ -993,7 +993,8 @@ pub fn rustc_short_optgroups() -> Vec { "[asm|llvm-bc|llvm-ir|obj|link|dep-info]"), opt::multi_s("", "print", "Comma separated list of compiler information to \ print on stdout", - "[crate-name|file-names|sysroot|cfg|target-list]"), + "[crate-name|file-names|sysroot|cfg|target-list|target-cpus|\ + target-features|relocation-models|code-models]"), opt::flagmulti_s("g", "", "Equivalent to -C debuginfo=2"), opt::flagmulti_s("O", "", "Equivalent to -C opt-level=2"), opt::opt_s("o", "", "Write output to ", "FILENAME"), diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index e539a732b116..f50ea9af493e 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -69,7 +69,7 @@ use pretty::{PpMode, UserIdentifiedItem}; use rustc_resolve as resolve; use rustc_save_analysis as save; use rustc_trans::back::link; -use rustc_trans::back::write::create_target_machine; +use rustc_trans::back::write::{create_target_machine, RELOC_MODEL_ARGS, CODE_GEN_MODEL_ARGS}; use rustc::dep_graph::DepGraph; use rustc::session::{self, config, Session, build_session, CompileResult}; use rustc::session::config::{Input, PrintRequest, OutputType, ErrorOutputType}; @@ -676,19 +676,18 @@ impl RustcDefaultCalls { unsafe { llvm::LLVMRustPrintTargetFeatures(tm); } } PrintRequest::RelocationModels => { - println!("Available relocation models:\n"); - println!(" pic"); - println!(" static"); - println!(" default"); - println!(" dynamic-no-pic\n"); + println!("Available relocation models:"); + for &(name, _) in RELOC_MODEL_ARGS.iter() { + println!(" {}", name); + } + println!(""); } PrintRequest::CodeModels => { - println!("Available code models:\n"); - println!(" default"); - println!(" small"); - println!(" kernel"); - println!(" medium"); - println!(" large\n"); + println!("Available code models:"); + for &(name, _) in CODE_GEN_MODEL_ARGS.iter(){ + println!(" {}", name); + } + println!(""); } } } diff --git a/src/librustc_trans/back/write.rs b/src/librustc_trans/back/write.rs index 33cffa8a4801..422e3d436b42 100644 --- a/src/librustc_trans/back/write.rs +++ b/src/librustc_trans/back/write.rs @@ -33,6 +33,21 @@ use std::sync::mpsc::channel; use std::thread; use libc::{c_uint, c_void}; +pub const RELOC_MODEL_ARGS : [(&'static str, llvm::RelocMode); 4] = [ + ("pic", llvm::RelocPIC), + ("static", llvm::RelocStatic), + ("default", llvm::RelocDefault), + ("dynamic-no-pic", llvm::RelocDynamicNoPic), +]; + +pub const CODE_GEN_MODEL_ARGS : [(&'static str, llvm::CodeGenModel); 5] = [ + ("default", llvm::CodeModelDefault), + ("small", llvm::CodeModelSmall), + ("kernel", llvm::CodeModelKernel), + ("medium", llvm::CodeModelMedium), + ("large", llvm::CodeModelLarge), +]; + pub fn llvm_err(handler: &errors::Handler, msg: String) -> ! { match llvm::last_error() { Some(err) => panic!(handler.fatal(&format!("{}: {}", msg, err))), @@ -156,11 +171,9 @@ pub fn create_target_machine(sess: &Session) -> TargetMachineRef { Some(ref s) => &s[..], None => &sess.target.target.options.relocation_model[..], }; - let reloc_model = match reloc_model_arg { - "pic" => llvm::RelocPIC, - "static" => llvm::RelocStatic, - "default" => llvm::RelocDefault, - "dynamic-no-pic" => llvm::RelocDynamicNoPic, + let reloc_model = match RELOC_MODEL_ARGS.iter().find( + |&&arg| arg.0 == reloc_model_arg) { + Some(x) => x.1, _ => { sess.err(&format!("{:?} is not a valid relocation mode", sess.opts @@ -186,12 +199,9 @@ pub fn create_target_machine(sess: &Session) -> TargetMachineRef { None => &sess.target.target.options.code_model[..], }; - let code_model = match code_model_arg { - "default" => llvm::CodeModelDefault, - "small" => llvm::CodeModelSmall, - "kernel" => llvm::CodeModelKernel, - "medium" => llvm::CodeModelMedium, - "large" => llvm::CodeModelLarge, + let code_model = match CODE_GEN_MODEL_ARGS.iter().find( + |&&arg| arg.0 == code_model_arg) { + Some(x) => x.1, _ => { sess.err(&format!("{:?} is not a valid code model", sess.opts