about summary refs log tree commit diff
diff options
context:
space:
mode:
authorCameron Hart <cameron.hart@gmail.com>2016-07-24 17:27:23 +1000
committerCameron Hart <cameron.hart@gmail.com>2016-07-24 18:44:08 +1000
commit6aee1e2a67d0608257a1087477e11e5b37e48d87 (patch)
tree94b944f87805bec6304ec60cccccf2a90611205e
parent87ed467077703ccada419c8b4cf183eed60467c7 (diff)
Tidy ups for code gen options help
Remove duplication code gen options and updated help to reflect
changes.
-rw-r--r--src/librustc/session/config.rs11
-rw-r--r--src/librustc_driver/lib.rs23
-rw-r--r--src/librustc_trans/back/write.rs32
3 files changed, 38 insertions, 28 deletions
diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs
index 2e511e34508..ed14c1e6417 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<String> = (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<String> = (Vec::new(), parse_list,
         "a list of extra LLVM passes to run (space separated)"),
     llvm_args: Vec<String> = (Vec::new(), parse_list,
@@ -630,9 +630,9 @@ options! {CodegenOptions, CodegenSetter, basic_codegen_options,
     no_redzone: Option<bool> = (None, parse_opt_bool,
         "disable the use of the redzone"),
     relocation_model: Option<String> = (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<String> = (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<String> = (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<RustcOptGroup> {
                  "[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>", "FILENAME"),
diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs
index e539a732b11..f50ea9af493 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 33cffa8a480..422e3d436b4 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