Skip to content

Commit

Permalink
provide a way to replace the tag in a Scalar/MemPlace
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Dec 3, 2018
1 parent d2c19e0 commit 005df5f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/librustc/mir/interpret/value.rs
Expand Up @@ -138,6 +138,14 @@ impl<'tcx, Tag> Scalar<Tag> {
}
}

#[inline]
pub fn with_tag(self, new_tag: Tag) -> Self {
match self {
Scalar::Ptr(ptr) => Scalar::Ptr(Pointer { tag: new_tag, ..ptr }),
Scalar::Bits { bits, size } => Scalar::Bits { bits, size },
}
}

#[inline]
pub fn ptr_null(cx: &impl HasDataLayout) -> Self {
Scalar::Bits {
Expand Down
20 changes: 20 additions & 0 deletions src/librustc_mir/interpret/place.rs
Expand Up @@ -115,6 +115,16 @@ impl<Tag> MemPlace<Tag> {
}
}

#[inline]
pub fn with_tag(self, new_tag: Tag) -> Self
{
MemPlace {
ptr: self.ptr.with_tag(new_tag),
align: self.align,
meta: self.meta,
}
}

#[inline(always)]
pub fn from_scalar_ptr(ptr: Scalar<Tag>, align: Align) -> Self {
MemPlace {
Expand Down Expand Up @@ -187,6 +197,16 @@ impl<'tcx, Tag> MPlaceTy<'tcx, Tag> {
}
}

#[inline]
pub fn with_tag(self, new_tag: Tag) -> Self
{
MPlaceTy {
mplace: self.mplace.with_tag(new_tag),
layout: self.layout,
}
}

#[inline]
pub fn offset(
self,
offset: Size,
Expand Down

0 comments on commit 005df5f

Please sign in to comment.