@@ -2,15 +2,22 @@ use super::write::WriteBackendMethods;
22use super :: CodegenObject ;
33use crate :: ModuleCodegen ;
44
5- use rustc:: middle:: cstore:: EncodedMetadata ;
5+ use rustc:: dep_graph:: DepGraph ;
6+ use rustc:: middle:: cstore:: { EncodedMetadata , MetadataLoaderDyn } ;
67use rustc:: ty:: layout:: { HasTyCtxt , LayoutOf , TyLayout } ;
7- use rustc:: ty:: Ty ;
8- use rustc:: ty:: TyCtxt ;
8+ use rustc:: ty:: query:: Providers ;
9+ use rustc:: ty:: { Ty , TyCtxt } ;
10+ use rustc:: util:: common:: ErrorReported ;
911use rustc_ast:: expand:: allocator:: AllocatorKind ;
10- use rustc_codegen_utils:: codegen_backend:: CodegenBackend ;
11- use rustc_session:: { config, Session } ;
12+ use rustc_session:: {
13+ config:: { self , OutputFilenames , PrintRequest } ,
14+ Session ,
15+ } ;
1216use rustc_span:: symbol:: Symbol ;
1317
18+ pub use rustc_data_structures:: sync:: MetadataRef ;
19+
20+ use std:: any:: Any ;
1421use std:: sync:: Arc ;
1522
1623pub trait BackendTypes {
@@ -37,6 +44,50 @@ impl<'tcx, T> Backend<'tcx> for T where
3744{
3845}
3946
47+ pub trait CodegenBackend {
48+ fn init ( & self , _sess : & Session ) { }
49+ fn print ( & self , _req : PrintRequest , _sess : & Session ) { }
50+ fn target_features ( & self , _sess : & Session ) -> Vec < Symbol > {
51+ vec ! [ ]
52+ }
53+ fn print_passes ( & self ) { }
54+ fn print_version ( & self ) { }
55+
56+ fn metadata_loader ( & self ) -> Box < MetadataLoaderDyn > ;
57+ fn provide ( & self , _providers : & mut Providers < ' _ > ) ;
58+ fn provide_extern ( & self , _providers : & mut Providers < ' _ > ) ;
59+ fn codegen_crate < ' tcx > (
60+ & self ,
61+ tcx : TyCtxt < ' tcx > ,
62+ metadata : EncodedMetadata ,
63+ need_metadata_module : bool ,
64+ ) -> Box < dyn Any > ;
65+
66+ /// This is called on the returned `Box<dyn Any>` from `codegen_backend`
67+ ///
68+ /// # Panics
69+ ///
70+ /// Panics when the passed `Box<dyn Any>` was not returned by `codegen_backend`.
71+ fn join_codegen (
72+ & self ,
73+ ongoing_codegen : Box < dyn Any > ,
74+ sess : & Session ,
75+ dep_graph : & DepGraph ,
76+ ) -> Result < Box < dyn Any > , ErrorReported > ;
77+
78+ /// This is called on the returned `Box<dyn Any>` from `join_codegen`
79+ ///
80+ /// # Panics
81+ ///
82+ /// Panics when the passed `Box<dyn Any>` was not returned by `join_codegen`.
83+ fn link (
84+ & self ,
85+ sess : & Session ,
86+ codegen_results : Box < dyn Any > ,
87+ outputs : & OutputFilenames ,
88+ ) -> Result < ( ) , ErrorReported > ;
89+ }
90+
4091pub trait ExtraBackendMethods : CodegenBackend + WriteBackendMethods + Sized + Send + Sync {
4192 fn new_metadata ( & self , sess : TyCtxt < ' _ > , mod_name : & str ) -> Self :: Module ;
4293 fn write_compressed_metadata < ' tcx > (
0 commit comments