Remove CValue::Func

This commit is contained in:
bjorn3 2018-08-19 10:50:39 +02:00
parent 72f48776a1
commit 8a1c86473c
3 changed files with 13 additions and 14 deletions

View File

@ -472,9 +472,15 @@ pub fn codegen_call<'a, 'tcx: 'a>(
}
})).collect::<Vec<_>>();
let inst = match trans_operand(fx, func) {
CValue::Func(func, _) => fx.bcx.ins().call(func, &call_args),
func => {
let call_inst = match fn_ty.sty {
TypeVariants::TyFnDef(def_id, substs) => {
let func_ref = fx.get_function_ref(
Instance::resolve(fx.tcx, ParamEnv::reveal_all(), def_id, substs).unwrap(),
);
fx.bcx.ins().call(func_ref, &call_args)
}
_ => {
let func = trans_operand(fx, func);
let func = func.load_value(fx);
let sig = fx.bcx.import_signature(cton_sig_from_fn_ty(fx.tcx, fn_ty));
fx.bcx.ins().call_indirect(sig, func, &call_args)
@ -485,7 +491,7 @@ pub fn codegen_call<'a, 'tcx: 'a>(
PassMode::NoPass => {}
PassMode::ByVal(_) => {
if let Some((ret_place, _)) = destination {
let results = fx.bcx.inst_results(inst);
let results = fx.bcx.inst_results(call_inst);
ret_place.write_cvalue(fx, CValue::ByVal(results[0], ret_layout));
}
}

View File

@ -71,13 +71,12 @@ fn codegen_field<'a, 'tcx: 'a>(
pub enum CValue<'tcx> {
ByRef(Value, TyLayout<'tcx>),
ByVal(Value, TyLayout<'tcx>),
Func(FuncRef, TyLayout<'tcx>),
}
impl<'tcx> CValue<'tcx> {
pub fn layout(&self) -> TyLayout<'tcx> {
match *self {
CValue::ByRef(_, layout) | CValue::ByVal(_, layout) | CValue::Func(_, layout) => layout,
CValue::ByRef(_, layout) | CValue::ByVal(_, layout) => layout,
}
}
@ -96,10 +95,6 @@ impl<'tcx> CValue<'tcx> {
fx.bcx.ins().stack_store(value, stack_slot, 0);
fx.bcx.ins().stack_addr(types::I64, stack_slot, 0)
}
CValue::Func(func, ty) => {
let func = fx.bcx.ins().func_addr(types::I64, func);
CValue::ByVal(func, ty).force_stack(fx)
}
}
}
@ -115,7 +110,6 @@ impl<'tcx> CValue<'tcx> {
fx.bcx.ins().load(cton_ty, MemFlags::new(), addr, 0)
}
CValue::ByVal(value, _layout) => value,
CValue::Func(func, _layout) => fx.bcx.ins().func_addr(types::I64, func),
}
}
@ -123,7 +117,6 @@ impl<'tcx> CValue<'tcx> {
match self {
CValue::ByRef(value, layout) => (value, layout),
CValue::ByVal(_, _) => bug!("Expected CValue::ByRef, found CValue::ByVal: {:?}", self),
CValue::Func(_, _) => bug!("Expected CValue::ByRef, found CValue::Func: {:?}", self),
}
}
@ -161,7 +154,6 @@ impl<'tcx> CValue<'tcx> {
match self {
CValue::ByRef(addr, _) => CValue::ByRef(addr, layout),
CValue::ByVal(val, _) => CValue::ByVal(val, layout),
CValue::Func(fun, _) => CValue::Func(fun, layout),
}
}
}

View File

@ -109,7 +109,8 @@ fn trans_const_value<'a, 'tcx: 'a>(
let func_ref = fx.get_function_ref(
Instance::resolve(fx.tcx, ParamEnv::reveal_all(), def_id, substs).unwrap(),
);
CValue::Func(func_ref, layout)
let func_addr = fx.bcx.ins().func_addr(types::I64, func_ref);
CValue::ByVal(func_addr, layout)
}
_ => trans_const_place(fx, const_).to_cvalue(fx),
}