@@ -634,30 +634,24 @@ pub(crate) unsafe fn codegen(
634634 f ( cpm)
635635 }
636636
637- // If we don't have the integrated assembler, then we need to emit asm
638- // from LLVM and use `gcc` to create the object file.
639- let asm_to_obj = config. emit_obj && config. no_integrated_as ;
640-
641- // Change what we write and cleanup based on whether obj files are
642- // just llvm bitcode. In that case write bitcode, and possibly
643- // delete the bitcode if it wasn't requested. Don't generate the
644- // machine code, instead copy the .o file from the .bc
645- let write_bc = config. emit_bc || config. obj_is_bitcode ;
646- let rm_bc = !config. emit_bc && config. obj_is_bitcode ;
647- let write_obj = config. emit_obj && !config. obj_is_bitcode && !asm_to_obj;
648- let copy_bc_to_obj = config. emit_obj && config. obj_is_bitcode ;
637+ // Two things to note:
638+ // - If object files are just LLVM bitcode we write bitcode, copy it to
639+ // the .o file, and delete the bitcode if it wasn't otherwise
640+ // requested.
641+ // - If we don't have the integrated assembler then we need to emit
642+ // asm from LLVM and use `gcc` to create the object file.
649643
650644 let bc_out = cgcx. output_filenames . temp_path ( OutputType :: Bitcode , module_name) ;
651645 let obj_out = cgcx. output_filenames . temp_path ( OutputType :: Object , module_name) ;
652646
653- if write_bc || config. emit_bc_compressed || config . embed_bitcode {
647+ if config. bitcode_needed ( ) {
654648 let _timer = cgcx
655649 . prof
656650 . generic_activity_with_arg ( "LLVM_module_codegen_make_bitcode" , & module. name [ ..] ) ;
657651 let thin = ThinBuffer :: new ( llmod) ;
658652 let data = thin. data ( ) ;
659653
660- if write_bc {
654+ if config . emit_bc || config . obj_is_bitcode {
661655 let _timer = cgcx. prof . generic_activity_with_arg (
662656 "LLVM_module_codegen_emit_bitcode" ,
663657 & module. name [ ..] ,
@@ -740,7 +734,7 @@ pub(crate) unsafe fn codegen(
740734 } ) ?;
741735 }
742736
743- if config. emit_asm || asm_to_obj {
737+ if config. emit_asm || ( config . emit_obj && config . no_integrated_as ) {
744738 let _timer = cgcx
745739 . prof
746740 . generic_activity_with_arg ( "LLVM_module_codegen_emit_asm" , & module. name [ ..] ) ;
@@ -762,7 +756,7 @@ pub(crate) unsafe fn codegen(
762756 } ) ?;
763757 }
764758
765- if write_obj {
759+ if config . emit_obj && !config . obj_is_bitcode && !config . no_integrated_as {
766760 let _timer = cgcx
767761 . prof
768762 . generic_activity_with_arg ( "LLVM_module_codegen_emit_obj" , & module. name [ ..] ) ;
@@ -776,7 +770,7 @@ pub(crate) unsafe fn codegen(
776770 llvm:: FileType :: ObjectFile ,
777771 )
778772 } ) ?;
779- } else if asm_to_obj {
773+ } else if config . emit_obj && config . no_integrated_as {
780774 let _timer = cgcx
781775 . prof
782776 . generic_activity_with_arg ( "LLVM_module_codegen_asm_to_obj" , & module. name [ ..] ) ;
@@ -789,14 +783,14 @@ pub(crate) unsafe fn codegen(
789783 }
790784 }
791785
792- if copy_bc_to_obj {
786+ if config . emit_obj && config . obj_is_bitcode {
793787 debug ! ( "copying bitcode {:?} to obj {:?}" , bc_out, obj_out) ;
794788 if let Err ( e) = link_or_copy ( & bc_out, & obj_out) {
795789 diag_handler. err ( & format ! ( "failed to copy bitcode to object file: {}" , e) ) ;
796790 }
797791 }
798792
799- if rm_bc {
793+ if !config . emit_bc && config . obj_is_bitcode {
800794 debug ! ( "removing_bitcode {:?}" , bc_out) ;
801795 if let Err ( e) = fs:: remove_file ( & bc_out) {
802796 diag_handler. err ( & format ! ( "failed to remove bitcode: {}" , e) ) ;
0 commit comments