rustc_codegen_ssa/traits/
write.rs1use std::any::Any;
2use std::path::PathBuf;
3
4use rustc_data_structures::profiling::SelfProfilerRef;
5use rustc_errors::DiagCtxtHandle;
6use rustc_middle::dep_graph::WorkProduct;
7use rustc_session::{Session, config};
8
9use crate::back::lto::ThinModule;
10use crate::back::write::{
11 CodegenContext, FatLtoInput, ModuleConfig, SharedEmitter, TargetMachineFactoryFn, ThinLtoInput,
12};
13use crate::{CompiledModule, ModuleCodegen};
14
15pub trait WriteBackendMethods: Clone + 'static {
16 type Module: Send + Sync;
17 type TargetMachine;
18 type ModuleBuffer: ModuleBufferMethods;
19 type ThinData: Send + Sync;
20
21 fn thread_profiler() -> Box<dyn Any> {
22 Box::new(())
23 }
24 fn target_machine_factory(
25 &self,
26 sess: &Session,
27 opt_level: config::OptLevel,
28 target_features: &[String],
29 ) -> TargetMachineFactoryFn<Self>;
30 fn optimize_and_codegen_fat_lto(
33 cgcx: &CodegenContext,
34 prof: &SelfProfilerRef,
35 shared_emitter: &SharedEmitter,
36 tm_factory: TargetMachineFactoryFn<Self>,
37 exported_symbols_for_lto: &[String],
38 each_linked_rlib_for_lto: &[PathBuf],
39 modules: Vec<FatLtoInput<Self>>,
40 ) -> CompiledModule;
41 fn run_thin_lto(
45 cgcx: &CodegenContext,
46 prof: &SelfProfilerRef,
47 dcx: DiagCtxtHandle<'_>,
48 exported_symbols_for_lto: &[String],
49 each_linked_rlib_for_lto: &[PathBuf],
50 modules: Vec<ThinLtoInput<Self>>,
51 ) -> (Vec<ThinModule<Self>>, Vec<WorkProduct>);
52 fn optimize(
53 cgcx: &CodegenContext,
54 prof: &SelfProfilerRef,
55 shared_emitter: &SharedEmitter,
56 module: &mut ModuleCodegen<Self::Module>,
57 config: &ModuleConfig,
58 );
59 fn optimize_and_codegen_thin(
60 cgcx: &CodegenContext,
61 prof: &SelfProfilerRef,
62 shared_emitter: &SharedEmitter,
63 tm_factory: TargetMachineFactoryFn<Self>,
64 thin: ThinModule<Self>,
65 ) -> CompiledModule;
66 fn codegen(
67 cgcx: &CodegenContext,
68 prof: &SelfProfilerRef,
69 shared_emitter: &SharedEmitter,
70 module: ModuleCodegen<Self::Module>,
71 config: &ModuleConfig,
72 ) -> CompiledModule;
73 fn serialize_module(module: Self::Module, is_thin: bool) -> Self::ModuleBuffer;
74}
75
76pub trait ModuleBufferMethods: Send + Sync {
77 fn data(&self) -> &[u8];
78}