]> git.lizzy.rs Git - rust.git/blob - src/librustc_codegen_utils/codegen_backend.rs
Merge branch 'master' into rusty-hermit
[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
29     fn metadata_loader(&self) -> Box<dyn MetadataLoader + Sync>;
30     fn provide(&self, _providers: &mut Providers<'_>);
31     fn provide_extern(&self, _providers: &mut Providers<'_>);
32     fn codegen_crate<'tcx>(
33         &self,
34         tcx: TyCtxt<'tcx>,
35         metadata: EncodedMetadata,
36         need_metadata_module: bool,
37     ) -> Box<dyn Any>;
38
39     /// This is called on the returned `Box<dyn Any>` from `codegen_backend`
40     ///
41     /// # Panics
42     ///
43     /// Panics when the passed `Box<dyn Any>` was not returned by `codegen_backend`.
44     fn join_codegen_and_link(
45         &self,
46         ongoing_codegen: Box<dyn Any>,
47         sess: &Session,
48         dep_graph: &DepGraph,
49         outputs: &OutputFilenames,
50     ) -> Result<(), ErrorReported>;
51 }