59 lines
1.9 KiB
Rust
Raw Normal View History

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
use super::write::WriteBackendMethods;
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;
use rustc::session::{Session, config};
2018-09-25 17:52:03 +02:00
use rustc::ty::TyCtxt;
use rustc_codegen_utils::codegen_backend::CodegenBackend;
use std::sync::Arc;
2018-09-27 15:31:20 +02:00
use syntax_pos::symbol::InternedString;
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;
type Funclet;
type DIScope: Copy;
}
2018-09-13 14:58:19 +02:00
pub trait Backend<'tcx>:
Sized + BackendTypes + HasTyCtxt<'tcx> + LayoutOf<Ty = Ty<'tcx>, TyLayout = TyLayout<'tcx>>
2018-09-13 14:58:19 +02:00
{
}
impl<'tcx, T> Backend<'tcx> for T where
Self: BackendTypes + HasTyCtxt<'tcx> + LayoutOf<Ty = Ty<'tcx>, TyLayout = TyLayout<'tcx>>
2018-11-24 16:15:26 +01:00
{
}
2018-09-25 17:52:03 +02:00
pub trait ExtraBackendMethods: CodegenBackend + WriteBackendMethods + Sized + Send {
fn new_metadata(&self, sess: TyCtxt<'_, '_>, mod_name: &str) -> Self::Module;
fn write_compressed_metadata<'gcx>(
2018-09-25 17:52:03 +02:00
&self,
tcx: TyCtxt<'gcx, 'gcx>,
metadata: &EncodedMetadata,
llvm_module: &mut Self::Module,
);
fn codegen_allocator<'gcx>(
&self,
tcx: TyCtxt<'gcx, 'gcx>,
mods: &mut Self::Module,
kind: AllocatorKind,
);
fn compile_codegen_unit<'a, 'tcx: 'a>(&self, tcx: TyCtxt<'tcx, 'tcx>, cgu_name: InternedString);
// If find_features is true this won't access `sess.crate_types` by assuming
// that `is_pie_binary` is false. When we discover LLVM target features
// `sess.crate_types` is uninitialized so we cannot access it.
fn target_machine_factory(
&self,
sess: &Session,
opt_level: config::OptLevel,
find_features: bool,
) -> Arc<dyn Fn() -> Result<Self::TargetMachine, String> + Send + Sync>;
fn target_cpu<'b>(&self, sess: &'b Session) -> &'b str;
}