3 use gccjit::OutputKind;
4 use rustc_codegen_ssa::{CompiledModule, ModuleCodegen};
5 use rustc_codegen_ssa::back::write::{CodegenContext, EmitObj, ModuleConfig};
6 use rustc_errors::Handler;
7 use rustc_session::config::OutputType;
8 use rustc_span::fatal_error::FatalError;
9 use rustc_target::spec::SplitDebuginfo;
11 use crate::{GccCodegenBackend, GccContext};
13 pub(crate) unsafe fn codegen(cgcx: &CodegenContext<GccCodegenBackend>, _diag_handler: &Handler, module: ModuleCodegen<GccContext>, config: &ModuleConfig) -> Result<CompiledModule, FatalError> {
14 let _timer = cgcx.prof.generic_activity_with_arg("LLVM_module_codegen", &module.name[..]);
16 let context = &module.module_llvm.context;
18 let module_name = module.name.clone();
19 let module_name = Some(&module_name[..]);
21 let _bc_out = cgcx.output_filenames.temp_path(OutputType::Bitcode, module_name);
22 let obj_out = cgcx.output_filenames.temp_path(OutputType::Object, module_name);
24 if config.bitcode_needed() {
35 .generic_activity_with_arg("LLVM_module_codegen_emit_asm", &module.name[..]);
36 let path = cgcx.output_filenames.temp_path(OutputType::Assembly, module_name);
37 context.compile_to_file(OutputKind::Assembler, path.to_str().expect("path to str"));
40 match config.emit_obj {
41 EmitObj::ObjectCode(_) => {
44 .generic_activity_with_arg("LLVM_module_codegen_emit_obj", &module.name[..]);
46 "std_example.7rcbfp3g-cgu.15" => {
47 println!("Dumping reproducer {}", module.name);
48 let _ = fs::create_dir("/tmp/reproducers");
49 // FIXME(antoyo): segfault in dump_reproducer_to_file() might be caused by
50 // transmuting an rvalue to an lvalue.
51 // Segfault is actually in gcc::jit::reproducer::get_identifier_as_lvalue
52 context.dump_reproducer_to_file(&format!("/tmp/reproducers/{}.c", module.name));
53 println!("Dumped reproducer {}", module.name);
57 context.compile_to_file(OutputKind::ObjectFile, obj_out.to_str().expect("path to str"));
68 Ok(module.into_compiled_module(
69 config.emit_obj != EmitObj::None,
70 cgcx.target_can_use_split_dwarf && cgcx.split_debuginfo == SplitDebuginfo::Unpacked,
72 &cgcx.output_filenames,
76 pub(crate) fn link(_cgcx: &CodegenContext<GccCodegenBackend>, _diag_handler: &Handler, mut _modules: Vec<ModuleCodegen<GccContext>>) -> Result<ModuleCodegen<GccContext>, FatalError> {