Refactor TargetOptions::data_layout
into an Option
al value to reflect current usage.
NFC.
This commit is contained in:
parent
6f142404d6
commit
cdf6cebc00
@ -91,7 +91,7 @@ pub struct Target {
|
|||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct TargetOptions {
|
pub struct TargetOptions {
|
||||||
/// [Data layout](http://llvm.org/docs/LangRef.html#data-layout) to pass to LLVM.
|
/// [Data layout](http://llvm.org/docs/LangRef.html#data-layout) to pass to LLVM.
|
||||||
pub data_layout: String,
|
pub data_layout: Option<String>,
|
||||||
/// Linker to invoke. Defaults to "cc".
|
/// Linker to invoke. Defaults to "cc".
|
||||||
pub linker: String,
|
pub linker: String,
|
||||||
/// Archive utility to use when managing archives. Defaults to "ar".
|
/// 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.
|
/// incomplete, and if used for compilation, will certainly not work.
|
||||||
fn default() -> TargetOptions {
|
fn default() -> TargetOptions {
|
||||||
TargetOptions {
|
TargetOptions {
|
||||||
data_layout: String::new(),
|
data_layout: None,
|
||||||
linker: option_env!("CFG_DEFAULT_LINKER").unwrap_or("cc").to_string(),
|
linker: option_env!("CFG_DEFAULT_LINKER").unwrap_or("cc").to_string(),
|
||||||
ar: option_env!("CFG_DEFAULT_AR").unwrap_or("ar").to_string(),
|
ar: option_env!("CFG_DEFAULT_AR").unwrap_or("ar").to_string(),
|
||||||
pre_link_args: Vec::new(),
|
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);
|
key!(cpu);
|
||||||
@ -300,7 +308,7 @@ impl Target {
|
|||||||
key!(staticlib_prefix);
|
key!(staticlib_prefix);
|
||||||
key!(staticlib_suffix);
|
key!(staticlib_suffix);
|
||||||
key!(features);
|
key!(features);
|
||||||
key!(data_layout);
|
key!(data_layout, optional);
|
||||||
key!(dynamic_linking, bool);
|
key!(dynamic_linking, bool);
|
||||||
key!(executables, bool);
|
key!(executables, bool);
|
||||||
key!(disable_redzone, bool);
|
key!(disable_redzone, bool);
|
||||||
|
@ -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 mod_name = CString::new(mod_name).unwrap();
|
||||||
let llmod = llvm::LLVMModuleCreateWithNameInContext(mod_name.as_ptr(), llcx);
|
let llmod = llvm::LLVMModuleCreateWithNameInContext(mod_name.as_ptr(), llcx);
|
||||||
|
|
||||||
let custom_data_layout = &sess.target.target.options.data_layout[..];
|
if let Some(ref custom_data_layout) = sess.target.target.options.data_layout {
|
||||||
if custom_data_layout.len() > 0 {
|
let data_layout = CString::new(&custom_data_layout[..]).unwrap();
|
||||||
let data_layout = CString::new(custom_data_layout).unwrap();
|
|
||||||
llvm::LLVMSetDataLayout(llmod, data_layout.as_ptr());
|
llvm::LLVMSetDataLayout(llmod, data_layout.as_ptr());
|
||||||
} else {
|
} else {
|
||||||
let tm = ::back::write::create_target_machine(sess);
|
let tm = ::back::write::create_target_machine(sess);
|
||||||
|
Loading…
Reference in New Issue
Block a user