2018-08-28 11:40:34 +02:00
|
|
|
// 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;
|
2018-10-01 10:32:09 +02:00
|
|
|
use rustc::util::time_graph::TimeGraph;
|
2018-10-04 15:23:10 +02:00
|
|
|
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;
|
2018-10-03 13:49:57 +02:00
|
|
|
use {CachedModuleCodegen, ModuleCodegen};
|
2018-08-30 15:41:59 +02:00
|
|
|
|
2018-09-13 14:58:19 +02:00
|
|
|
pub trait BackendTypes {
|
2018-09-14 17:48:57 +02:00
|
|
|
type Value: CodegenObject;
|
2018-09-20 15:47:22 +02:00
|
|
|
type BasicBlock: Copy;
|
2018-09-14 17:48:57 +02:00
|
|
|
type Type: CodegenObject;
|
2018-08-28 17:03:46 +02:00
|
|
|
type Context;
|
2018-11-13 12:51:42 +02:00
|
|
|
type Funclet;
|
2018-09-20 15:47:22 +02:00
|
|
|
|
|
|
|
type DIScope: Copy;
|
2018-08-28 11:40:34 +02:00
|
|
|
}
|
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
|
|
|
|
2018-10-04 15:23:10 +02:00
|
|
|
pub trait ExtraBackendMethods: CodegenBackend {
|
2018-09-26 17:00:01 +02:00
|
|
|
type Module;
|
2018-09-25 17:52:03 +02:00
|
|
|
type OngoingCodegen;
|
|
|
|
|
2018-09-26 17:00:01 +02:00
|
|
|
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,
|
2018-09-26 17:00:01 +02:00
|
|
|
tcx: TyCtxt<'b, 'gcx, 'gcx>,
|
|
|
|
metadata: &Self::Module,
|
2018-09-25 17:52:03 +02:00
|
|
|
) -> EncodedMetadata;
|
2018-09-26 17:00:01 +02:00
|
|
|
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;
|
2018-10-03 13:49:57 +02:00
|
|
|
fn submit_pre_codegened_module_to_backend(
|
2018-09-25 17:52:03 +02:00
|
|
|
&self,
|
|
|
|
codegen: &Self::OngoingCodegen,
|
|
|
|
tcx: TyCtxt,
|
2018-09-26 17:00:01 +02:00
|
|
|
module: ModuleCodegen<Self::Module>,
|
2018-09-25 17:52:03 +02:00
|
|
|
);
|
2018-10-03 13:49:57 +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>(
|
2018-09-26 17:00:01 +02:00
|
|
|
&self,
|
|
|
|
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
2018-09-27 15:31:20 +02:00
|
|
|
cgu_name: InternedString,
|
|
|
|
) -> Stats;
|
2018-09-26 17:00:01 +02:00
|
|
|
}
|