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