]> git.lizzy.rs Git - rust.git/blob - src/librustc_codegen_ssa/interfaces/backend.rs
Beginning of moving all backend-agnostic code to rustc_codegen_ssa
[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 std::any::Any;
22 use std::sync::mpsc::Receiver;
23 use syntax_pos::symbol::InternedString;
24 use ModuleCodegen;
25
26 pub trait BackendTypes {
27     type Value: CodegenObject;
28     type BasicBlock: Copy;
29     type Type: CodegenObject;
30     type Context;
31     type Funclet;
32
33     type DIScope: Copy;
34 }
35
36 pub trait Backend<'tcx>:
37     BackendTypes + HasTyCtxt<'tcx> + LayoutOf<Ty = Ty<'tcx>, TyLayout = TyLayout<'tcx>>
38 {
39 }
40
41 impl<'tcx, T> Backend<'tcx> for T where
42     Self: BackendTypes + HasTyCtxt<'tcx> + LayoutOf<Ty = Ty<'tcx>, TyLayout = TyLayout<'tcx>>
43 {}
44
45 pub trait BackendMethods {
46     type Module;
47     type OngoingCodegen;
48
49     fn new_metadata(&self, sess: &Session, mod_name: &str) -> Self::Module;
50     fn write_metadata<'b, 'gcx>(
51         &self,
52         tcx: TyCtxt<'b, 'gcx, 'gcx>,
53         metadata: &Self::Module,
54     ) -> EncodedMetadata;
55     fn codegen_allocator(&self, tcx: TyCtxt, mods: &Self::Module, kind: AllocatorKind);
56
57     fn start_async_codegen(
58         &self,
59         tcx: TyCtxt,
60         time_graph: Option<TimeGraph>,
61         metadata: EncodedMetadata,
62         coordinator_receive: Receiver<Box<dyn Any + Send>>,
63         total_cgus: usize,
64     ) -> Self::OngoingCodegen;
65     fn submit_pre_codegened_module_to_llvm(
66         &self,
67         codegen: &Self::OngoingCodegen,
68         tcx: TyCtxt,
69         module: ModuleCodegen<Self::Module>,
70     );
71     fn codegen_aborted(codegen: Self::OngoingCodegen);
72     fn codegen_finished(&self, codegen: &Self::OngoingCodegen, tcx: TyCtxt);
73     fn check_for_errors(&self, codegen: &Self::OngoingCodegen, sess: &Session);
74     fn wait_for_signal_to_codegen_item(&self, codegen: &Self::OngoingCodegen);
75     fn compile_codegen_unit<'a, 'tcx: 'a>(
76         &self,
77         tcx: TyCtxt<'a, 'tcx, 'tcx>,
78         cgu_name: InternedString,
79     ) -> Stats;
80 }