]> git.lizzy.rs Git - rust.git/blob - src/librustc_codegen_utils/codegen_backend.rs
Run `rustfmt --file-lines ...` for changes from previous commits.
[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 #![deny(warnings)]
9 #![feature(box_syntax)]
10
11 use std::any::Any;
12 use std::sync::mpsc;
13
14 use syntax::symbol::Symbol;
15 use rustc::session::Session;
16 use rustc::util::common::ErrorReported;
17 use rustc::session::config::{OutputFilenames, PrintRequest};
18 use rustc::ty::TyCtxt;
19 use rustc::ty::query::Providers;
20 use rustc::middle::cstore::{EncodedMetadata, MetadataLoader};
21 use rustc::dep_graph::DepGraph;
22
23 pub use rustc_data_structures::sync::MetadataRef;
24
25 pub trait CodegenBackend {
26     fn init(&self, _sess: &Session) {}
27     fn print(&self, _req: PrintRequest, _sess: &Session) {}
28     fn target_features(&self, _sess: &Session) -> Vec<Symbol> { vec![] }
29     fn print_passes(&self) {}
30     fn print_version(&self) {}
31     fn diagnostics(&self) -> &[(&'static str, &'static str)] { &[] }
32
33     fn metadata_loader(&self) -> Box<dyn MetadataLoader + Sync>;
34     fn provide(&self, _providers: &mut Providers<'_>);
35     fn provide_extern(&self, _providers: &mut Providers<'_>);
36     fn codegen_crate<'tcx>(
37         &self,
38         tcx: TyCtxt<'tcx, 'tcx>,
39         metadata: EncodedMetadata,
40         need_metadata_module: bool,
41         rx: mpsc::Receiver<Box<dyn Any + Send>>,
42     ) -> Box<dyn Any>;
43
44     /// This is called on the returned `Box<dyn Any>` from `codegen_backend`
45     ///
46     /// # Panics
47     ///
48     /// Panics when the passed `Box<dyn Any>` was not returned by `codegen_backend`.
49     fn join_codegen_and_link(
50         &self,
51         ongoing_codegen: Box<dyn Any>,
52         sess: &Session,
53         dep_graph: &DepGraph,
54         outputs: &OutputFilenames,
55     ) -> Result<(), ErrorReported>;
56 }