Convert a chained if-else to a match.

It makes things a little clearer.
This commit is contained in:
Nicholas Nethercote 2020-03-26 13:53:03 +11:00
parent 87ef16c9dc
commit a50cca920d

View file

@ -751,44 +751,53 @@ pub(crate) unsafe fn codegen(
})?; })?;
} }
if config_emit_object_code { match config.emit_obj {
if !config.no_integrated_as { EmitObj::ObjectCode(_) => {
let _timer = cgcx if !config.no_integrated_as {
.prof let _timer = cgcx.prof.generic_activity_with_arg(
.generic_activity_with_arg("LLVM_module_codegen_emit_obj", &module.name[..]); "LLVM_module_codegen_emit_obj",
with_codegen(tm, llmod, config.no_builtins, |cpm| { &module.name[..],
write_output_file( );
diag_handler, with_codegen(tm, llmod, config.no_builtins, |cpm| {
tm, write_output_file(
cpm, diag_handler,
llmod, tm,
&obj_out, cpm,
llvm::FileType::ObjectFile, llmod,
) &obj_out,
})?; llvm::FileType::ObjectFile,
} else { )
let _timer = cgcx })?;
.prof } else {
.generic_activity_with_arg("LLVM_module_codegen_asm_to_obj", &module.name[..]); let _timer = cgcx.prof.generic_activity_with_arg(
let assembly = cgcx.output_filenames.temp_path(OutputType::Assembly, module_name); "LLVM_module_codegen_asm_to_obj",
run_assembler(cgcx, diag_handler, &assembly, &obj_out); &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_asm && !cgcx.save_temps {
drop(fs::remove_file(&assembly)); drop(fs::remove_file(&assembly));
}
} }
} }
} else if config.emit_obj == EmitObj::Bitcode {
debug!("copying bitcode {:?} to obj {:?}", bc_out, obj_out);
if let Err(e) = link_or_copy(&bc_out, &obj_out) {
diag_handler.err(&format!("failed to copy bitcode to object file: {}", e));
}
if !config.emit_bc { EmitObj::Bitcode => {
debug!("removing_bitcode {:?}", bc_out); debug!("copying bitcode {:?} to obj {:?}", bc_out, obj_out);
if let Err(e) = fs::remove_file(&bc_out) { if let Err(e) = link_or_copy(&bc_out, &obj_out) {
diag_handler.err(&format!("failed to remove bitcode: {}", e)); diag_handler.err(&format!("failed to copy bitcode to object file: {}", e));
}
if !config.emit_bc {
debug!("removing_bitcode {:?}", bc_out);
if let Err(e) = fs::remove_file(&bc_out) {
diag_handler.err(&format!("failed to remove bitcode: {}", e));
}
} }
} }
EmitObj::None => {}
} }
drop(handlers); drop(handlers);