]> git.lizzy.rs Git - rust.git/blob - src/librustc_codegen_ssa/interfaces/backend.rs
Added some docs + start to &mut self builder methods
[rust.git] / src / librustc_codegen_ssa / interfaces / backend.rs
1 // Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 use rustc::ty::layout::{HasTyCtxt, LayoutOf, TyLayout};
12 use rustc::ty::Ty;
13
14 use super::CodegenObject;
15 use rustc::middle::allocator::AllocatorKind;
16 use rustc::middle::cstore::EncodedMetadata;
17 use rustc::mir::mono::Stats;
18 use rustc::session::Session;
19 use rustc::ty::TyCtxt;
20 use rustc::util::time_graph::TimeGraph;
21 use rustc_codegen_utils::codegen_backend::CodegenBackend;
22 use std::any::Any;
23 use std::sync::mpsc::Receiver;
24 use syntax_pos::symbol::InternedString;
25 use {CachedModuleCodegen, ModuleCodegen};
26
27 pub trait BackendTypes {
28     type Value: CodegenObject;
29     type BasicBlock: Copy;
30     type Type: CodegenObject;
31     type Context;
32     type Funclet;
33
34     type DIScope: Copy;
35 }
36
37 pub trait Backend<'tcx>:
38     BackendTypes + HasTyCtxt<'tcx> + LayoutOf<Ty = Ty<'tcx>, TyLayout = TyLayout<'tcx>>
39 {
40 }
41
42 impl<'tcx, T> Backend<'tcx> for T where
43     Self: BackendTypes + HasTyCtxt<'tcx> + LayoutOf<Ty = Ty<'tcx>, TyLayout = TyLayout<'tcx>>
44 {}
45
46 pub trait ExtraBackendMethods: CodegenBackend {
47     type Module;
48     type OngoingCodegen;
49
50     fn new_metadata(&self, sess: &Session, mod_name: &str) -> Self::Module;
51     fn write_metadata<'b, 'gcx>(
52         &self,
53         tcx: TyCtxt<'b, 'gcx, 'gcx>,
54         metadata: &Self::Module,
55     ) -> EncodedMetadata;
56     fn codegen_allocator(&self, tcx: TyCtxt, mods: &Self::Module, kind: AllocatorKind);
57
58     fn start_async_codegen(
59         &self,
60         tcx: TyCtxt,
61         time_graph: Option<TimeGraph>,
62         metadata: EncodedMetadata,
63         coordinator_receive: Receiver<Box<dyn Any + Send>>,
64         total_cgus: usize,
65     ) -> Self::OngoingCodegen;
66     fn submit_pre_codegened_module_to_backend(
67         &self,
68         codegen: &Self::OngoingCodegen,
69         tcx: TyCtxt,
70         module: ModuleCodegen<Self::Module>,
71     );
72     fn submit_pre_lto_module_to_backend(&self, tcx: TyCtxt, module: CachedModuleCodegen);
73     fn submit_post_lto_module_to_backend(&self, tcx: TyCtxt, module: CachedModuleCodegen);
74     fn codegen_aborted(codegen: Self::OngoingCodegen);
75     fn codegen_finished(&self, codegen: &Self::OngoingCodegen, tcx: TyCtxt);
76     fn check_for_errors(&self, codegen: &Self::OngoingCodegen, sess: &Session);
77     fn wait_for_signal_to_codegen_item(&self, codegen: &Self::OngoingCodegen);
78     fn compile_codegen_unit<'a, 'tcx: 'a>(
79         &self,
80         tcx: TyCtxt<'a, 'tcx, 'tcx>,
81         cgu_name: InternedString,
82     ) -> Stats;
83 }