5 //! This API is completely unstable and subject to change.
7 #![doc(html_root_url = "https://doc.rust-lang.org/nightly/")]
11 use rustc::dep_graph::DepGraph;
12 use rustc::middle::cstore::{EncodedMetadata, MetadataLoaderDyn};
13 use rustc::session::config::{OutputFilenames, PrintRequest};
14 use rustc::session::Session;
15 use rustc::ty::query::Providers;
16 use rustc::ty::TyCtxt;
17 use rustc::util::common::ErrorReported;
18 use rustc_span::symbol::Symbol;
20 pub use rustc_data_structures::sync::MetadataRef;
22 pub trait CodegenBackend {
23 fn init(&self, _sess: &Session) {}
24 fn print(&self, _req: PrintRequest, _sess: &Session) {}
25 fn target_features(&self, _sess: &Session) -> Vec<Symbol> {
28 fn print_passes(&self) {}
29 fn print_version(&self) {}
31 fn metadata_loader(&self) -> Box<MetadataLoaderDyn>;
32 fn provide(&self, _providers: &mut Providers<'_>);
33 fn provide_extern(&self, _providers: &mut Providers<'_>);
34 fn codegen_crate<'tcx>(
37 metadata: EncodedMetadata,
38 need_metadata_module: bool,
41 /// This is called on the returned `Box<dyn Any>` from `codegen_backend`
45 /// Panics when the passed `Box<dyn Any>` was not returned by `codegen_backend`.
48 ongoing_codegen: Box<dyn Any>,
51 ) -> Result<Box<dyn Any>, ErrorReported>;
53 /// This is called on the returned `Box<dyn Any>` from `join_codegen`
57 /// Panics when the passed `Box<dyn Any>` was not returned by `join_codegen`.
61 codegen_results: Box<dyn Any>,
62 outputs: &OutputFilenames,
63 ) -> Result<(), ErrorReported>;