Skip to content

Commit 299d8b9

Browse files
committed
Implement printing to file in llvm_util
1 parent 294a4f5 commit 299d8b9

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

compiler/rustc_codegen_llvm/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ impl CodegenBackend for LlvmCodegenBackend {
320320
"#
321321
);
322322
}
323-
req => llvm_util::print(req, sess),
323+
req => llvm_util::print(req, out, sess),
324324
}
325325
}
326326

compiler/rustc_codegen_llvm/src/llvm_util.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use libc::c_int;
88
use rustc_codegen_ssa::target_features::{
99
supported_target_features, tied_target_features, RUSTC_SPECIFIC_FEATURES,
1010
};
11+
use rustc_codegen_ssa::traits::PrintBackendInfo;
1112
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1213
use rustc_data_structures::small_c_str::SmallCStr;
1314
use rustc_fs_util::path_to_c_string;
@@ -350,7 +351,7 @@ fn llvm_target_features(tm: &llvm::TargetMachine) -> Vec<(&str, &str)> {
350351
ret
351352
}
352353

353-
fn print_target_features(sess: &Session, tm: &llvm::TargetMachine) {
354+
fn print_target_features(out: &mut dyn PrintBackendInfo, sess: &Session, tm: &llvm::TargetMachine) {
354355
let mut llvm_target_features = llvm_target_features(tm);
355356
let mut known_llvm_target_features = FxHashSet::<&'static str>::default();
356357
let mut rustc_target_features = supported_target_features(sess)
@@ -383,24 +384,24 @@ fn print_target_features(sess: &Session, tm: &llvm::TargetMachine) {
383384
.max()
384385
.unwrap_or(0);
385386

386-
println!("Features supported by rustc for this target:");
387+
writeln!(out, "Features supported by rustc for this target:");
387388
for (feature, desc) in &rustc_target_features {
388-
println!(" {1:0$} - {2}.", max_feature_len, feature, desc);
389+
writeln!(out, " {1:0$} - {2}.", max_feature_len, feature, desc);
389390
}
390-
println!("\nCode-generation features supported by LLVM for this target:");
391+
writeln!(out, "\nCode-generation features supported by LLVM for this target:");
391392
for (feature, desc) in &llvm_target_features {
392-
println!(" {1:0$} - {2}.", max_feature_len, feature, desc);
393+
writeln!(out, " {1:0$} - {2}.", max_feature_len, feature, desc);
393394
}
394395
if llvm_target_features.is_empty() {
395-
println!(" Target features listing is not supported by this LLVM version.");
396+
writeln!(out, " Target features listing is not supported by this LLVM version.");
396397
}
397-
println!("\nUse +feature to enable a feature, or -feature to disable it.");
398-
println!("For example, rustc -C target-cpu=mycpu -C target-feature=+feature1,-feature2\n");
399-
println!("Code-generation features cannot be used in cfg or #[target_feature],");
400-
println!("and may be renamed or removed in a future version of LLVM or rustc.\n");
398+
writeln!(out, "\nUse +feature to enable a feature, or -feature to disable it.");
399+
writeln!(out, "For example, rustc -C target-cpu=mycpu -C target-feature=+feature1,-feature2\n");
400+
writeln!(out, "Code-generation features cannot be used in cfg or #[target_feature],");
401+
writeln!(out, "and may be renamed or removed in a future version of LLVM or rustc.\n");
401402
}
402403

403-
pub(crate) fn print(req: PrintRequest, sess: &Session) {
404+
pub(crate) fn print(req: PrintRequest, out: &mut dyn PrintBackendInfo, sess: &Session) {
404405
require_inited();
405406
let tm = create_informational_target_machine(sess);
406407
match req {
@@ -412,7 +413,7 @@ pub(crate) fn print(req: PrintRequest, sess: &Session) {
412413
.unwrap_or_else(|e| bug!("failed to convert to cstring: {}", e));
413414
unsafe { llvm::LLVMRustPrintTargetCPUs(tm, cpu_cstring.as_ptr()) };
414415
}
415-
PrintRequest::TargetFeatures => print_target_features(sess, tm),
416+
PrintRequest::TargetFeatures => print_target_features(out, sess, tm),
416417
_ => bug!("rustc_codegen_llvm can't handle print request: {:?}", req),
417418
}
418419
}

0 commit comments

Comments
 (0)