1 use super::write::WriteBackendMethods;
2 use super::CodegenObject;
3 use crate::ModuleCodegen;
5 use rustc::middle::cstore::EncodedMetadata;
6 use rustc::session::{config, Session};
7 use rustc::ty::layout::{HasTyCtxt, LayoutOf, TyLayout};
10 use rustc_codegen_utils::codegen_backend::CodegenBackend;
11 use rustc_span::symbol::Symbol;
12 use syntax::expand::allocator::AllocatorKind;
16 pub trait BackendTypes {
17 type Value: CodegenObject;
18 type Function: CodegenObject;
20 type BasicBlock: Copy;
21 type Type: CodegenObject;
24 // FIXME(eddyb) find a common convention for all of the debuginfo-related
25 // names (choose between `Dbg`, `Debug`, `DebugInfo`, `DI` etc.).
27 type DIVariable: Copy;
30 pub trait Backend<'tcx>:
31 Sized + BackendTypes + HasTyCtxt<'tcx> + LayoutOf<Ty = Ty<'tcx>, TyLayout = TyLayout<'tcx>>
35 impl<'tcx, T> Backend<'tcx> for T where
36 Self: BackendTypes + HasTyCtxt<'tcx> + LayoutOf<Ty = Ty<'tcx>, TyLayout = TyLayout<'tcx>>
40 pub trait ExtraBackendMethods: CodegenBackend + WriteBackendMethods + Sized + Send + Sync {
41 fn new_metadata(&self, sess: TyCtxt<'_>, mod_name: &str) -> Self::Module;
42 fn write_compressed_metadata<'tcx>(
45 metadata: &EncodedMetadata,
46 llvm_module: &mut Self::Module,
48 fn codegen_allocator<'tcx>(
51 mods: &mut Self::Module,
54 /// This generates the codegen unit and returns it along with
55 /// a `u64` giving an estimate of the unit's processing cost.
56 fn compile_codegen_unit(
60 ) -> (ModuleCodegen<Self::Module>, u64);
61 // If find_features is true this won't access `sess.crate_types` by assuming
62 // that `is_pie_binary` is false. When we discover LLVM target features
63 // `sess.crate_types` is uninitialized so we cannot access it.
64 fn target_machine_factory(
67 opt_level: config::OptLevel,
69 ) -> Arc<dyn Fn() -> Result<Self::TargetMachine, String> + Send + Sync>;
70 fn target_cpu<'b>(&self, sess: &'b Session) -> &'b str;