about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNicholas Nethercote <nnethercote@mozilla.com>2020-03-26 13:53:03 +1100
committerNicholas Nethercote <nnethercote@mozilla.com>2020-03-26 13:53:03 +1100
commita50cca920d06b831ce0a54e958d1e4e4dfcc350b (patch)
tree71963dd9cd706a8e57e70d8ed3fde48532b56e32
parent87ef16c9dc7b4ebb46c1db3363e1a00586a819d8 (diff)
downloadrust-a50cca920d06b831ce0a54e958d1e4e4dfcc350b.tar.gz
rust-a50cca920d06b831ce0a54e958d1e4e4dfcc350b.zip
Convert a chained if-else to a match.
It makes things a little clearer.
-rw-r--r--src/librustc_codegen_llvm/back/write.rs75
1 files changed, 42 insertions, 33 deletions
diff --git a/src/librustc_codegen_llvm/back/write.rs b/src/librustc_codegen_llvm/back/write.rs
index a864d81f2da..1557630fc7a 100644
--- a/src/librustc_codegen_llvm/back/write.rs
+++ b/src/librustc_codegen_llvm/back/write.rs
@@ -751,44 +751,53 @@ pub(crate) unsafe fn codegen(
             })?;
         }
 
-        if config_emit_object_code {
-            if !config.no_integrated_as {
-                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 {
-                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));
+        match config.emit_obj {
+            EmitObj::ObjectCode(_) => {
+                if !config.no_integrated_as {
+                    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 {
+                    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));
+                    }
                 }
             }
-        } 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 {
-                debug!("removing_bitcode {:?}", bc_out);
-                if let Err(e) = fs::remove_file(&bc_out) {
-                    diag_handler.err(&format!("failed to remove bitcode: {}", e));
+            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 {
+                    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);