Remove an unnecessary block scope.
This commit is contained in:
parent
47c8f3f56b
commit
e4b36baf54
1 changed files with 72 additions and 82 deletions
|
@ -686,100 +686,90 @@ pub(crate) unsafe fn codegen(
|
||||||
embed_bitcode(cgcx, llcx, llmod, None);
|
embed_bitcode(cgcx, llcx, llmod, None);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
if config.emit_ir {
|
||||||
if config.emit_ir {
|
let _timer = cgcx
|
||||||
let _timer = cgcx
|
.prof
|
||||||
.prof
|
.generic_activity_with_arg("LLVM_module_codegen_emit_ir", &module.name[..]);
|
||||||
.generic_activity_with_arg("LLVM_module_codegen_emit_ir", &module.name[..]);
|
let out = cgcx.output_filenames.temp_path(OutputType::LlvmAssembly, module_name);
|
||||||
let out = cgcx.output_filenames.temp_path(OutputType::LlvmAssembly, module_name);
|
let out_c = path_to_c_string(&out);
|
||||||
let out_c = path_to_c_string(&out);
|
|
||||||
|
|
||||||
extern "C" fn demangle_callback(
|
extern "C" fn demangle_callback(
|
||||||
input_ptr: *const c_char,
|
input_ptr: *const c_char,
|
||||||
input_len: size_t,
|
input_len: size_t,
|
||||||
output_ptr: *mut c_char,
|
output_ptr: *mut c_char,
|
||||||
output_len: size_t,
|
output_len: size_t,
|
||||||
) -> size_t {
|
) -> size_t {
|
||||||
let input = unsafe {
|
let input =
|
||||||
slice::from_raw_parts(input_ptr as *const u8, input_len as usize)
|
unsafe { slice::from_raw_parts(input_ptr as *const u8, input_len as usize) };
|
||||||
};
|
|
||||||
|
|
||||||
let input = match str::from_utf8(input) {
|
let input = match str::from_utf8(input) {
|
||||||
Ok(s) => s,
|
Ok(s) => s,
|
||||||
Err(_) => return 0,
|
Err(_) => return 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
let output = unsafe {
|
let output = unsafe {
|
||||||
slice::from_raw_parts_mut(output_ptr as *mut u8, output_len as usize)
|
slice::from_raw_parts_mut(output_ptr as *mut u8, output_len as usize)
|
||||||
};
|
};
|
||||||
let mut cursor = io::Cursor::new(output);
|
let mut cursor = io::Cursor::new(output);
|
||||||
|
|
||||||
let demangled = match rustc_demangle::try_demangle(input) {
|
let demangled = match rustc_demangle::try_demangle(input) {
|
||||||
Ok(d) => d,
|
Ok(d) => d,
|
||||||
Err(_) => return 0,
|
Err(_) => return 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
if write!(cursor, "{:#}", demangled).is_err() {
|
if write!(cursor, "{:#}", demangled).is_err() {
|
||||||
// Possible only if provided buffer is not big enough
|
// Possible only if provided buffer is not big enough
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
cursor.position() as size_t
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let result = llvm::LLVMRustPrintModule(llmod, out_c.as_ptr(), demangle_callback);
|
cursor.position() as size_t
|
||||||
result.into_result().map_err(|()| {
|
|
||||||
let msg = format!("failed to write LLVM IR to {}", out.display());
|
|
||||||
llvm_err(diag_handler, &msg)
|
|
||||||
})?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.emit_asm || (config.emit_obj && config.no_integrated_as) {
|
let result = llvm::LLVMRustPrintModule(llmod, out_c.as_ptr(), demangle_callback);
|
||||||
let _timer = cgcx
|
result.into_result().map_err(|()| {
|
||||||
.prof
|
let msg = format!("failed to write LLVM IR to {}", out.display());
|
||||||
.generic_activity_with_arg("LLVM_module_codegen_emit_asm", &module.name[..]);
|
llvm_err(diag_handler, &msg)
|
||||||
let path = cgcx.output_filenames.temp_path(OutputType::Assembly, module_name);
|
})?;
|
||||||
|
}
|
||||||
|
|
||||||
// We can't use the same module for asm and binary output, because that triggers
|
if config.emit_asm || (config.emit_obj && config.no_integrated_as) {
|
||||||
// various errors like invalid IR or broken binaries, so we might have to clone the
|
let _timer = cgcx
|
||||||
// module to produce the asm output
|
.prof
|
||||||
let llmod = if config.emit_obj { llvm::LLVMCloneModule(llmod) } else { llmod };
|
.generic_activity_with_arg("LLVM_module_codegen_emit_asm", &module.name[..]);
|
||||||
with_codegen(tm, llmod, config.no_builtins, |cpm| {
|
let path = cgcx.output_filenames.temp_path(OutputType::Assembly, module_name);
|
||||||
write_output_file(
|
|
||||||
diag_handler,
|
|
||||||
tm,
|
|
||||||
cpm,
|
|
||||||
llmod,
|
|
||||||
&path,
|
|
||||||
llvm::FileType::AssemblyFile,
|
|
||||||
)
|
|
||||||
})?;
|
|
||||||
}
|
|
||||||
|
|
||||||
if config.emit_obj && !config.obj_is_bitcode && !config.no_integrated_as {
|
// We can't use the same module for asm and binary output, because that triggers
|
||||||
let _timer = cgcx
|
// various errors like invalid IR or broken binaries, so we might have to clone the
|
||||||
.prof
|
// module to produce the asm output
|
||||||
.generic_activity_with_arg("LLVM_module_codegen_emit_obj", &module.name[..]);
|
let llmod = if config.emit_obj { llvm::LLVMCloneModule(llmod) } else { llmod };
|
||||||
with_codegen(tm, llmod, config.no_builtins, |cpm| {
|
with_codegen(tm, llmod, config.no_builtins, |cpm| {
|
||||||
write_output_file(
|
write_output_file(diag_handler, tm, cpm, llmod, &path, llvm::FileType::AssemblyFile)
|
||||||
diag_handler,
|
})?;
|
||||||
tm,
|
}
|
||||||
cpm,
|
|
||||||
llmod,
|
|
||||||
&obj_out,
|
|
||||||
llvm::FileType::ObjectFile,
|
|
||||||
)
|
|
||||||
})?;
|
|
||||||
} else if config.emit_obj && config.no_integrated_as {
|
|
||||||
let _timer = cgcx
|
|
||||||
.prof
|
|
||||||
.generic_activity_with_arg("LLVM_module_codegen_asm_to_obj", &module.name[..]);
|
|
||||||
let assembly = cgcx.output_filenames.temp_path(OutputType::Assembly, module_name);
|
|
||||||
run_assembler(cgcx, diag_handler, &assembly, &obj_out);
|
|
||||||
|
|
||||||
if !config.emit_asm && !cgcx.save_temps {
|
if config.emit_obj && !config.obj_is_bitcode && !config.no_integrated_as {
|
||||||
drop(fs::remove_file(&assembly));
|
let _timer = cgcx
|
||||||
}
|
.prof
|
||||||
|
.generic_activity_with_arg("LLVM_module_codegen_emit_obj", &module.name[..]);
|
||||||
|
with_codegen(tm, llmod, config.no_builtins, |cpm| {
|
||||||
|
write_output_file(
|
||||||
|
diag_handler,
|
||||||
|
tm,
|
||||||
|
cpm,
|
||||||
|
llmod,
|
||||||
|
&obj_out,
|
||||||
|
llvm::FileType::ObjectFile,
|
||||||
|
)
|
||||||
|
})?;
|
||||||
|
} else if config.emit_obj && config.no_integrated_as {
|
||||||
|
let _timer = cgcx
|
||||||
|
.prof
|
||||||
|
.generic_activity_with_arg("LLVM_module_codegen_asm_to_obj", &module.name[..]);
|
||||||
|
let assembly = cgcx.output_filenames.temp_path(OutputType::Assembly, module_name);
|
||||||
|
run_assembler(cgcx, diag_handler, &assembly, &obj_out);
|
||||||
|
|
||||||
|
if !config.emit_asm && !cgcx.save_temps {
|
||||||
|
drop(fs::remove_file(&assembly));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue