84 lines
2.8 KiB
Rust
Raw Normal View History

// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
2018-09-13 14:58:19 +02:00
use rustc::ty::layout::{HasTyCtxt, LayoutOf, TyLayout};
use rustc::ty::Ty;
2018-09-14 17:48:57 +02:00
2018-09-27 15:31:20 +02:00
use super::CodegenObject;
2018-09-25 17:52:03 +02:00
use rustc::middle::allocator::AllocatorKind;
use rustc::middle::cstore::EncodedMetadata;
2018-09-27 15:31:20 +02:00
use rustc::mir::mono::Stats;
2018-09-25 17:52:03 +02:00
use rustc::session::Session;
use rustc::ty::TyCtxt;
use rustc::util::time_graph::TimeGraph;
use rustc_codegen_utils::codegen_backend::CodegenBackend;
2018-09-25 17:52:03 +02:00
use std::any::Any;
use std::sync::mpsc::Receiver;
2018-09-27 15:31:20 +02:00
use syntax_pos::symbol::InternedString;
use {CachedModuleCodegen, ModuleCodegen};
2018-09-13 14:58:19 +02:00
pub trait BackendTypes {
2018-09-14 17:48:57 +02:00
type Value: CodegenObject;
type BasicBlock: Copy;
2018-09-14 17:48:57 +02:00
type Type: CodegenObject;
2018-08-28 17:03:46 +02:00
type Context;
type Funclet;
type DIScope: Copy;
}
2018-09-13 14:58:19 +02:00
pub trait Backend<'tcx>:
BackendTypes + HasTyCtxt<'tcx> + LayoutOf<Ty = Ty<'tcx>, TyLayout = TyLayout<'tcx>>
{
}
impl<'tcx, T> Backend<'tcx> for T where
Self: BackendTypes + HasTyCtxt<'tcx> + LayoutOf<Ty = Ty<'tcx>, TyLayout = TyLayout<'tcx>>
{}
2018-09-25 17:52:03 +02:00
pub trait ExtraBackendMethods: CodegenBackend {
type Module;
2018-09-25 17:52:03 +02:00
type OngoingCodegen;
fn new_metadata(&self, sess: &Session, mod_name: &str) -> Self::Module;
fn write_metadata<'b, 'gcx>(
2018-09-25 17:52:03 +02:00
&self,
tcx: TyCtxt<'b, 'gcx, 'gcx>,
metadata: &Self::Module,
2018-09-25 17:52:03 +02:00
) -> EncodedMetadata;
fn codegen_allocator(&self, tcx: TyCtxt, mods: &Self::Module, kind: AllocatorKind);
2018-09-25 17:52:03 +02:00
fn start_async_codegen(
&self,
tcx: TyCtxt,
time_graph: Option<TimeGraph>,
metadata: EncodedMetadata,
coordinator_receive: Receiver<Box<dyn Any + Send>>,
total_cgus: usize,
) -> Self::OngoingCodegen;
fn submit_pre_codegened_module_to_backend(
2018-09-25 17:52:03 +02:00
&self,
codegen: &Self::OngoingCodegen,
tcx: TyCtxt,
module: ModuleCodegen<Self::Module>,
2018-09-25 17:52:03 +02:00
);
fn submit_pre_lto_module_to_backend(&self, tcx: TyCtxt, module: CachedModuleCodegen);
fn submit_post_lto_module_to_backend(&self, tcx: TyCtxt, module: CachedModuleCodegen);
2018-09-25 17:52:03 +02:00
fn codegen_aborted(codegen: Self::OngoingCodegen);
fn codegen_finished(&self, codegen: &Self::OngoingCodegen, tcx: TyCtxt);
fn check_for_errors(&self, codegen: &Self::OngoingCodegen, sess: &Session);
fn wait_for_signal_to_codegen_item(&self, codegen: &Self::OngoingCodegen);
2018-09-27 15:31:20 +02:00
fn compile_codegen_unit<'a, 'tcx: 'a>(
&self,
tcx: TyCtxt<'a, 'tcx, 'tcx>,
2018-09-27 15:31:20 +02:00
cgu_name: InternedString,
) -> Stats;
}