]> git.lizzy.rs Git - rust.git/commitdiff
Support for specifying the code model
authorJohn Kåre Alsaker <john.kare.alsaker@gmail.com>
Tue, 15 Jul 2014 23:14:02 +0000 (23:14 +0000)
committerJohn Kåre Alsaker <john.kare.alsaker@gmail.com>
Tue, 15 Jul 2014 23:21:22 +0000 (23:21 +0000)
The default code model is usually unsuitable for kernels,
so we add an option to specify which model we want.

src/librustc/back/link.rs
src/librustc/driver/config.rs

index cad164c9e2019d0c271c5c7c00b3b2988cedffaf..a7a959651653a0a6648e5a3ca3261b715bdac046 100644 (file)
@@ -186,6 +186,22 @@ pub fn run_passes(sess: &Session,
                 }
             };
 
+            let code_model = match sess.opts.cg.code_model.as_slice() {
+                "default" => llvm::CodeModelDefault,
+                "small" => llvm::CodeModelSmall,
+                "kernel" => llvm::CodeModelKernel,
+                "medium" => llvm::CodeModelMedium,
+                "large" => llvm::CodeModelLarge,
+                _ => {
+                    sess.err(format!("{} is not a valid code model",
+                                     sess.opts
+                                         .cg
+                                         .code_model).as_slice());
+                    sess.abort_if_errors();
+                    return;
+                }
+            };
+
             let tm = sess.targ_cfg
                          .target_strs
                          .target_triple
@@ -195,7 +211,7 @@ pub fn run_passes(sess: &Session,
                     target_feature(sess).with_c_str(|features| {
                         llvm::LLVMRustCreateTargetMachine(
                             t, cpu, features,
-                            llvm::CodeModelDefault,
+                            code_model,
                             reloc_model,
                             opt_level,
                             true /* EnableSegstk */,
index 345877d9ab6c47beea8f81694eeccb00af7c462b..ddb95f12f15acb9a8c8d338bcd122e29d10814ba 100644 (file)
@@ -334,6 +334,8 @@ fn parse_list(slot: &mut Vec<String>, v: Option<&str>)
         "use an external assembler rather than LLVM's integrated one"),
     relocation_model: String = ("pic".to_string(), parse_string,
          "choose the relocation model to use (llc -relocation-model for details)"),
+    code_model: String = ("default".to_string(), parse_string,
+         "choose the code model to use (llc -code-model for details)"),
     metadata: Vec<String> = (Vec::new(), parse_list,
          "metadata to mangle symbol names with"),
     extra_filename: String = ("".to_string(), parse_string,