@@ -634,30 +634,24 @@ pub(crate) unsafe fn codegen(
634
634
f ( cpm)
635
635
}
636
636
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.
649
643
650
644
let bc_out = cgcx. output_filenames . temp_path ( OutputType :: Bitcode , module_name) ;
651
645
let obj_out = cgcx. output_filenames . temp_path ( OutputType :: Object , module_name) ;
652
646
653
- if write_bc || config. emit_bc_compressed || config . embed_bitcode {
647
+ if config. bitcode_needed ( ) {
654
648
let _timer = cgcx
655
649
. prof
656
650
. generic_activity_with_arg ( "LLVM_module_codegen_make_bitcode" , & module. name [ ..] ) ;
657
651
let thin = ThinBuffer :: new ( llmod) ;
658
652
let data = thin. data ( ) ;
659
653
660
- if write_bc {
654
+ if config . emit_bc || config . obj_is_bitcode {
661
655
let _timer = cgcx. prof . generic_activity_with_arg (
662
656
"LLVM_module_codegen_emit_bitcode" ,
663
657
& module. name [ ..] ,
@@ -740,7 +734,7 @@ pub(crate) unsafe fn codegen(
740
734
} ) ?;
741
735
}
742
736
743
- if config. emit_asm || asm_to_obj {
737
+ if config. emit_asm || ( config . emit_obj && config . no_integrated_as ) {
744
738
let _timer = cgcx
745
739
. prof
746
740
. generic_activity_with_arg ( "LLVM_module_codegen_emit_asm" , & module. name [ ..] ) ;
@@ -762,7 +756,7 @@ pub(crate) unsafe fn codegen(
762
756
} ) ?;
763
757
}
764
758
765
- if write_obj {
759
+ if config . emit_obj && !config . obj_is_bitcode && !config . no_integrated_as {
766
760
let _timer = cgcx
767
761
. prof
768
762
. generic_activity_with_arg ( "LLVM_module_codegen_emit_obj" , & module. name [ ..] ) ;
@@ -776,7 +770,7 @@ pub(crate) unsafe fn codegen(
776
770
llvm:: FileType :: ObjectFile ,
777
771
)
778
772
} ) ?;
779
- } else if asm_to_obj {
773
+ } else if config . emit_obj && config . no_integrated_as {
780
774
let _timer = cgcx
781
775
. prof
782
776
. generic_activity_with_arg ( "LLVM_module_codegen_asm_to_obj" , & module. name [ ..] ) ;
@@ -789,14 +783,14 @@ pub(crate) unsafe fn codegen(
789
783
}
790
784
}
791
785
792
- if copy_bc_to_obj {
786
+ if config . emit_obj && config . obj_is_bitcode {
793
787
debug ! ( "copying bitcode {:?} to obj {:?}" , bc_out, obj_out) ;
794
788
if let Err ( e) = link_or_copy ( & bc_out, & obj_out) {
795
789
diag_handler. err ( & format ! ( "failed to copy bitcode to object file: {}" , e) ) ;
796
790
}
797
791
}
798
792
799
- if rm_bc {
793
+ if !config . emit_bc && config . obj_is_bitcode {
800
794
debug ! ( "removing_bitcode {:?}" , bc_out) ;
801
795
if let Err ( e) = fs:: remove_file ( & bc_out) {
802
796
diag_handler. err ( & format ! ( "failed to remove bitcode: {}" , e) ) ;
0 commit comments