]> git.lizzy.rs Git - rust.git/blob - src/librustc_codegen_ssa/traits/backend.rs
typeck: remove redundant diverges code
[rust.git] / src / librustc_codegen_ssa / traits / backend.rs
1 use super::write::WriteBackendMethods;
2 use super::CodegenObject;
3 use crate::ModuleCodegen;
4
5 use rustc::middle::cstore::EncodedMetadata;
6 use rustc::session::{config, Session};
7 use rustc::ty::layout::{HasTyCtxt, LayoutOf, TyLayout};
8 use rustc::ty::Ty;
9 use rustc::ty::TyCtxt;
10 use rustc_codegen_utils::codegen_backend::CodegenBackend;
11 use rustc_span::symbol::Symbol;
12 use syntax::expand::allocator::AllocatorKind;
13
14 use std::sync::Arc;
15
16 pub trait BackendTypes {
17     type Value: CodegenObject;
18     type Function: CodegenObject;
19
20     type BasicBlock: Copy;
21     type Type: CodegenObject;
22     type Funclet;
23
24     type DIScope: Copy;
25 }
26
27 pub trait Backend<'tcx>:
28     Sized + BackendTypes + HasTyCtxt<'tcx> + LayoutOf<Ty = Ty<'tcx>, TyLayout = TyLayout<'tcx>>
29 {
30 }
31
32 impl<'tcx, T> Backend<'tcx> for T where
33     Self: BackendTypes + HasTyCtxt<'tcx> + LayoutOf<Ty = Ty<'tcx>, TyLayout = TyLayout<'tcx>>
34 {
35 }
36
37 pub trait ExtraBackendMethods: CodegenBackend + WriteBackendMethods + Sized + Send + Sync {
38     fn new_metadata(&self, sess: TyCtxt<'_>, mod_name: &str) -> Self::Module;
39     fn write_compressed_metadata<'tcx>(
40         &self,
41         tcx: TyCtxt<'tcx>,
42         metadata: &EncodedMetadata,
43         llvm_module: &mut Self::Module,
44     );
45     fn codegen_allocator<'tcx>(
46         &self,
47         tcx: TyCtxt<'tcx>,
48         mods: &mut Self::Module,
49         kind: AllocatorKind,
50     );
51     /// This generates the codegen unit and returns it along with
52     /// a `u64` giving an estimate of the unit's processing cost.
53     fn compile_codegen_unit(
54         &self,
55         tcx: TyCtxt<'_>,
56         cgu_name: Symbol,
57     ) -> (ModuleCodegen<Self::Module>, u64);
58     // If find_features is true this won't access `sess.crate_types` by assuming
59     // that `is_pie_binary` is false. When we discover LLVM target features
60     // `sess.crate_types` is uninitialized so we cannot access it.
61     fn target_machine_factory(
62         &self,
63         sess: &Session,
64         opt_level: config::OptLevel,
65         find_features: bool,
66     ) -> Arc<dyn Fn() -> Result<Self::TargetMachine, String> + Send + Sync>;
67     fn target_cpu<'b>(&self, sess: &'b Session) -> &'b str;
68 }