diff options
| author | khei4 <kk.asano.luxy@gmail.com> | 2023-07-17 00:37:52 +0900 |
|---|---|---|
| committer | khei4 <kk.asano.luxy@gmail.com> | 2023-07-17 00:37:52 +0900 |
| commit | 4d307c482271ea3575a13b6c04222911e7706189 (patch) | |
| tree | 32cf391f1ab50bf3d0a56199b8599064b232c325 /compiler/rustc_codegen_llvm/src | |
| parent | 138f522b590492d1ef80f1483382a2a678dec7d9 (diff) | |
| download | rust-4d307c482271ea3575a13b6c04222911e7706189.tar.gz rust-4d307c482271ea3575a13b6c04222911e7706189.zip | |
print on rustc_codegen_llvm and rename malloc and cpy c_char
Diffstat (limited to 'compiler/rustc_codegen_llvm/src')
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/lib.rs | 30 | ||||
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/llvm/ffi.rs | 4 |
2 files changed, 26 insertions, 8 deletions
diff --git a/compiler/rustc_codegen_llvm/src/lib.rs b/compiler/rustc_codegen_llvm/src/lib.rs index 713c22ebfeb..c03b2188824 100644 --- a/compiler/rustc_codegen_llvm/src/lib.rs +++ b/compiler/rustc_codegen_llvm/src/lib.rs @@ -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>, diff --git a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs index 3eb04555749..7cc79d859a3 100644 --- a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs +++ b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs @@ -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; |
