From cdf6cebc0010653aa2fbf315f7f7660983d007da Mon Sep 17 00:00:00 2001 From: Richard Diamond Date: Mon, 7 Sep 2015 00:35:57 -0500 Subject: [PATCH] Refactor `TargetOptions::data_layout` into an `Option`al value to reflect current usage. NFC. --- src/librustc_back/target/mod.rs | 14 +++++++++++--- src/librustc_trans/trans/context.rs | 5 ++--- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/librustc_back/target/mod.rs b/src/librustc_back/target/mod.rs index 1f3b823d008..56562c8dfdb 100644 --- a/src/librustc_back/target/mod.rs +++ b/src/librustc_back/target/mod.rs @@ -91,7 +91,7 @@ pub struct Target { #[derive(Clone, Debug)] pub struct TargetOptions { /// [Data layout](http://llvm.org/docs/LangRef.html#data-layout) to pass to LLVM. - pub data_layout: String, + pub data_layout: Option, /// Linker to invoke. Defaults to "cc". pub linker: String, /// Archive utility to use when managing archives. Defaults to "ar". @@ -186,7 +186,7 @@ impl Default for TargetOptions { /// incomplete, and if used for compilation, will certainly not work. fn default() -> TargetOptions { TargetOptions { - data_layout: String::new(), + data_layout: None, linker: option_env!("CFG_DEFAULT_LINKER").unwrap_or("cc").to_string(), ar: option_env!("CFG_DEFAULT_AR").unwrap_or("ar").to_string(), pre_link_args: Vec::new(), @@ -287,6 +287,14 @@ impl Target { ) ); } ); + ($key_name:ident, optional) => ( { + let name = (stringify!($key_name)).replace("_", "-"); + if let Some(o) = obj.find(&name[..]) { + base.options.$key_name = o + .as_string() + .map(|s| s.to_string() ); + } + } ); } key!(cpu); @@ -300,7 +308,7 @@ impl Target { key!(staticlib_prefix); key!(staticlib_suffix); key!(features); - key!(data_layout); + key!(data_layout, optional); key!(dynamic_linking, bool); key!(executables, bool); key!(disable_redzone, bool); diff --git a/src/librustc_trans/trans/context.rs b/src/librustc_trans/trans/context.rs index fd8dbe83add..203614ee7bd 100644 --- a/src/librustc_trans/trans/context.rs +++ b/src/librustc_trans/trans/context.rs @@ -229,9 +229,8 @@ unsafe fn create_context_and_module(sess: &Session, mod_name: &str) -> (ContextR let mod_name = CString::new(mod_name).unwrap(); let llmod = llvm::LLVMModuleCreateWithNameInContext(mod_name.as_ptr(), llcx); - let custom_data_layout = &sess.target.target.options.data_layout[..]; - if custom_data_layout.len() > 0 { - let data_layout = CString::new(custom_data_layout).unwrap(); + if let Some(ref custom_data_layout) = sess.target.target.options.data_layout { + let data_layout = CString::new(&custom_data_layout[..]).unwrap(); llvm::LLVMSetDataLayout(llmod, data_layout.as_ptr()); } else { let tm = ::back::write::create_target_machine(sess);