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.
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.
11 use rustc::ty::layout::{HasTyCtxt, LayoutOf, TyLayout};
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;
23 use std::sync::mpsc::Receiver;
24 use syntax_pos::symbol::InternedString;
25 use {CachedModuleCodegen, ModuleCodegen};
27 pub trait BackendTypes {
28 type Value: CodegenObject;
29 type BasicBlock: Copy;
30 type Type: CodegenObject;
37 pub trait Backend<'tcx>:
38 BackendTypes + HasTyCtxt<'tcx> + LayoutOf<Ty = Ty<'tcx>, TyLayout = TyLayout<'tcx>>
42 impl<'tcx, T> Backend<'tcx> for T where
43 Self: BackendTypes + HasTyCtxt<'tcx> + LayoutOf<Ty = Ty<'tcx>, TyLayout = TyLayout<'tcx>>
46 pub trait ExtraBackendMethods: CodegenBackend {
50 fn new_metadata(&self, sess: &Session, mod_name: &str) -> Self::Module;
51 fn write_metadata<'b, 'gcx>(
53 tcx: TyCtxt<'b, 'gcx, 'gcx>,
54 metadata: &Self::Module,
56 fn codegen_allocator(&self, tcx: TyCtxt, mods: &Self::Module, kind: AllocatorKind);
58 fn start_async_codegen(
61 time_graph: Option<TimeGraph>,
62 metadata: EncodedMetadata,
63 coordinator_receive: Receiver<Box<dyn Any + Send>>,
65 ) -> Self::OngoingCodegen;
66 fn submit_pre_codegened_module_to_backend(
68 codegen: &Self::OngoingCodegen,
70 module: ModuleCodegen<Self::Module>,
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>(
80 tcx: TyCtxt<'a, 'tcx, 'tcx>,
81 cgu_name: InternedString,