diff --git a/src/abi.rs b/src/abi.rs index 036ea80d7ee..84abc5eced8 100644 --- a/src/abi.rs +++ b/src/abi.rs @@ -13,7 +13,7 @@ enum PassMode { } impl PassMode { - fn get_param_ty(self, _fx: &FunctionCx) -> Type { + fn get_param_ty(self, _fx: &FunctionCx) -> Type { match self { PassMode::NoPass => unimplemented!("pass mode nopass"), PassMode::ByVal(cton_type) => cton_type, @@ -163,7 +163,7 @@ pub fn get_function_name_and_sig<'a, 'tcx>( (tcx.symbol_name(inst).as_str().to_string(), sig) } -impl<'a, 'tcx: 'a> FunctionCx<'a, 'tcx> { +impl<'a, 'tcx: 'a, B: Backend + 'a> FunctionCx<'a, 'tcx, B> { /// Instance must be monomorphized pub fn get_function_ref(&mut self, inst: Instance<'tcx>) -> FuncRef { let (name, sig) = get_function_name_and_sig(self.tcx, inst); @@ -243,7 +243,10 @@ fn return_type(&self) -> Ty<'tcx> { } } -pub fn codegen_fn_prelude<'a, 'tcx: 'a>(fx: &mut FunctionCx<'a, 'tcx>, start_ebb: Ebb) { +pub fn codegen_fn_prelude<'a, 'tcx: 'a>( + fx: &mut FunctionCx<'a, 'tcx, impl Backend>, + start_ebb: Ebb, +) { let ssa_analyzed = crate::analyze::analyze(fx); fx.tcx.sess.warn(&format!("ssa {:?}", ssa_analyzed)); @@ -414,7 +417,7 @@ enum ArgKind { } pub fn codegen_call<'a, 'tcx: 'a>( - fx: &mut FunctionCx<'a, 'tcx>, + fx: &mut FunctionCx<'a, 'tcx, impl Backend>, func: &Operand<'tcx>, args: &[Operand<'tcx>], destination: &Option<(Place<'tcx>, BasicBlock)>, @@ -507,7 +510,7 @@ pub fn codegen_call<'a, 'tcx: 'a>( } } -pub fn codegen_return(fx: &mut FunctionCx) { +pub fn codegen_return(fx: &mut FunctionCx) { match get_pass_mode(fx.tcx, fx.self_sig().abi, fx.return_type(), true) { PassMode::NoPass | PassMode::ByRef => { fx.bcx.ins().return_(&[]); @@ -521,7 +524,7 @@ pub fn codegen_return(fx: &mut FunctionCx) { } fn codegen_intrinsic_call<'a, 'tcx: 'a>( - fx: &mut FunctionCx<'a, 'tcx>, + fx: &mut FunctionCx<'a, 'tcx, impl Backend>, fn_ty: Ty<'tcx>, sig: FnSig<'tcx>, args: &[CValue<'tcx>], diff --git a/src/analyze.rs b/src/analyze.rs index cd53a810fe4..048f8812d44 100644 --- a/src/analyze.rs +++ b/src/analyze.rs @@ -8,7 +8,7 @@ pub struct Flags: u8 { } } -pub fn analyze<'a, 'tcx: 'a>(fx: &FunctionCx<'a, 'tcx>) -> HashMap { +pub fn analyze<'a, 'tcx: 'a>(fx: &FunctionCx<'a, 'tcx, impl Backend>) -> HashMap { let mut flag_map = HashMap::new(); for local in fx.mir.local_decls.indices() { diff --git a/src/base.rs b/src/base.rs index 1c14c94065c..4c91db448c7 100644 --- a/src/base.rs +++ b/src/base.rs @@ -126,7 +126,7 @@ fn verify_func(tcx: TyCtxt, writer: crate::pretty_clif::CommentWriter, func: &Fu } } -fn codegen_fn_content<'a, 'tcx: 'a>(fx: &mut FunctionCx<'a, 'tcx>) { +fn codegen_fn_content<'a, 'tcx: 'a>(fx: &mut FunctionCx<'a, 'tcx, impl Backend>) { for (bb, bb_data) in fx.mir.basic_blocks().iter_enumerated() { let ebb = fx.get_ebb(bb); fx.bcx.switch_to_block(ebb); @@ -225,7 +225,11 @@ fn codegen_fn_content<'a, 'tcx: 'a>(fx: &mut FunctionCx<'a, 'tcx>) { fx.bcx.finalize(); } -fn trans_stmt<'a, 'tcx: 'a>(fx: &mut FunctionCx<'a, 'tcx>, cur_ebb: Ebb, stmt: &Statement<'tcx>) { +fn trans_stmt<'a, 'tcx: 'a>( + fx: &mut FunctionCx<'a, 'tcx, impl Backend>, + cur_ebb: Ebb, + stmt: &Statement<'tcx>, +) { fx.tcx.sess.warn(&format!("stmt {:?}", stmt)); let inst = fx.bcx.func.layout.last_inst(cur_ebb).unwrap(); @@ -504,7 +508,7 @@ fn trans_stmt<'a, 'tcx: 'a>(fx: &mut FunctionCx<'a, 'tcx>, cur_ebb: Ebb, stmt: & } pub fn trans_get_discriminant<'a, 'tcx: 'a>( - fx: &mut FunctionCx<'a, 'tcx>, + fx: &mut FunctionCx<'a, 'tcx, impl Backend>, value: CValue<'tcx>, dest_layout: TyLayout<'tcx>, ) -> CValue<'tcx> { @@ -630,7 +634,7 @@ macro_rules! binop_match { } fn trans_bool_binop<'a, 'tcx: 'a>( - fx: &mut FunctionCx<'a, 'tcx>, + fx: &mut FunctionCx<'a, 'tcx, impl Backend>, bin_op: BinOp, lhs: CValue<'tcx>, rhs: CValue<'tcx>, @@ -663,7 +667,7 @@ fn trans_bool_binop<'a, 'tcx: 'a>( } pub fn trans_int_binop<'a, 'tcx: 'a>( - fx: &mut FunctionCx<'a, 'tcx>, + fx: &mut FunctionCx<'a, 'tcx, impl Backend>, bin_op: BinOp, lhs: CValue<'tcx>, rhs: CValue<'tcx>, @@ -709,7 +713,7 @@ pub fn trans_int_binop<'a, 'tcx: 'a>( } pub fn trans_checked_int_binop<'a, 'tcx: 'a>( - fx: &mut FunctionCx<'a, 'tcx>, + fx: &mut FunctionCx<'a, 'tcx, impl Backend>, bin_op: BinOp, lhs: CValue<'tcx>, rhs: CValue<'tcx>, @@ -771,7 +775,7 @@ pub fn trans_checked_int_binop<'a, 'tcx: 'a>( } fn trans_float_binop<'a, 'tcx: 'a>( - fx: &mut FunctionCx<'a, 'tcx>, + fx: &mut FunctionCx<'a, 'tcx, impl Backend>, bin_op: BinOp, lhs: CValue<'tcx>, rhs: CValue<'tcx>, @@ -812,7 +816,7 @@ fn trans_float_binop<'a, 'tcx: 'a>( } fn trans_char_binop<'a, 'tcx: 'a>( - fx: &mut FunctionCx<'a, 'tcx>, + fx: &mut FunctionCx<'a, 'tcx, impl Backend>, bin_op: BinOp, lhs: CValue<'tcx>, rhs: CValue<'tcx>, @@ -845,7 +849,7 @@ fn trans_char_binop<'a, 'tcx: 'a>( } fn trans_ptr_binop<'a, 'tcx: 'a>( - fx: &mut FunctionCx<'a, 'tcx>, + fx: &mut FunctionCx<'a, 'tcx, impl Backend>, bin_op: BinOp, lhs: CValue<'tcx>, rhs: CValue<'tcx>, @@ -884,7 +888,7 @@ fn trans_ptr_binop<'a, 'tcx: 'a>( } pub fn trans_place<'a, 'tcx: 'a>( - fx: &mut FunctionCx<'a, 'tcx>, + fx: &mut FunctionCx<'a, 'tcx, impl Backend>, place: &Place<'tcx>, ) -> CPlace<'tcx> { match place { @@ -937,7 +941,7 @@ pub fn trans_place<'a, 'tcx: 'a>( } pub fn trans_operand<'a, 'tcx>( - fx: &mut FunctionCx<'a, 'tcx>, + fx: &mut FunctionCx<'a, 'tcx, impl Backend>, operand: &Operand<'tcx>, ) -> CValue<'tcx> { match operand { diff --git a/src/common.rs b/src/common.rs index dc9023eda4f..e0c66218ba2 100644 --- a/src/common.rs +++ b/src/common.rs @@ -62,7 +62,7 @@ pub fn cton_type_from_ty<'a, 'tcx: 'a>( } fn codegen_field<'a, 'tcx: 'a>( - fx: &mut FunctionCx<'a, 'tcx>, + fx: &mut FunctionCx<'a, 'tcx, impl Backend>, base: Value, layout: TyLayout<'tcx>, field: mir::Field, @@ -92,7 +92,7 @@ pub fn layout(&self) -> TyLayout<'tcx> { } } - pub fn force_stack<'a>(self, fx: &mut FunctionCx<'a, 'tcx>) -> Value + pub fn force_stack<'a>(self, fx: &mut FunctionCx<'a, 'tcx, impl Backend>) -> Value where 'tcx: 'a, { @@ -114,7 +114,7 @@ pub fn force_stack<'a>(self, fx: &mut FunctionCx<'a, 'tcx>) -> Value } } - pub fn load_value<'a>(self, fx: &mut FunctionCx<'a, 'tcx>) -> Value + pub fn load_value<'a>(self, fx: &mut FunctionCx<'a, 'tcx, impl Backend>) -> Value where 'tcx: 'a, { @@ -138,7 +138,11 @@ pub fn expect_byref(self) -> (Value, TyLayout<'tcx>) { } } - pub fn value_field<'a>(self, fx: &mut FunctionCx<'a, 'tcx>, field: mir::Field) -> CValue<'tcx> + pub fn value_field<'a>( + self, + fx: &mut FunctionCx<'a, 'tcx, impl Backend>, + field: mir::Field, + ) -> CValue<'tcx> where 'tcx: 'a, { @@ -152,7 +156,7 @@ pub fn value_field<'a>(self, fx: &mut FunctionCx<'a, 'tcx>, field: mir::Field) - } pub fn const_val<'a>( - fx: &mut FunctionCx<'a, 'tcx>, + fx: &mut FunctionCx<'a, 'tcx, impl Backend>, ty: Ty<'tcx>, const_val: i64, ) -> CValue<'tcx> @@ -187,7 +191,7 @@ pub fn layout(&self) -> TyLayout<'tcx> { } } - pub fn temp(fx: &mut FunctionCx<'a, 'tcx>, ty: Ty<'tcx>) -> CPlace<'tcx> { + pub fn temp(fx: &mut FunctionCx<'a, 'tcx, impl Backend>, ty: Ty<'tcx>) -> CPlace<'tcx> { let layout = fx.layout_of(ty); let stack_slot = fx.bcx.create_stack_slot(StackSlotData { kind: StackSlotKind::ExplicitSlot, @@ -198,7 +202,7 @@ pub fn temp(fx: &mut FunctionCx<'a, 'tcx>, ty: Ty<'tcx>) -> CPlace<'tcx> { } pub fn from_stack_slot( - fx: &mut FunctionCx<'a, 'tcx>, + fx: &mut FunctionCx<'a, 'tcx, impl Backend>, stack_slot: StackSlot, ty: Ty<'tcx>, ) -> CPlace<'tcx> { @@ -206,7 +210,7 @@ pub fn from_stack_slot( CPlace::Addr(fx.bcx.ins().stack_addr(types::I64, stack_slot, 0), layout) } - pub fn to_cvalue(self, fx: &mut FunctionCx<'a, 'tcx>) -> CValue<'tcx> { + pub fn to_cvalue(self, fx: &mut FunctionCx<'a, 'tcx, impl Backend>) -> CValue<'tcx> { match self { CPlace::Var(var, layout) => CValue::ByVal(fx.bcx.use_var(var), layout), CPlace::Addr(addr, layout) => CValue::ByRef(addr, layout), @@ -220,7 +224,7 @@ pub fn expect_addr(self) -> Value { } } - pub fn write_cvalue(self, fx: &mut FunctionCx<'a, 'tcx>, from: CValue<'tcx>) { + pub fn write_cvalue(self, fx: &mut FunctionCx<'a, 'tcx, impl Backend>, from: CValue<'tcx>) { match (&self.layout().ty.sty, &from.layout().ty.sty) { (TypeVariants::TyRef(_, t, dest_mut), TypeVariants::TyRef(_, u, src_mut)) if (if *dest_mut != ::rustc::hir::Mutability::MutImmutable && src_mut != dest_mut { @@ -289,7 +293,11 @@ pub fn write_cvalue(self, fx: &mut FunctionCx<'a, 'tcx>, from: CValue<'tcx>) { } } - pub fn place_field(self, fx: &mut FunctionCx<'a, 'tcx>, field: mir::Field) -> CPlace<'tcx> { + pub fn place_field( + self, + fx: &mut FunctionCx<'a, 'tcx, impl Backend>, + field: mir::Field, + ) -> CPlace<'tcx> { let base = self.expect_addr(); let layout = self.layout(); @@ -297,7 +305,11 @@ pub fn place_field(self, fx: &mut FunctionCx<'a, 'tcx>, field: mir::Field) -> CP CPlace::Addr(field_ptr, field_layout) } - pub fn place_index(self, fx: &mut FunctionCx<'a, 'tcx>, index: Value) -> CPlace<'tcx> { + pub fn place_index( + self, + fx: &mut FunctionCx<'a, 'tcx, impl Backend>, + index: Value, + ) -> CPlace<'tcx> { let addr = self.expect_addr(); let layout = self.layout(); match layout.ty.sty { @@ -322,14 +334,14 @@ pub fn unchecked_cast_to(self, layout: TyLayout<'tcx>) -> Self { } } - pub fn downcast_variant(self, fx: &FunctionCx<'a, 'tcx>, variant: usize) -> Self { + pub fn downcast_variant(self, fx: &FunctionCx<'a, 'tcx, impl Backend>, variant: usize) -> Self { let layout = self.layout().for_variant(fx, variant); self.unchecked_cast_to(layout) } } pub fn cton_intcast<'a, 'tcx: 'a>( - fx: &mut FunctionCx<'a, 'tcx>, + fx: &mut FunctionCx<'a, 'tcx, impl Backend>, val: Value, to: Type, signed: bool, @@ -349,9 +361,9 @@ pub fn cton_intcast<'a, 'tcx: 'a>( } } -pub struct FunctionCx<'a, 'tcx: 'a> { +pub struct FunctionCx<'a, 'tcx: 'a, B: Backend + 'a> { pub tcx: TyCtxt<'a, 'tcx, 'tcx>, - pub module: &'a mut Module, + pub module: &'a mut Module, pub instance: Instance<'tcx>, pub mir: &'tcx Mir<'tcx>, pub param_substs: &'tcx Substs<'tcx>, @@ -362,7 +374,7 @@ pub struct FunctionCx<'a, 'tcx: 'a> { pub constants: &'a mut crate::constant::ConstantCx, } -impl<'a, 'tcx: 'a> fmt::Debug for FunctionCx<'a, 'tcx> { +impl<'a, 'tcx: 'a, B: Backend + 'a> fmt::Debug for FunctionCx<'a, 'tcx, B> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { writeln!(f, "{:?}", self.param_substs)?; writeln!(f, "{:?}", self.local_map)?; @@ -379,7 +391,7 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { } } -impl<'a, 'tcx: 'a> LayoutOf for &'a FunctionCx<'a, 'tcx> { +impl<'a, 'tcx: 'a, B: Backend> LayoutOf for &'a FunctionCx<'a, 'tcx, B> { type Ty = Ty<'tcx>; type TyLayout = TyLayout<'tcx>; @@ -389,25 +401,25 @@ fn layout_of(self, ty: Ty<'tcx>) -> TyLayout<'tcx> { } } -impl<'a, 'tcx> layout::HasTyCtxt<'tcx> for &'a FunctionCx<'a, 'tcx> { +impl<'a, 'tcx, B: Backend + 'a> layout::HasTyCtxt<'tcx> for &'a FunctionCx<'a, 'tcx, B> { fn tcx<'b>(&'b self) -> TyCtxt<'b, 'tcx, 'tcx> { self.tcx } } -impl<'a, 'tcx> layout::HasDataLayout for &'a FunctionCx<'a, 'tcx> { +impl<'a, 'tcx, B: Backend + 'a> layout::HasDataLayout for &'a FunctionCx<'a, 'tcx, B> { fn data_layout(&self) -> &layout::TargetDataLayout { &self.tcx.data_layout } } -impl<'a, 'tcx> HasTargetSpec for &'a FunctionCx<'a, 'tcx> { +impl<'a, 'tcx, B: Backend + 'a> HasTargetSpec for &'a FunctionCx<'a, 'tcx, B> { fn target_spec(&self) -> &Target { &self.tcx.sess.target.target } } -impl<'a, 'tcx: 'a> FunctionCx<'a, 'tcx> { +impl<'a, 'tcx: 'a, B: Backend + 'a> FunctionCx<'a, 'tcx, B> { pub fn monomorphize(&self, value: &T) -> T where T: TypeFoldable<'tcx>, diff --git a/src/constant.rs b/src/constant.rs index 868bf2a8181..d745386e758 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -37,7 +37,7 @@ pub fn codegen_static<'a, 'tcx: 'a>(ccx: &mut ConstantCx, def_id: DefId) { } pub fn codegen_static_ref<'a, 'tcx: 'a>( - fx: &mut FunctionCx<'a, 'tcx>, + fx: &mut FunctionCx<'a, 'tcx, impl Backend>, static_: &Static<'tcx>, ) -> CPlace<'tcx> { let data_id = data_id_for_static(fx.tcx, fx.module, static_.def_id); @@ -45,7 +45,7 @@ pub fn codegen_static_ref<'a, 'tcx: 'a>( } pub fn trans_promoted<'a, 'tcx: 'a>( - fx: &mut FunctionCx<'a, 'tcx>, + fx: &mut FunctionCx<'a, 'tcx, impl Backend>, promoted: Promoted, ) -> CPlace<'tcx> { let const_ = fx @@ -60,7 +60,7 @@ pub fn trans_promoted<'a, 'tcx: 'a>( } pub fn trans_constant<'a, 'tcx: 'a>( - fx: &mut FunctionCx<'a, 'tcx>, + fx: &mut FunctionCx<'a, 'tcx, impl Backend>, constant: &Constant<'tcx>, ) -> CValue<'tcx> { let const_ = fx.monomorphize(&constant.literal); @@ -69,7 +69,7 @@ pub fn trans_constant<'a, 'tcx: 'a>( } fn force_eval_const<'a, 'tcx: 'a>( - fx: &FunctionCx<'a, 'tcx>, + fx: &FunctionCx<'a, 'tcx, impl Backend>, const_: &'tcx Const<'tcx>, ) -> &'tcx Const<'tcx> { match const_.val { @@ -87,7 +87,7 @@ fn force_eval_const<'a, 'tcx: 'a>( } fn trans_const_value<'a, 'tcx: 'a>( - fx: &mut FunctionCx<'a, 'tcx>, + fx: &mut FunctionCx<'a, 'tcx, impl Backend>, const_: &'tcx Const<'tcx>, ) -> CValue<'tcx> { let ty = fx.monomorphize(&const_.ty); @@ -114,7 +114,7 @@ fn trans_const_value<'a, 'tcx: 'a>( } fn trans_const_place<'a, 'tcx: 'a>( - fx: &mut FunctionCx<'a, 'tcx>, + fx: &mut FunctionCx<'a, 'tcx, impl Backend>, const_: &'tcx Const<'tcx>, ) -> CPlace<'tcx> { let alloc = fx.tcx.const_value_to_allocation(const_); @@ -139,7 +139,7 @@ fn data_id_for_static(tcx: TyCtxt, module: &mut Module, def_id: D } fn cplace_for_dataid<'a, 'tcx: 'a>( - fx: &mut FunctionCx<'a, 'tcx>, + fx: &mut FunctionCx<'a, 'tcx, impl Backend>, ty: Ty<'tcx>, data_id: DataId, ) -> CPlace<'tcx> { diff --git a/src/pretty_clif.rs b/src/pretty_clif.rs index 51c17037561..d872a70b0fe 100644 --- a/src/pretty_clif.rs +++ b/src/pretty_clif.rs @@ -34,7 +34,7 @@ fn write_preamble( } } -impl<'a, 'tcx: 'a> FunctionCx<'a, 'tcx> { +impl<'a, 'tcx: 'a, B: Backend + 'a> FunctionCx<'a, 'tcx, B> { pub fn add_comment<'s, S: Into>>(&mut self, inst: Inst, comment: S) { use std::collections::hash_map::Entry; match self.comments.entry(inst) {