Traitified IntrinsicCallMethods
This commit is contained in:
parent
a5aeb8edd6
commit
0a1c50955b
11 changed files with 670 additions and 646 deletions
|
@ -73,9 +73,7 @@ use rustc_data_structures::small_c_str::SmallCStr;
|
||||||
use rustc_data_structures::sync::Lrc;
|
use rustc_data_structures::sync::Lrc;
|
||||||
use rustc_data_structures::indexed_vec::Idx;
|
use rustc_data_structures::indexed_vec::Idx;
|
||||||
|
|
||||||
use interfaces::{
|
use interfaces::*;
|
||||||
BuilderMethods, ConstMethods, BaseTypeMethods, DerivedTypeMethods, DerivedIntrinsicMethods,
|
|
||||||
};
|
|
||||||
|
|
||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
|
|
|
@ -19,10 +19,7 @@ use rustc::ty::TyCtxt;
|
||||||
use rustc::ty::layout::{Align, Size};
|
use rustc::ty::layout::{Align, Size};
|
||||||
use rustc::session::{config, Session};
|
use rustc::session::{config, Session};
|
||||||
use rustc_data_structures::small_c_str::SmallCStr;
|
use rustc_data_structures::small_c_str::SmallCStr;
|
||||||
use interfaces::{
|
use interfaces::*;
|
||||||
Backend,
|
|
||||||
BuilderMethods, ConstMethods, BaseTypeMethods, DerivedTypeMethods, DerivedIntrinsicMethods,
|
|
||||||
};
|
|
||||||
use syntax;
|
use syntax;
|
||||||
|
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
@ -59,16 +56,11 @@ bitflags! {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Backend for Builder<'a, 'll, 'tcx> {
|
impl HasCodegen for Builder<'a, 'll, 'tcx> {
|
||||||
type Value = &'ll Value;
|
type CodegenCx = CodegenCx<'ll, 'tcx>;
|
||||||
type BasicBlock = &'ll BasicBlock;
|
|
||||||
type Type = &'ll Type;
|
|
||||||
type Context = &'ll llvm::Context;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
|
impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
|
||||||
type CodegenCx = CodegenCx<'ll, 'tcx>;
|
|
||||||
|
|
||||||
fn new_block<'b>(
|
fn new_block<'b>(
|
||||||
cx: &'a CodegenCx<'ll, 'tcx>,
|
cx: &'a CodegenCx<'ll, 'tcx>,
|
||||||
llfn: &'ll Value,
|
llfn: &'ll Value,
|
||||||
|
|
|
@ -23,8 +23,7 @@ use value::Value;
|
||||||
use monomorphize::partitioning::CodegenUnit;
|
use monomorphize::partitioning::CodegenUnit;
|
||||||
use type_::Type;
|
use type_::Type;
|
||||||
use type_of::PointeeInfo;
|
use type_of::PointeeInfo;
|
||||||
use interfaces::{BaseTypeMethods, DerivedTypeMethods,
|
use interfaces::{BaseTypeMethods, DerivedTypeMethods, IntrinsicDeclarationMethods};
|
||||||
IntrinsicMethods, BaseIntrinsicMethods, DerivedIntrinsicMethods};
|
|
||||||
|
|
||||||
use rustc_data_structures::base_n;
|
use rustc_data_structures::base_n;
|
||||||
use rustc_data_structures::small_c_str::SmallCStr;
|
use rustc_data_structures::small_c_str::SmallCStr;
|
||||||
|
@ -323,9 +322,7 @@ impl<'b, 'tcx> CodegenCx<'b, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BaseIntrinsicMethods for CodegenCx<'_, '_> {}
|
impl IntrinsicDeclarationMethods for CodegenCx<'b, 'tcx> {
|
||||||
|
|
||||||
impl DerivedIntrinsicMethods for CodegenCx<'b, 'tcx> {
|
|
||||||
fn get_intrinsic(&self, key: &str) -> &'b Value {
|
fn get_intrinsic(&self, key: &str) -> &'b Value {
|
||||||
if let Some(v) = self.intrinsics.borrow().get(key).cloned() {
|
if let Some(v) = self.intrinsics.borrow().get(key).cloned() {
|
||||||
return v;
|
return v;
|
||||||
|
@ -647,8 +644,6 @@ impl DerivedIntrinsicMethods for CodegenCx<'b, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IntrinsicMethods for CodegenCx<'a, 'tcx> {}
|
|
||||||
|
|
||||||
impl<'b, 'tcx> CodegenCx<'b, 'tcx> {
|
impl<'b, 'tcx> CodegenCx<'b, 'tcx> {
|
||||||
/// Generate a new symbol name with the given prefix. This symbol name must
|
/// Generate a new symbol name with the given prefix. This symbol name must
|
||||||
/// only be used for definitions with `internal` or `private` linkage.
|
/// only be used for definitions with `internal` or `private` linkage.
|
||||||
|
|
|
@ -17,21 +17,29 @@ use builder::MemFlags;
|
||||||
use super::backend::Backend;
|
use super::backend::Backend;
|
||||||
use super::type_::TypeMethods;
|
use super::type_::TypeMethods;
|
||||||
use super::consts::ConstMethods;
|
use super::consts::ConstMethods;
|
||||||
use super::intrinsic::IntrinsicMethods;
|
use super::intrinsic::IntrinsicDeclarationMethods;
|
||||||
|
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::ops::Range;
|
use std::ops::Range;
|
||||||
use syntax::ast::AsmDialect;
|
use syntax::ast::AsmDialect;
|
||||||
|
|
||||||
|
pub trait HasCodegen: Backend {
|
||||||
pub trait BuilderMethods<'a, 'tcx: 'a>: Backend {
|
type CodegenCx: TypeMethods + ConstMethods + IntrinsicDeclarationMethods + Backend<
|
||||||
type CodegenCx: 'a + TypeMethods + ConstMethods + IntrinsicMethods + Backend<
|
|
||||||
Value = Self::Value,
|
Value = Self::Value,
|
||||||
BasicBlock = Self::BasicBlock,
|
BasicBlock = Self::BasicBlock,
|
||||||
Type = Self::Type,
|
Type = Self::Type,
|
||||||
Context = Self::Context,
|
Context = Self::Context,
|
||||||
>;
|
>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: HasCodegen> Backend for T {
|
||||||
|
type Value = <T::CodegenCx as Backend>::Value;
|
||||||
|
type BasicBlock = <T::CodegenCx as Backend>::BasicBlock;
|
||||||
|
type Type = <T::CodegenCx as Backend>::Type;
|
||||||
|
type Context = <T::CodegenCx as Backend>::Context;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait BuilderMethods<'a, 'tcx: 'a>: HasCodegen {
|
||||||
fn new_block<'b>(
|
fn new_block<'b>(
|
||||||
cx: &'a Self::CodegenCx,
|
cx: &'a Self::CodegenCx,
|
||||||
llfn: Self::Value,
|
llfn: Self::Value,
|
||||||
|
|
|
@ -9,17 +9,27 @@
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
use super::backend::Backend;
|
use super::backend::Backend;
|
||||||
|
use super::builder::HasCodegen;
|
||||||
|
use mir::operand::OperandRef;
|
||||||
|
use rustc::ty::Ty;
|
||||||
|
use abi::FnType;
|
||||||
|
use syntax_pos::Span;
|
||||||
|
|
||||||
pub trait BaseIntrinsicMethods: Backend {
|
pub trait IntrinsicCallMethods<'a, 'tcx: 'a>: HasCodegen {
|
||||||
|
fn codegen_intrinsic_call(
|
||||||
|
&self,
|
||||||
|
callee_ty: Ty<'tcx>,
|
||||||
|
fn_ty: &FnType<'tcx, Ty<'tcx>>,
|
||||||
|
args: &[OperandRef<'tcx, Self::Value>],
|
||||||
|
llresult: Self::Value,
|
||||||
|
span: Span,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait DerivedIntrinsicMethods: Backend {
|
pub trait IntrinsicDeclarationMethods: Backend {
|
||||||
fn get_intrinsic(&self, key: &str) -> Self::Value;
|
fn get_intrinsic(&self, key: &str) -> Self::Value;
|
||||||
fn declare_intrinsic(
|
fn declare_intrinsic(
|
||||||
&self,
|
&self,
|
||||||
key: &str
|
key: &str
|
||||||
) -> Option<Self::Value>;
|
) -> Option<Self::Value>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait IntrinsicMethods: BaseIntrinsicMethods + DerivedIntrinsicMethods {}
|
|
||||||
|
|
|
@ -15,9 +15,9 @@ mod type_;
|
||||||
mod intrinsic;
|
mod intrinsic;
|
||||||
mod statics;
|
mod statics;
|
||||||
|
|
||||||
pub use self::builder::BuilderMethods;
|
pub use self::builder::{BuilderMethods, HasCodegen};
|
||||||
pub use self::backend::Backend;
|
pub use self::backend::Backend;
|
||||||
pub use self::consts::ConstMethods;
|
pub use self::consts::ConstMethods;
|
||||||
pub use self::type_::{TypeMethods, BaseTypeMethods, DerivedTypeMethods};
|
pub use self::type_::{TypeMethods, BaseTypeMethods, DerivedTypeMethods};
|
||||||
pub use self::intrinsic::{IntrinsicMethods, BaseIntrinsicMethods, DerivedIntrinsicMethods};
|
pub use self::intrinsic::{IntrinsicCallMethods, IntrinsicDeclarationMethods};
|
||||||
pub use self::statics::StaticMethods;
|
pub use self::statics::StaticMethods;
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -25,10 +25,7 @@ use type_of::LayoutLlvmExt;
|
||||||
use type_::Type;
|
use type_::Type;
|
||||||
use value::Value;
|
use value::Value;
|
||||||
|
|
||||||
use interfaces::{
|
use interfaces::*;
|
||||||
BuilderMethods, ConstMethods, BaseTypeMethods, DerivedTypeMethods, DerivedIntrinsicMethods,
|
|
||||||
StaticMethods,
|
|
||||||
};
|
|
||||||
|
|
||||||
use syntax::symbol::Symbol;
|
use syntax::symbol::Symbol;
|
||||||
use syntax_pos::Pos;
|
use syntax_pos::Pos;
|
||||||
|
@ -560,8 +557,6 @@ impl FunctionCx<'a, 'll, 'tcx, &'ll Value> {
|
||||||
};
|
};
|
||||||
|
|
||||||
if intrinsic.is_some() && intrinsic != Some("drop_in_place") {
|
if intrinsic.is_some() && intrinsic != Some("drop_in_place") {
|
||||||
use intrinsic::codegen_intrinsic_call;
|
|
||||||
|
|
||||||
let dest = match ret_dest {
|
let dest = match ret_dest {
|
||||||
_ if fn_ty.ret.is_indirect() => llargs[0],
|
_ if fn_ty.ret.is_indirect() => llargs[0],
|
||||||
ReturnDest::Nothing => {
|
ReturnDest::Nothing => {
|
||||||
|
@ -628,8 +623,8 @@ impl FunctionCx<'a, 'll, 'tcx, &'ll Value> {
|
||||||
|
|
||||||
|
|
||||||
let callee_ty = instance.as_ref().unwrap().ty(bx.cx().tcx);
|
let callee_ty = instance.as_ref().unwrap().ty(bx.cx().tcx);
|
||||||
codegen_intrinsic_call(&bx, callee_ty, &fn_ty, &args, dest,
|
&bx.codegen_intrinsic_call(callee_ty, &fn_ty, &args, dest,
|
||||||
terminator.source_info.span);
|
terminator.source_info.span);
|
||||||
|
|
||||||
if let ReturnDest::IndirectOperand(dst, _) = ret_dest {
|
if let ReturnDest::IndirectOperand(dst, _) = ret_dest {
|
||||||
self.store_return(&bx, ret_dest, &fn_ty.ret, dst.llval);
|
self.store_return(&bx, ret_dest, &fn_ty.ret, dst.llval);
|
||||||
|
|
|
@ -20,7 +20,7 @@ use value::Value;
|
||||||
use type_of::LayoutLlvmExt;
|
use type_of::LayoutLlvmExt;
|
||||||
use glue;
|
use glue;
|
||||||
|
|
||||||
use interfaces::{BuilderMethods, ConstMethods, BaseTypeMethods, DerivedIntrinsicMethods};
|
use interfaces::{BuilderMethods, ConstMethods, BaseTypeMethods, IntrinsicDeclarationMethods};
|
||||||
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
|
|
|
@ -21,10 +21,7 @@ use value::Value;
|
||||||
use glue;
|
use glue;
|
||||||
use mir::constant::const_alloc_to_llvm;
|
use mir::constant::const_alloc_to_llvm;
|
||||||
|
|
||||||
use interfaces::{
|
use interfaces::*;
|
||||||
BuilderMethods, ConstMethods, BaseTypeMethods, DerivedTypeMethods, DerivedIntrinsicMethods,
|
|
||||||
StaticMethods,
|
|
||||||
};
|
|
||||||
|
|
||||||
use super::{FunctionCx, LocalRef};
|
use super::{FunctionCx, LocalRef};
|
||||||
use super::operand::{OperandRef, OperandValue};
|
use super::operand::{OperandRef, OperandValue};
|
||||||
|
|
|
@ -25,7 +25,7 @@ use type_::Type;
|
||||||
use type_of::LayoutLlvmExt;
|
use type_of::LayoutLlvmExt;
|
||||||
use value::Value;
|
use value::Value;
|
||||||
|
|
||||||
use interfaces::{BuilderMethods, ConstMethods, BaseTypeMethods, DerivedIntrinsicMethods};
|
use interfaces::{BuilderMethods, ConstMethods, BaseTypeMethods, IntrinsicDeclarationMethods};
|
||||||
|
|
||||||
use super::{FunctionCx, LocalRef};
|
use super::{FunctionCx, LocalRef};
|
||||||
use super::operand::{OperandRef, OperandValue};
|
use super::operand::{OperandRef, OperandValue};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue