Cleanup the diff

This commit is contained in:
Oliver Schneider 2017-03-29 09:10:05 +02:00
parent 065e9593b4
commit fdeee8fb59

View File

@ -28,6 +28,7 @@ pub(super) fn call_intrinsic(
let usize = self.tcx.types.usize;
let f32 = self.tcx.types.f32;
let f64 = self.tcx.types.f64;
let substs = instance.substs;
let intrinsic_name = &self.tcx.item_name(instance.def_id()).as_str()[..];
match intrinsic_name {
@ -58,7 +59,7 @@ pub(super) fn call_intrinsic(
"atomic_load_relaxed" |
"atomic_load_acq" |
"volatile_load" => {
let ty = instance.substs.type_at(0);
let ty = substs.type_at(0);
let ptr = arg_vals[0].read_ptr(&self.memory)?;
self.write_value(Value::ByRef(ptr), dest, ty)?;
}
@ -67,7 +68,7 @@ pub(super) fn call_intrinsic(
"atomic_store_relaxed" |
"atomic_store_rel" |
"volatile_store" => {
let ty = instance.substs.type_at(0);
let ty = substs.type_at(0);
let dest = arg_vals[0].read_ptr(&self.memory)?;
self.write_value_to_ptr(arg_vals[1], dest, ty)?;
}
@ -77,7 +78,7 @@ pub(super) fn call_intrinsic(
}
_ if intrinsic_name.starts_with("atomic_xchg") => {
let ty = instance.substs.type_at(0);
let ty = substs.type_at(0);
let ptr = arg_vals[0].read_ptr(&self.memory)?;
let change = self.value_to_primval(arg_vals[1], ty)?;
let old = self.read_value(ptr, ty)?;
@ -91,7 +92,7 @@ pub(super) fn call_intrinsic(
}
_ if intrinsic_name.starts_with("atomic_cxchg") => {
let ty = instance.substs.type_at(0);
let ty = substs.type_at(0);
let ptr = arg_vals[0].read_ptr(&self.memory)?;
let expect_old = self.value_to_primval(arg_vals[1], ty)?;
let change = self.value_to_primval(arg_vals[2], ty)?;
@ -113,7 +114,7 @@ pub(super) fn call_intrinsic(
"atomic_and" | "atomic_and_acq" | "atomic_and_rel" | "atomic_and_acqrel" | "atomic_and_relaxed" |
"atomic_xadd" | "atomic_xadd_acq" | "atomic_xadd_rel" | "atomic_xadd_acqrel" | "atomic_xadd_relaxed" |
"atomic_xsub" | "atomic_xsub_acq" | "atomic_xsub_rel" | "atomic_xsub_acqrel" | "atomic_xsub_relaxed" => {
let ty = instance.substs.type_at(0);
let ty = substs.type_at(0);
let ptr = arg_vals[0].read_ptr(&self.memory)?;
let change = self.value_to_primval(arg_vals[1], ty)?;
let old = self.read_value(ptr, ty)?;
@ -142,7 +143,7 @@ pub(super) fn call_intrinsic(
"copy" |
"copy_nonoverlapping" => {
// FIXME: check whether overlapping occurs
let elem_ty = instance.substs.type_at(0);
let elem_ty = substs.type_at(0);
let elem_size = self.type_size(elem_ty)?.expect("cannot copy unsized value");
let elem_align = self.type_align(elem_ty)?;
let src = arg_vals[0].read_ptr(&self.memory)?;
@ -155,7 +156,7 @@ pub(super) fn call_intrinsic(
"cttz" |
"ctlz" |
"bswap" => {
let ty = instance.substs.type_at(0);
let ty = substs.type_at(0);
let num = self.value_to_primval(arg_vals[0], ty)?;
let kind = self.ty_to_primval_kind(ty)?;
let num = numeric_intrinsic(intrinsic_name, num, kind)?;
@ -163,7 +164,7 @@ pub(super) fn call_intrinsic(
}
"discriminant_value" => {
let ty = instance.substs.type_at(0);
let ty = substs.type_at(0);
let adt_ptr = arg_vals[0].read_ptr(&self.memory)?;
let discr_val = self.read_discriminant_value(adt_ptr, ty)?;
self.write_primval(dest, PrimVal::Bytes(discr_val), dest_ty)?;
@ -216,7 +217,7 @@ pub(super) fn call_intrinsic(
}
"fadd_fast" | "fsub_fast" | "fmul_fast" | "fdiv_fast" | "frem_fast" => {
let ty = instance.substs.type_at(0);
let ty = substs.type_at(0);
let kind = self.ty_to_primval_kind(ty)?;
let a = self.value_to_primval(arg_vals[0], ty)?;
let b = self.value_to_primval(arg_vals[1], ty)?;
@ -248,7 +249,7 @@ pub(super) fn call_intrinsic(
Value::ByVal(PrimVal::Undef) => match this.ty_to_primval_kind(dest_ty) {
Ok(_) => Value::ByVal(PrimVal::Bytes(0)),
Err(_) => {
let ptr = this.alloc_ptr_with_substs(dest_ty, instance.substs)?;
let ptr = this.alloc_ptr_with_substs(dest_ty, substs)?;
this.memory.write_repeat(ptr, 0, size)?;
Value::ByRef(ptr)
}
@ -268,14 +269,14 @@ pub(super) fn call_intrinsic(
}
"min_align_of" => {
let elem_ty = instance.substs.type_at(0);
let elem_ty = substs.type_at(0);
let elem_align = self.type_align(elem_ty)?;
let align_val = PrimVal::from_u128(elem_align as u128);
self.write_primval(dest, align_val, dest_ty)?;
}
"pref_align_of" => {
let ty = instance.substs.type_at(0);
let ty = substs.type_at(0);
let layout = self.type_layout(ty)?;
let align = layout.align(&self.tcx.data_layout).pref();
let align_val = PrimVal::from_u128(align as u128);
@ -283,20 +284,20 @@ pub(super) fn call_intrinsic(
}
"move_val_init" => {
let ty = instance.substs.type_at(0);
let ty = substs.type_at(0);
let ptr = arg_vals[0].read_ptr(&self.memory)?;
self.write_value_to_ptr(arg_vals[1], ptr, ty)?;
}
"needs_drop" => {
let ty = instance.substs.type_at(0);
let ty = substs.type_at(0);
let env = self.tcx.empty_parameter_environment();
let needs_drop = self.tcx.type_needs_drop_given_env(ty, &env);
self.write_primval(dest, PrimVal::from_bool(needs_drop), dest_ty)?;
}
"offset" => {
let pointee_ty = instance.substs.type_at(0);
let pointee_ty = substs.type_at(0);
// FIXME: assuming here that type size is < i64::max_value()
let pointee_size = self.type_size(pointee_ty)?.expect("cannot offset a pointer to an unsized type") as i64;
let offset = self.value_to_primval(arg_vals[1], isize)?.to_i128()? as i64;
@ -357,7 +358,7 @@ pub(super) fn call_intrinsic(
}
"size_of" => {
let ty = instance.substs.type_at(0);
let ty = substs.type_at(0);
// FIXME: change the `box_free` lang item to take `T: ?Sized` and have it use the
// `size_of_val` intrinsic, then change this back to
// .expect("size_of intrinsic called on unsized value")
@ -367,32 +368,32 @@ pub(super) fn call_intrinsic(
}
"size_of_val" => {
let ty = instance.substs.type_at(0);
let ty = substs.type_at(0);
let (size, _) = self.size_and_align_of_dst(ty, arg_vals[0])?;
self.write_primval(dest, PrimVal::from_u128(size as u128), dest_ty)?;
}
"min_align_of_val" |
"align_of_val" => {
let ty = instance.substs.type_at(0);
let ty = substs.type_at(0);
let (_, align) = self.size_and_align_of_dst(ty, arg_vals[0])?;
self.write_primval(dest, PrimVal::from_u128(align as u128), dest_ty)?;
}
"type_name" => {
let ty = instance.substs.type_at(0);
let ty = substs.type_at(0);
let ty_name = ty.to_string();
let s = self.str_to_value(&ty_name)?;
self.write_value(s, dest, dest_ty)?;
}
"type_id" => {
let ty = instance.substs.type_at(0);
let ty = substs.type_at(0);
let n = self.tcx.type_id_hash(ty);
self.write_primval(dest, PrimVal::Bytes(n as u128), dest_ty)?;
}
"transmute" => {
let dest_ty = instance.substs.type_at(1);
let dest_ty = substs.type_at(1);
self.write_value(arg_vals[0], dest, dest_ty)?;
}
@ -418,7 +419,7 @@ pub(super) fn call_intrinsic(
"write_bytes" => {
let u8 = self.tcx.types.u8;
let ty = instance.substs.type_at(0);
let ty = substs.type_at(0);
let ty_align = self.type_align(ty)?;
let val_byte = self.value_to_primval(arg_vals[1], u8)?.to_u128()? as u8;
let size = self.type_size(ty)?.expect("write_bytes() type must be sized");