]> git.lizzy.rs Git - rust.git/blob - src/librustc_codegen_utils/codegen_backend.rs
Rollup merge of #64708 - SimonSapin:option-deref, r=Centril
[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
11 use syntax::symbol::Symbol;
12 use rustc::session::Session;
13 use rustc::util::common::ErrorReported;
14 use rustc::session::config::{OutputFilenames, PrintRequest};
15 use rustc::ty::TyCtxt;
16 use rustc::ty::query::Providers;
17 use rustc::middle::cstore::{EncodedMetadata, MetadataLoader};
18 use rustc::dep_graph::DepGraph;
19
20 pub use rustc_data_structures::sync::MetadataRef;
21
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> { vec![] }
26     fn print_passes(&self) {}
27     fn print_version(&self) {}
28     fn diagnostics(&self) -> &[(&'static str, &'static str)] { &[] }
29
30     fn metadata_loader(&self) -> Box<dyn MetadataLoader + Sync>;
31     fn provide(&self, _providers: &mut Providers<'_>);
32     fn provide_extern(&self, _providers: &mut Providers<'_>);
33     fn codegen_crate<'tcx>(
34         &self,
35         tcx: TyCtxt<'tcx>,
36         metadata: EncodedMetadata,
37         need_metadata_module: bool,
38     ) -> Box<dyn Any>;
39
40     /// This is called on the returned `Box<dyn Any>` from `codegen_backend`
41     ///
42     /// # Panics
43     ///
44     /// Panics when the passed `Box<dyn Any>` was not returned by `codegen_backend`.
45     fn join_codegen_and_link(
46         &self,
47         ongoing_codegen: Box<dyn Any>,
48         sess: &Session,
49         dep_graph: &DepGraph,
50         outputs: &OutputFilenames,
51     ) -> Result<(), ErrorReported>;
52 }