]>
Commit | Line | Data |
---|---|---|
a1dfa0c6 XL |
1 | use super::write::WriteBackendMethods; |
2 | use super::CodegenObject; | |
dfeec247 | 3 | use crate::ModuleCodegen; |
60c5eb7d | 4 | |
74b04a01 | 5 | use rustc_ast::expand::allocator::AllocatorKind; |
ba9703b0 XL |
6 | use rustc_errors::ErrorReported; |
7 | use rustc_middle::dep_graph::DepGraph; | |
8 | use rustc_middle::middle::cstore::{EncodedMetadata, MetadataLoaderDyn}; | |
9 | use rustc_middle::ty::layout::{HasTyCtxt, TyAndLayout}; | |
10 | use rustc_middle::ty::query::Providers; | |
11 | use rustc_middle::ty::{Ty, TyCtxt}; | |
12 | use rustc_session::{ | |
13 | config::{self, OutputFilenames, PrintRequest}, | |
14 | Session, | |
15 | }; | |
dfeec247 | 16 | use rustc_span::symbol::Symbol; |
ba9703b0 | 17 | use rustc_target::abi::LayoutOf; |
a1dfa0c6 | 18 | |
ba9703b0 XL |
19 | pub use rustc_data_structures::sync::MetadataRef; |
20 | ||
21 | use std::any::Any; | |
60c5eb7d | 22 | use std::sync::Arc; |
60c5eb7d | 23 | |
a1dfa0c6 XL |
24 | pub trait BackendTypes { |
25 | type Value: CodegenObject; | |
e74abb32 XL |
26 | type Function: CodegenObject; |
27 | ||
a1dfa0c6 XL |
28 | type BasicBlock: Copy; |
29 | type Type: CodegenObject; | |
30 | type Funclet; | |
31 | ||
74b04a01 XL |
32 | // FIXME(eddyb) find a common convention for all of the debuginfo-related |
33 | // names (choose between `Dbg`, `Debug`, `DebugInfo`, `DI` etc.). | |
a1dfa0c6 | 34 | type DIScope: Copy; |
74b04a01 | 35 | type DIVariable: Copy; |
a1dfa0c6 XL |
36 | } |
37 | ||
38 | pub trait Backend<'tcx>: | |
ba9703b0 | 39 | Sized + BackendTypes + HasTyCtxt<'tcx> + LayoutOf<Ty = Ty<'tcx>, TyAndLayout = TyAndLayout<'tcx>> |
a1dfa0c6 XL |
40 | { |
41 | } | |
42 | ||
43 | impl<'tcx, T> Backend<'tcx> for T where | |
ba9703b0 | 44 | Self: BackendTypes + HasTyCtxt<'tcx> + LayoutOf<Ty = Ty<'tcx>, TyAndLayout = TyAndLayout<'tcx>> |
a1dfa0c6 XL |
45 | { |
46 | } | |
47 | ||
ba9703b0 XL |
48 | pub trait CodegenBackend { |
49 | fn init(&self, _sess: &Session) {} | |
50 | fn print(&self, _req: PrintRequest, _sess: &Session) {} | |
51 | fn target_features(&self, _sess: &Session) -> Vec<Symbol> { | |
52 | vec![] | |
53 | } | |
54 | fn print_passes(&self) {} | |
55 | fn print_version(&self) {} | |
56 | ||
57 | fn metadata_loader(&self) -> Box<MetadataLoaderDyn>; | |
f035d41b XL |
58 | fn provide(&self, _providers: &mut Providers); |
59 | fn provide_extern(&self, _providers: &mut Providers); | |
ba9703b0 XL |
60 | fn codegen_crate<'tcx>( |
61 | &self, | |
62 | tcx: TyCtxt<'tcx>, | |
63 | metadata: EncodedMetadata, | |
64 | need_metadata_module: bool, | |
65 | ) -> Box<dyn Any>; | |
66 | ||
67 | /// This is called on the returned `Box<dyn Any>` from `codegen_backend` | |
68 | /// | |
69 | /// # Panics | |
70 | /// | |
71 | /// Panics when the passed `Box<dyn Any>` was not returned by `codegen_backend`. | |
72 | fn join_codegen( | |
73 | &self, | |
74 | ongoing_codegen: Box<dyn Any>, | |
75 | sess: &Session, | |
76 | dep_graph: &DepGraph, | |
77 | ) -> Result<Box<dyn Any>, ErrorReported>; | |
78 | ||
79 | /// This is called on the returned `Box<dyn Any>` from `join_codegen` | |
80 | /// | |
81 | /// # Panics | |
82 | /// | |
83 | /// Panics when the passed `Box<dyn Any>` was not returned by `join_codegen`. | |
84 | fn link( | |
85 | &self, | |
86 | sess: &Session, | |
87 | codegen_results: Box<dyn Any>, | |
88 | outputs: &OutputFilenames, | |
89 | ) -> Result<(), ErrorReported>; | |
90 | } | |
91 | ||
dfeec247 | 92 | pub trait ExtraBackendMethods: CodegenBackend + WriteBackendMethods + Sized + Send + Sync { |
dc9dc135 XL |
93 | fn new_metadata(&self, sess: TyCtxt<'_>, mod_name: &str) -> Self::Module; |
94 | fn write_compressed_metadata<'tcx>( | |
a1dfa0c6 | 95 | &self, |
dc9dc135 | 96 | tcx: TyCtxt<'tcx>, |
48663c56 XL |
97 | metadata: &EncodedMetadata, |
98 | llvm_module: &mut Self::Module, | |
99 | ); | |
dc9dc135 | 100 | fn codegen_allocator<'tcx>( |
9fa01778 | 101 | &self, |
dc9dc135 | 102 | tcx: TyCtxt<'tcx>, |
9fa01778 | 103 | mods: &mut Self::Module, |
dc9dc135 | 104 | kind: AllocatorKind, |
9fa01778 | 105 | ); |
dfeec247 XL |
106 | /// This generates the codegen unit and returns it along with |
107 | /// a `u64` giving an estimate of the unit's processing cost. | |
e74abb32 XL |
108 | fn compile_codegen_unit( |
109 | &self, | |
110 | tcx: TyCtxt<'_>, | |
111 | cgu_name: Symbol, | |
dfeec247 | 112 | ) -> (ModuleCodegen<Self::Module>, u64); |
a1dfa0c6 XL |
113 | fn target_machine_factory( |
114 | &self, | |
115 | sess: &Session, | |
9fa01778 | 116 | opt_level: config::OptLevel, |
a1dfa0c6 XL |
117 | ) -> Arc<dyn Fn() -> Result<Self::TargetMachine, String> + Send + Sync>; |
118 | fn target_cpu<'b>(&self, sess: &'b Session) -> &'b str; | |
119 | } |