1
Fork 0

add method to obtain the ptr offset of a Scalar

This commit is contained in:
Ralf Jung 2018-11-05 15:11:28 +01:00
parent a0074cafb1
commit 7b7c6ceb75

View file

@ -202,6 +202,19 @@ impl<'tcx, Tag> Scalar<Tag> {
}
}
/// Returns this pointers offset from the allocation base, or from NULL (for
/// integer pointers).
#[inline]
pub fn get_ptr_offset(self, cx: &impl HasDataLayout) -> Size {
match self {
Scalar::Bits { bits, size } => {
assert_eq!(size as u64, cx.pointer_size().bytes());
Size::from_bytes(bits as u64)
}
Scalar::Ptr(ptr) => ptr.offset,
}
}
#[inline]
pub fn is_null_ptr(self, cx: &impl HasDataLayout) -> bool {
match self {