mirror of
https://github.com/rust-lang/rust.git
synced 2024-10-31 22:41:50 +00:00
Implement some intrinsics
This commit is contained in:
parent
dc4f234115
commit
812fd6daca
@ -147,3 +147,7 @@ fn eq_char(a: char, b: char) -> bool {
|
||||
unsafe fn transmute(c: char) -> u32 {
|
||||
intrinsics::transmute(c)
|
||||
}
|
||||
|
||||
unsafe fn call_uninit() -> u8 {
|
||||
intrinsics::uninit()
|
||||
}
|
||||
|
@ -118,5 +118,6 @@ pub mod intrinsics {
|
||||
pub fn size_of<T>() -> usize;
|
||||
pub fn copy<T>(src: *const T, dst: *mut T, count: usize);
|
||||
pub fn transmute<T, U>(e: T) -> U;
|
||||
pub fn uninit<T>() -> T;
|
||||
}
|
||||
}
|
||||
|
29
src/abi.rs
29
src/abi.rs
@ -252,6 +252,9 @@ pub fn codegen_call<'a, 'tcx: 'a>(
|
||||
let usize_layout = fx.layout_of(fx.tcx.types.usize);
|
||||
let ret = return_place.unwrap();
|
||||
match intrinsic {
|
||||
"abort" => {
|
||||
fx.bcx.ins().trap(TrapCode::User(!0 - 1));
|
||||
}
|
||||
"copy" | "copy_nonoverlapping" => {
|
||||
/*let elem_ty = substs.type_at(0);
|
||||
assert_eq!(args.len(), 3);
|
||||
@ -266,6 +269,18 @@ pub fn codegen_call<'a, 'tcx: 'a>(
|
||||
let size_of = CValue::const_val(fx, usize_layout.ty, size_of as i64);
|
||||
ret.write_cvalue(fx, size_of);
|
||||
}
|
||||
"type_id" => {
|
||||
assert_eq!(args.len(), 0);
|
||||
let type_id = fx.tcx.type_id_hash(substs.type_at(0));
|
||||
let type_id = CValue::const_val(fx, usize_layout.ty, type_id as i64);
|
||||
ret.write_cvalue(fx, type_id);
|
||||
}
|
||||
"min_align_of" => {
|
||||
assert_eq!(args.len(), 0);
|
||||
let min_align = fx.layout_of(substs.type_at(0)).align.abi();
|
||||
let min_align = CValue::const_val(fx, usize_layout.ty, min_align as i64);
|
||||
ret.write_cvalue(fx, min_align);
|
||||
}
|
||||
_ if intrinsic.starts_with("unchecked_") => {
|
||||
assert_eq!(args.len(), 2);
|
||||
let lhs = args[0].load_value(fx);
|
||||
@ -304,6 +319,20 @@ pub fn codegen_call<'a, 'tcx: 'a>(
|
||||
let dst_layout = fx.layout_of(dst_ty);
|
||||
ret.write_cvalue(fx, CValue::ByRef(addr, dst_layout))
|
||||
}
|
||||
"uninit" => {
|
||||
assert_eq!(args.len(), 0);
|
||||
let ty = substs.type_at(0);
|
||||
let layout = fx.layout_of(ty);
|
||||
let stack_slot = fx.bcx.create_stack_slot(StackSlotData {
|
||||
kind: StackSlotKind::ExplicitSlot,
|
||||
size: layout.size.bytes() as u32,
|
||||
offset: None,
|
||||
});
|
||||
|
||||
let uninit_place = CPlace::from_stack_slot(fx, stack_slot, ty);
|
||||
let uninit_val = uninit_place.to_cvalue(fx);
|
||||
ret.write_cvalue(fx, uninit_val);
|
||||
}
|
||||
_ => fx.tcx.sess.fatal(&format!("unsupported intrinsic {}", intrinsic)),
|
||||
}
|
||||
if let Some((_, dest)) = *destination {
|
||||
|
@ -501,7 +501,7 @@ pub fn trans_int_binop<'a, 'tcx: 'a>(fx: &mut FunctionCx<'a, 'tcx>, bin_op: BinO
|
||||
|
||||
fn trans_float_binop<'a, 'tcx: 'a>(fx: &mut FunctionCx<'a, 'tcx>, bin_op: BinOp, lhs: Value, rhs: Value, ty: Ty<'tcx>) -> CValue<'tcx> {
|
||||
let res = binop_match! {
|
||||
fx, bin_op, false, lhs, rhs, "bool";
|
||||
fx, bin_op, false, lhs, rhs, "float";
|
||||
Add (_) fadd;
|
||||
Sub (_) fsub;
|
||||
Mul (_) fmul;
|
||||
|
Loading…
Reference in New Issue
Block a user