Extract codegen_intrinsic_call
This commit is contained in:
parent
5629c423ff
commit
5ebcea23e4
2 changed files with 211 additions and 199 deletions
108
src/abi.rs
108
src/abi.rs
|
@ -351,10 +351,6 @@ pub fn codegen_call<'a, 'tcx: 'a>(
|
|||
let intrinsic = fx.tcx.item_name(def_id).as_str();
|
||||
let intrinsic = &intrinsic[..];
|
||||
|
||||
let nil_ty = fx.tcx.mk_nil();
|
||||
let u64_layout = fx.layout_of(fx.tcx.types.u64);
|
||||
let usize_layout = fx.layout_of(fx.tcx.types.usize);
|
||||
|
||||
let ret = match return_place {
|
||||
Some(ret) => ret,
|
||||
None => {
|
||||
|
@ -375,6 +371,66 @@ pub fn codegen_call<'a, 'tcx: 'a>(
|
|||
return;
|
||||
}
|
||||
};
|
||||
|
||||
codegen_intrinsic_call(fx, intrinsic, substs, args, ret);
|
||||
|
||||
if let Some((_, dest)) = *destination {
|
||||
let ret_ebb = fx.get_ebb(dest);
|
||||
fx.bcx.ins().jump(ret_ebb, &[]);
|
||||
} else {
|
||||
fx.bcx.ins().trap(TrapCode::User(!0));
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
let return_ptr = match return_place {
|
||||
Some(place) => place.expect_addr(),
|
||||
None => fx.bcx.ins().iconst(types::I64, 0),
|
||||
};
|
||||
|
||||
let call_args = Some(return_ptr)
|
||||
.into_iter()
|
||||
.chain(args.into_iter().map(|arg| {
|
||||
if fx.cton_type(arg.layout().ty).is_some() {
|
||||
arg.load_value(fx)
|
||||
} else {
|
||||
arg.force_stack(fx)
|
||||
}
|
||||
})).collect::<Vec<_>>();
|
||||
|
||||
match func {
|
||||
CValue::Func(func, _) => {
|
||||
fx.bcx.ins().call(func, &call_args);
|
||||
}
|
||||
func => {
|
||||
let func_ty = func.layout().ty;
|
||||
let func = func.load_value(fx);
|
||||
let sig = fx
|
||||
.bcx
|
||||
.import_signature(cton_sig_from_fn_ty(fx.tcx, func_ty));
|
||||
fx.bcx.ins().call_indirect(sig, func, &call_args);
|
||||
}
|
||||
}
|
||||
if let Some((_, dest)) = *destination {
|
||||
let ret_ebb = fx.get_ebb(dest);
|
||||
fx.bcx.ins().jump(ret_ebb, &[]);
|
||||
} else {
|
||||
fx.bcx.ins().trap(TrapCode::User(!0));
|
||||
}
|
||||
}
|
||||
|
||||
fn codegen_intrinsic_call<'a, 'tcx: 'a>(
|
||||
fx: &mut FunctionCx<'a, 'tcx>,
|
||||
intrinsic: &str,
|
||||
substs: &Substs<'tcx>,
|
||||
args: Vec<CValue<'tcx>>,
|
||||
ret: CPlace<'tcx>,
|
||||
) {
|
||||
let nil_ty = fx.tcx.mk_nil();
|
||||
let u64_layout = fx.layout_of(fx.tcx.types.u64);
|
||||
let usize_layout = fx.layout_of(fx.tcx.types.usize);
|
||||
|
||||
match intrinsic {
|
||||
"assume" => {
|
||||
assert_eq!(args.len(), 1);
|
||||
|
@ -569,48 +625,4 @@ pub fn codegen_call<'a, 'tcx: 'a>(
|
|||
}
|
||||
_ => unimpl!("unsupported intrinsic {}", intrinsic),
|
||||
}
|
||||
if let Some((_, dest)) = *destination {
|
||||
let ret_ebb = fx.get_ebb(dest);
|
||||
fx.bcx.ins().jump(ret_ebb, &[]);
|
||||
} else {
|
||||
fx.bcx.ins().trap(TrapCode::User(!0));
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
let return_ptr = match return_place {
|
||||
Some(place) => place.expect_addr(),
|
||||
None => fx.bcx.ins().iconst(types::I64, 0),
|
||||
};
|
||||
|
||||
let call_args = Some(return_ptr)
|
||||
.into_iter()
|
||||
.chain(args.into_iter().map(|arg| {
|
||||
if fx.cton_type(arg.layout().ty).is_some() {
|
||||
arg.load_value(fx)
|
||||
} else {
|
||||
arg.force_stack(fx)
|
||||
}
|
||||
})).collect::<Vec<_>>();
|
||||
|
||||
match func {
|
||||
CValue::Func(func, _) => {
|
||||
fx.bcx.ins().call(func, &call_args);
|
||||
}
|
||||
func => {
|
||||
let func_ty = func.layout().ty;
|
||||
let func = func.load_value(fx);
|
||||
let sig = fx
|
||||
.bcx
|
||||
.import_signature(cton_sig_from_fn_ty(fx.tcx, func_ty));
|
||||
fx.bcx.ins().call_indirect(sig, func, &call_args);
|
||||
}
|
||||
}
|
||||
if let Some((_, dest)) = *destination {
|
||||
let ret_ebb = fx.get_ebb(dest);
|
||||
fx.bcx.ins().jump(ret_ebb, &[]);
|
||||
} else {
|
||||
fx.bcx.ins().trap(TrapCode::User(!0));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -839,11 +839,11 @@ fn trans_ptr_binop<'a, 'tcx: 'a>(
|
|||
ty: Ty<'tcx>,
|
||||
) -> CValue<'tcx> {
|
||||
match lhs.layout().ty.sty {
|
||||
TypeVariants::TyRawPtr(TypeAndMut { ty, mutbl: _}) => {
|
||||
TypeVariants::TyRawPtr(TypeAndMut { ty, mutbl: _ }) => {
|
||||
if !ty.is_sized(fx.tcx.at(DUMMY_SP), ParamEnv::reveal_all()) {
|
||||
unimpl!("Unsized values are not yet implemented");
|
||||
}
|
||||
},
|
||||
}
|
||||
_ => bug!("trans_ptr_binop on non ptr"),
|
||||
}
|
||||
binop_match! {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue