print on rustc_codegen_llvm and rename malloc and cpy c_char

This commit is contained in:
khei4 2023-07-17 00:37:52 +09:00
parent 138f522b59
commit 4d307c4822
6 changed files with 47 additions and 19 deletions

View file

@ -177,14 +177,32 @@ impl WriteBackendMethods for LlvmCodegenBackend {
type ThinData = back::lto::ThinData;
type ThinBuffer = back::lto::ThinBuffer;
fn print_pass_timings(&self) {
unsafe {
llvm::LLVMRustPrintPassTimings();
}
let msg = unsafe {
let cstr = llvm::LLVMRustPrintPassTimings();
if cstr.is_null() {
"failed to get pass timings".into()
} else {
let timings = CStr::from_ptr(cstr).to_bytes();
let timings = String::from_utf8_lossy(timings).to_string();
libc::free(cstr as *mut _);
timings
}
};
println!("{}", msg);
}
fn print_statistics(&self) {
unsafe {
llvm::LLVMRustPrintStatistics();
}
let msg = unsafe {
let cstr = llvm::LLVMRustPrintStatistics();
if cstr.is_null() {
"failed to get stats".into()
} else {
let stats = CStr::from_ptr(cstr).to_bytes();
let stats = String::from_utf8_lossy(stats).to_string();
libc::free(cstr as *mut _);
stats
}
};
println!("{}", msg);
}
fn run_link(
cgcx: &CodegenContext<Self>,

View file

@ -1868,10 +1868,10 @@ extern "C" {
pub fn LLVMRustGetLastError() -> *const c_char;
/// Print the pass timings since static dtors aren't picking them up.
pub fn LLVMRustPrintPassTimings();
pub fn LLVMRustPrintPassTimings() -> *const c_char;
/// Print the statistics since static dtors aren't picking them up.
pub fn LLVMRustPrintStatistics();
pub fn LLVMRustPrintStatistics() -> *const c_char;
pub fn LLVMStructCreateNamed(C: &Context, Name: *const c_char) -> &Type;