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;
22 use std::sync::mpsc::Receiver;
23 use syntax_pos::symbol::InternedString;
24 use {CachedModuleCodegen, ModuleCodegen};
26 pub trait BackendTypes {
27 type Value: CodegenObject;
28 type BasicBlock: Copy;
29 type Type: CodegenObject;
36 pub trait Backend<'tcx>:
37 BackendTypes + HasTyCtxt<'tcx> + LayoutOf<Ty = Ty<'tcx>, TyLayout = TyLayout<'tcx>>
41 impl<'tcx, T> Backend<'tcx> for T where
42 Self: BackendTypes + HasTyCtxt<'tcx> + LayoutOf<Ty = Ty<'tcx>, TyLayout = TyLayout<'tcx>>
45 pub trait BackendMethods {
49 fn new_metadata(&self, sess: &Session, mod_name: &str) -> Self::Module;
50 fn write_metadata<'b, 'gcx>(
52 tcx: TyCtxt<'b, 'gcx, 'gcx>,
53 metadata: &Self::Module,
55 fn codegen_allocator(&self, tcx: TyCtxt, mods: &Self::Module, kind: AllocatorKind);
57 fn start_async_codegen(
60 time_graph: Option<TimeGraph>,
61 metadata: EncodedMetadata,
62 coordinator_receive: Receiver<Box<dyn Any + Send>>,
64 ) -> Self::OngoingCodegen;
65 fn submit_pre_codegened_module_to_backend(
67 codegen: &Self::OngoingCodegen,
69 module: ModuleCodegen<Self::Module>,
71 fn submit_pre_lto_module_to_backend(&self, tcx: TyCtxt, module: CachedModuleCodegen);
72 fn submit_post_lto_module_to_backend(&self, tcx: TyCtxt, module: CachedModuleCodegen);
73 fn codegen_aborted(codegen: Self::OngoingCodegen);
74 fn codegen_finished(&self, codegen: &Self::OngoingCodegen, tcx: TyCtxt);
75 fn check_for_errors(&self, codegen: &Self::OngoingCodegen, sess: &Session);
76 fn wait_for_signal_to_codegen_item(&self, codegen: &Self::OngoingCodegen);
77 fn compile_codegen_unit<'a, 'tcx: 'a>(
79 tcx: TyCtxt<'a, 'tcx, 'tcx>,
80 cgu_name: InternedString,