]> git.lizzy.rs Git - rust.git/blob - src/librustc_codegen_utils/codegen_backend.rs
Rollup merge of #63055 - Mark-Simulacrum:save-analysis-clean-2, r=Xanewok
[rust.git] / src / librustc_codegen_utils / codegen_backend.rs
1 //! The Rust compiler.
2 //!
3 //! # Note
4 //!
5 //! This API is completely unstable and subject to change.
6
7 #![doc(html_root_url = "https://doc.rust-lang.org/nightly/")]
8
9 use std::any::Any;
10 use std::sync::mpsc;
11
12 use syntax::symbol::Symbol;
13 use rustc::session::Session;
14 use rustc::util::common::ErrorReported;
15 use rustc::session::config::{OutputFilenames, PrintRequest};
16 use rustc::ty::TyCtxt;
17 use rustc::ty::query::Providers;
18 use rustc::middle::cstore::{EncodedMetadata, MetadataLoader};
19 use rustc::dep_graph::DepGraph;
20
21 pub use rustc_data_structures::sync::MetadataRef;
22
23 pub trait CodegenBackend {
24     fn init(&self, _sess: &Session) {}
25     fn print(&self, _req: PrintRequest, _sess: &Session) {}
26     fn target_features(&self, _sess: &Session) -> Vec<Symbol> { vec![] }
27     fn print_passes(&self) {}
28     fn print_version(&self) {}
29     fn diagnostics(&self) -> &[(&'static str, &'static str)] { &[] }
30
31     fn metadata_loader(&self) -> Box<dyn MetadataLoader + Sync>;
32     fn provide(&self, _providers: &mut Providers<'_>);
33     fn provide_extern(&self, _providers: &mut Providers<'_>);
34     fn codegen_crate<'tcx>(
35         &self,
36         tcx: TyCtxt<'tcx>,
37         metadata: EncodedMetadata,
38         need_metadata_module: bool,
39         rx: mpsc::Receiver<Box<dyn Any + Send>>,
40     ) -> Box<dyn Any>;
41
42     /// This is called on the returned `Box<dyn Any>` from `codegen_backend`
43     ///
44     /// # Panics
45     ///
46     /// Panics when the passed `Box<dyn Any>` was not returned by `codegen_backend`.
47     fn join_codegen_and_link(
48         &self,
49         ongoing_codegen: Box<dyn Any>,
50         sess: &Session,
51         dep_graph: &DepGraph,
52         outputs: &OutputFilenames,
53     ) -> Result<(), ErrorReported>;
54 }