auto merge of #5996 : sanxiyn/rust/target-feature, r=graydon
Fix #1879.
This commit is contained in:
commit
773f7e7560
5 changed files with 64 additions and 59 deletions
|
@ -61,23 +61,32 @@ pub fn llvm_err(sess: Session, msg: ~str) -> ! {
|
||||||
|
|
||||||
pub fn WriteOutputFile(sess: Session,
|
pub fn WriteOutputFile(sess: Session,
|
||||||
PM: lib::llvm::PassManagerRef, M: ModuleRef,
|
PM: lib::llvm::PassManagerRef, M: ModuleRef,
|
||||||
Triple: *c_char,
|
Triple: &str,
|
||||||
|
Feature: &str,
|
||||||
|
Output: &str,
|
||||||
// FIXME: When #2334 is fixed, change
|
// FIXME: When #2334 is fixed, change
|
||||||
// c_uint to FileType
|
// c_uint to FileType
|
||||||
Output: *c_char, FileType: c_uint,
|
FileType: c_uint,
|
||||||
OptLevel: c_int,
|
OptLevel: c_int,
|
||||||
EnableSegmentedStacks: bool) {
|
EnableSegmentedStacks: bool) {
|
||||||
unsafe {
|
unsafe {
|
||||||
let result = llvm::LLVMRustWriteOutputFile(
|
do str::as_c_str(Triple) |Triple| {
|
||||||
PM,
|
do str::as_c_str(Feature) |Feature| {
|
||||||
M,
|
do str::as_c_str(Output) |Output| {
|
||||||
Triple,
|
let result = llvm::LLVMRustWriteOutputFile(
|
||||||
Output,
|
PM,
|
||||||
FileType,
|
M,
|
||||||
OptLevel,
|
Triple,
|
||||||
EnableSegmentedStacks);
|
Feature,
|
||||||
if (!result) {
|
Output,
|
||||||
llvm_err(sess, ~"Could not write output");
|
FileType,
|
||||||
|
OptLevel,
|
||||||
|
EnableSegmentedStacks);
|
||||||
|
if (!result) {
|
||||||
|
llvm_err(sess, ~"Could not write output");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -310,66 +319,49 @@ pub mod write {
|
||||||
llvm::LLVMWriteBitcodeToFile(llmod, buf)
|
llvm::LLVMWriteBitcodeToFile(llmod, buf)
|
||||||
});
|
});
|
||||||
pm = mk_pass_manager();
|
pm = mk_pass_manager();
|
||||||
|
|
||||||
// Save the assembly file if -S is used
|
// Save the assembly file if -S is used
|
||||||
|
|
||||||
if output_type == output_type_assembly {
|
if output_type == output_type_assembly {
|
||||||
let _: () = str::as_c_str(
|
WriteOutputFile(
|
||||||
|
sess,
|
||||||
|
pm.llpm,
|
||||||
|
llmod,
|
||||||
sess.targ_cfg.target_strs.target_triple,
|
sess.targ_cfg.target_strs.target_triple,
|
||||||
|buf_t| {
|
opts.target_feature,
|
||||||
str::as_c_str(output.to_str(), |buf_o| {
|
output.to_str(),
|
||||||
WriteOutputFile(
|
lib::llvm::AssemblyFile as c_uint,
|
||||||
sess,
|
CodeGenOptLevel,
|
||||||
pm.llpm,
|
true);
|
||||||
llmod,
|
|
||||||
buf_t,
|
|
||||||
buf_o,
|
|
||||||
lib::llvm::AssemblyFile as c_uint,
|
|
||||||
CodeGenOptLevel,
|
|
||||||
true)
|
|
||||||
})
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Save the object file for -c or --save-temps alone
|
// Save the object file for -c or --save-temps alone
|
||||||
// This .o is needed when an exe is built
|
// This .o is needed when an exe is built
|
||||||
if output_type == output_type_object ||
|
if output_type == output_type_object ||
|
||||||
output_type == output_type_exe {
|
output_type == output_type_exe {
|
||||||
let _: () = str::as_c_str(
|
WriteOutputFile(
|
||||||
|
sess,
|
||||||
|
pm.llpm,
|
||||||
|
llmod,
|
||||||
sess.targ_cfg.target_strs.target_triple,
|
sess.targ_cfg.target_strs.target_triple,
|
||||||
|buf_t| {
|
opts.target_feature,
|
||||||
str::as_c_str(output.to_str(), |buf_o| {
|
output.to_str(),
|
||||||
WriteOutputFile(
|
lib::llvm::ObjectFile as c_uint,
|
||||||
sess,
|
CodeGenOptLevel,
|
||||||
pm.llpm,
|
true);
|
||||||
llmod,
|
|
||||||
buf_t,
|
|
||||||
buf_o,
|
|
||||||
lib::llvm::ObjectFile as c_uint,
|
|
||||||
CodeGenOptLevel,
|
|
||||||
true)
|
|
||||||
})
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// If we aren't saving temps then just output the file
|
// If we aren't saving temps then just output the file
|
||||||
// type corresponding to the '-c' or '-S' flag used
|
// type corresponding to the '-c' or '-S' flag used
|
||||||
|
WriteOutputFile(
|
||||||
let _: () = str::as_c_str(
|
sess,
|
||||||
|
pm.llpm,
|
||||||
|
llmod,
|
||||||
sess.targ_cfg.target_strs.target_triple,
|
sess.targ_cfg.target_strs.target_triple,
|
||||||
|buf_t| {
|
opts.target_feature,
|
||||||
str::as_c_str(output.to_str(), |buf_o| {
|
output.to_str(),
|
||||||
WriteOutputFile(
|
FileType as c_uint,
|
||||||
sess,
|
CodeGenOptLevel,
|
||||||
pm.llpm,
|
true);
|
||||||
llmod,
|
|
||||||
buf_t,
|
|
||||||
buf_o,
|
|
||||||
FileType as c_uint,
|
|
||||||
CodeGenOptLevel,
|
|
||||||
true)
|
|
||||||
})
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
// Clean up and return
|
// Clean up and return
|
||||||
|
|
||||||
|
|
|
@ -599,6 +599,7 @@ pub fn build_session_options(binary: @~str,
|
||||||
let sysroot_opt = getopts::opt_maybe_str(matches, ~"sysroot");
|
let sysroot_opt = getopts::opt_maybe_str(matches, ~"sysroot");
|
||||||
let sysroot_opt = sysroot_opt.map(|m| Path(*m));
|
let sysroot_opt = sysroot_opt.map(|m| Path(*m));
|
||||||
let target_opt = getopts::opt_maybe_str(matches, ~"target");
|
let target_opt = getopts::opt_maybe_str(matches, ~"target");
|
||||||
|
let target_feature_opt = getopts::opt_maybe_str(matches, ~"target-feature");
|
||||||
let save_temps = getopts::opt_present(matches, ~"save-temps");
|
let save_temps = getopts::opt_present(matches, ~"save-temps");
|
||||||
match output_type {
|
match output_type {
|
||||||
// unless we're emitting huamn-readable assembly, omit comments.
|
// unless we're emitting huamn-readable assembly, omit comments.
|
||||||
|
@ -637,6 +638,10 @@ pub fn build_session_options(binary: @~str,
|
||||||
None => host_triple(),
|
None => host_triple(),
|
||||||
Some(s) => s
|
Some(s) => s
|
||||||
};
|
};
|
||||||
|
let target_feature = match target_feature_opt {
|
||||||
|
None => ~"",
|
||||||
|
Some(s) => s
|
||||||
|
};
|
||||||
|
|
||||||
let addl_lib_search_paths =
|
let addl_lib_search_paths =
|
||||||
getopts::opt_strs(matches, ~"L")
|
getopts::opt_strs(matches, ~"L")
|
||||||
|
@ -659,6 +664,7 @@ pub fn build_session_options(binary: @~str,
|
||||||
addl_lib_search_paths: addl_lib_search_paths,
|
addl_lib_search_paths: addl_lib_search_paths,
|
||||||
maybe_sysroot: sysroot_opt,
|
maybe_sysroot: sysroot_opt,
|
||||||
target_triple: target,
|
target_triple: target,
|
||||||
|
target_feature: target_feature,
|
||||||
cfg: cfg,
|
cfg: cfg,
|
||||||
binary: binary,
|
binary: binary,
|
||||||
test: test,
|
test: test,
|
||||||
|
@ -769,6 +775,9 @@ pub fn optgroups() -> ~[getopts::groups::OptGroup] {
|
||||||
~"Target triple cpu-manufacturer-kernel[-os]
|
~"Target triple cpu-manufacturer-kernel[-os]
|
||||||
to compile for (see chapter 3.4 of http://www.sourceware.org/autobook/
|
to compile for (see chapter 3.4 of http://www.sourceware.org/autobook/
|
||||||
for detail)", ~"TRIPLE"),
|
for detail)", ~"TRIPLE"),
|
||||||
|
optopt(~"", ~"target-feature",
|
||||||
|
~"Target specific attributes (llc -mattr=help
|
||||||
|
for detail)", ~"FEATURE"),
|
||||||
optopt(~"", ~"android-cross-path",
|
optopt(~"", ~"android-cross-path",
|
||||||
~"The path to the Android NDK", "PATH"),
|
~"The path to the Android NDK", "PATH"),
|
||||||
optmulti(~"W", ~"warn",
|
optmulti(~"W", ~"warn",
|
||||||
|
|
|
@ -126,6 +126,7 @@ pub struct options {
|
||||||
addl_lib_search_paths: ~[Path],
|
addl_lib_search_paths: ~[Path],
|
||||||
maybe_sysroot: Option<Path>,
|
maybe_sysroot: Option<Path>,
|
||||||
target_triple: ~str,
|
target_triple: ~str,
|
||||||
|
target_feature: ~str,
|
||||||
// User-specified cfg meta items. The compiler itself will add additional
|
// User-specified cfg meta items. The compiler itself will add additional
|
||||||
// items to the crate config, and during parsing the entire crate config
|
// items to the crate config, and during parsing the entire crate config
|
||||||
// will be added to the crate AST node. This should not be used for
|
// will be added to the crate AST node. This should not be used for
|
||||||
|
@ -302,6 +303,7 @@ pub fn basic_options() -> @options {
|
||||||
addl_lib_search_paths: ~[],
|
addl_lib_search_paths: ~[],
|
||||||
maybe_sysroot: None,
|
maybe_sysroot: None,
|
||||||
target_triple: host_triple(),
|
target_triple: host_triple(),
|
||||||
|
target_feature: ~"",
|
||||||
cfg: ~[],
|
cfg: ~[],
|
||||||
binary: @~"rustc",
|
binary: @~"rustc",
|
||||||
test: false,
|
test: false,
|
||||||
|
|
|
@ -1799,9 +1799,10 @@ pub mod llvm {
|
||||||
pub unsafe fn LLVMRustWriteOutputFile(PM: PassManagerRef,
|
pub unsafe fn LLVMRustWriteOutputFile(PM: PassManagerRef,
|
||||||
M: ModuleRef,
|
M: ModuleRef,
|
||||||
Triple: *c_char,
|
Triple: *c_char,
|
||||||
|
Feature: *c_char,
|
||||||
|
Output: *c_char,
|
||||||
// FIXME: When #2334 is fixed,
|
// FIXME: When #2334 is fixed,
|
||||||
// change c_uint to FileType
|
// change c_uint to FileType
|
||||||
Output: *c_char,
|
|
||||||
FileType: c_uint,
|
FileType: c_uint,
|
||||||
OptLevel: c_int,
|
OptLevel: c_int,
|
||||||
EnableSegmentedStacks: bool)
|
EnableSegmentedStacks: bool)
|
||||||
|
|
|
@ -434,6 +434,7 @@ extern "C" bool
|
||||||
LLVMRustWriteOutputFile(LLVMPassManagerRef PMR,
|
LLVMRustWriteOutputFile(LLVMPassManagerRef PMR,
|
||||||
LLVMModuleRef M,
|
LLVMModuleRef M,
|
||||||
const char *triple,
|
const char *triple,
|
||||||
|
const char *feature,
|
||||||
const char *path,
|
const char *path,
|
||||||
TargetMachine::CodeGenFileType FileType,
|
TargetMachine::CodeGenFileType FileType,
|
||||||
CodeGenOpt::Level OptLevel,
|
CodeGenOpt::Level OptLevel,
|
||||||
|
@ -461,7 +462,7 @@ LLVMRustWriteOutputFile(LLVMPassManagerRef PMR,
|
||||||
|
|
||||||
std::string Err;
|
std::string Err;
|
||||||
std::string Trip(Triple::normalize(triple));
|
std::string Trip(Triple::normalize(triple));
|
||||||
std::string FeaturesStr;
|
std::string FeaturesStr(feature);
|
||||||
std::string CPUStr("generic");
|
std::string CPUStr("generic");
|
||||||
const Target *TheTarget = TargetRegistry::lookupTarget(Trip, Err);
|
const Target *TheTarget = TargetRegistry::lookupTarget(Trip, Err);
|
||||||
TargetMachine *Target =
|
TargetMachine *Target =
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue