Skip to content

Commit 773f7e7

Browse files
committed
auto merge of #5996 : sanxiyn/rust/target-feature, r=graydon
Fix #1879.
2 parents 05f9586 + da4bc49 commit 773f7e7

File tree

5 files changed

+64
-59
lines changed

5 files changed

+64
-59
lines changed

src/librustc/back/link.rs

+49-57
Original file line numberDiff line numberDiff line change
@@ -61,23 +61,32 @@ pub fn llvm_err(sess: Session, msg: ~str) -> ! {
6161
6262
pub fn WriteOutputFile(sess: Session,
6363
PM: lib::llvm::PassManagerRef, M: ModuleRef,
64-
Triple: *c_char,
64+
Triple: &str,
65+
Feature: &str,
66+
Output: &str,
6567
// FIXME: When #2334 is fixed, change
6668
// c_uint to FileType
67-
Output: *c_char, FileType: c_uint,
69+
FileType: c_uint,
6870
OptLevel: c_int,
6971
EnableSegmentedStacks: bool) {
7072
unsafe {
71-
let result = llvm::LLVMRustWriteOutputFile(
72-
PM,
73-
M,
74-
Triple,
75-
Output,
76-
FileType,
77-
OptLevel,
78-
EnableSegmentedStacks);
79-
if (!result) {
80-
llvm_err(sess, ~"Could not write output");
73+
do str::as_c_str(Triple) |Triple| {
74+
do str::as_c_str(Feature) |Feature| {
75+
do str::as_c_str(Output) |Output| {
76+
let result = llvm::LLVMRustWriteOutputFile(
77+
PM,
78+
M,
79+
Triple,
80+
Feature,
81+
Output,
82+
FileType,
83+
OptLevel,
84+
EnableSegmentedStacks);
85+
if (!result) {
86+
llvm_err(sess, ~"Could not write output");
87+
}
88+
}
89+
}
8190
}
8291
}
8392
}
@@ -310,66 +319,49 @@ pub mod write {
310319
llvm::LLVMWriteBitcodeToFile(llmod, buf)
311320
});
312321
pm = mk_pass_manager();
313-
// Save the assembly file if -S is used
314322

323+
// Save the assembly file if -S is used
315324
if output_type == output_type_assembly {
316-
let _: () = str::as_c_str(
325+
WriteOutputFile(
326+
sess,
327+
pm.llpm,
328+
llmod,
317329
sess.targ_cfg.target_strs.target_triple,
318-
|buf_t| {
319-
str::as_c_str(output.to_str(), |buf_o| {
320-
WriteOutputFile(
321-
sess,
322-
pm.llpm,
323-
llmod,
324-
buf_t,
325-
buf_o,
326-
lib::llvm::AssemblyFile as c_uint,
327-
CodeGenOptLevel,
328-
true)
329-
})
330-
});
330+
opts.target_feature,
331+
output.to_str(),
332+
lib::llvm::AssemblyFile as c_uint,
333+
CodeGenOptLevel,
334+
true);
331335
}
332336

333-
334337
// Save the object file for -c or --save-temps alone
335338
// This .o is needed when an exe is built
336339
if output_type == output_type_object ||
337340
output_type == output_type_exe {
338-
let _: () = str::as_c_str(
341+
WriteOutputFile(
342+
sess,
343+
pm.llpm,
344+
llmod,
339345
sess.targ_cfg.target_strs.target_triple,
340-
|buf_t| {
341-
str::as_c_str(output.to_str(), |buf_o| {
342-
WriteOutputFile(
343-
sess,
344-
pm.llpm,
345-
llmod,
346-
buf_t,
347-
buf_o,
348-
lib::llvm::ObjectFile as c_uint,
349-
CodeGenOptLevel,
350-
true)
351-
})
352-
});
346+
opts.target_feature,
347+
output.to_str(),
348+
lib::llvm::ObjectFile as c_uint,
349+
CodeGenOptLevel,
350+
true);
353351
}
354352
} else {
355353
// If we aren't saving temps then just output the file
356354
// type corresponding to the '-c' or '-S' flag used
357-
358-
let _: () = str::as_c_str(
355+
WriteOutputFile(
356+
sess,
357+
pm.llpm,
358+
llmod,
359359
sess.targ_cfg.target_strs.target_triple,
360-
|buf_t| {
361-
str::as_c_str(output.to_str(), |buf_o| {
362-
WriteOutputFile(
363-
sess,
364-
pm.llpm,
365-
llmod,
366-
buf_t,
367-
buf_o,
368-
FileType as c_uint,
369-
CodeGenOptLevel,
370-
true)
371-
})
372-
});
360+
opts.target_feature,
361+
output.to_str(),
362+
FileType as c_uint,
363+
CodeGenOptLevel,
364+
true);
373365
}
374366
// Clean up and return
375367

src/librustc/driver/driver.rs

+9
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,7 @@ pub fn build_session_options(binary: @~str,
599599
let sysroot_opt = getopts::opt_maybe_str(matches, ~"sysroot");
600600
let sysroot_opt = sysroot_opt.map(|m| Path(*m));
601601
let target_opt = getopts::opt_maybe_str(matches, ~"target");
602+
let target_feature_opt = getopts::opt_maybe_str(matches, ~"target-feature");
602603
let save_temps = getopts::opt_present(matches, ~"save-temps");
603604
match output_type {
604605
// unless we're emitting huamn-readable assembly, omit comments.
@@ -637,6 +638,10 @@ pub fn build_session_options(binary: @~str,
637638
None => host_triple(),
638639
Some(s) => s
639640
};
641+
let target_feature = match target_feature_opt {
642+
None => ~"",
643+
Some(s) => s
644+
};
640645
641646
let addl_lib_search_paths =
642647
getopts::opt_strs(matches, ~"L")
@@ -659,6 +664,7 @@ pub fn build_session_options(binary: @~str,
659664
addl_lib_search_paths: addl_lib_search_paths,
660665
maybe_sysroot: sysroot_opt,
661666
target_triple: target,
667+
target_feature: target_feature,
662668
cfg: cfg,
663669
binary: binary,
664670
test: test,
@@ -769,6 +775,9 @@ pub fn optgroups() -> ~[getopts::groups::OptGroup] {
769775
~"Target triple cpu-manufacturer-kernel[-os]
770776
to compile for (see chapter 3.4 of http://www.sourceware.org/autobook/
771777
for detail)", ~"TRIPLE"),
778+
optopt(~"", ~"target-feature",
779+
~"Target specific attributes (llc -mattr=help
780+
for detail)", ~"FEATURE"),
772781
optopt(~"", ~"android-cross-path",
773782
~"The path to the Android NDK", "PATH"),
774783
optmulti(~"W", ~"warn",

src/librustc/driver/session.rs

+2
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ pub struct options {
126126
addl_lib_search_paths: ~[Path],
127127
maybe_sysroot: Option<Path>,
128128
target_triple: ~str,
129+
target_feature: ~str,
129130
// User-specified cfg meta items. The compiler itself will add additional
130131
// items to the crate config, and during parsing the entire crate config
131132
// will be added to the crate AST node. This should not be used for
@@ -302,6 +303,7 @@ pub fn basic_options() -> @options {
302303
addl_lib_search_paths: ~[],
303304
maybe_sysroot: None,
304305
target_triple: host_triple(),
306+
target_feature: ~"",
305307
cfg: ~[],
306308
binary: @~"rustc",
307309
test: false,

src/librustc/lib/llvm.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1799,9 +1799,10 @@ pub mod llvm {
17991799
pub unsafe fn LLVMRustWriteOutputFile(PM: PassManagerRef,
18001800
M: ModuleRef,
18011801
Triple: *c_char,
1802+
Feature: *c_char,
1803+
Output: *c_char,
18021804
// FIXME: When #2334 is fixed,
18031805
// change c_uint to FileType
1804-
Output: *c_char,
18051806
FileType: c_uint,
18061807
OptLevel: c_int,
18071808
EnableSegmentedStacks: bool)

src/rustllvm/RustWrapper.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,7 @@ extern "C" bool
434434
LLVMRustWriteOutputFile(LLVMPassManagerRef PMR,
435435
LLVMModuleRef M,
436436
const char *triple,
437+
const char *feature,
437438
const char *path,
438439
TargetMachine::CodeGenFileType FileType,
439440
CodeGenOpt::Level OptLevel,
@@ -461,7 +462,7 @@ LLVMRustWriteOutputFile(LLVMPassManagerRef PMR,
461462

462463
std::string Err;
463464
std::string Trip(Triple::normalize(triple));
464-
std::string FeaturesStr;
465+
std::string FeaturesStr(feature);
465466
std::string CPUStr("generic");
466467
const Target *TheTarget = TargetRegistry::lookupTarget(Trip, Err);
467468
TargetMachine *Target =

0 commit comments

Comments
 (0)