Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Scalar::to_(u|i)16 methods #67604

Merged
merged 2 commits into from
Dec 28, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/librustc/mir/interpret/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,12 @@ impl<'tcx, Tag> Scalar<Tag> {
Ok(b as u8)
}

pub fn to_u16(self) -> InterpResult<'static, u16> {
pvdrz marked this conversation as resolved.
Show resolved Hide resolved
let sz = Size::from_bits(16);
let b = self.to_bits(sz)?;
Ok(b as u16)
}

pub fn to_u32(self) -> InterpResult<'static, u32> {
let sz = Size::from_bits(32);
let b = self.to_bits(sz)?;
Expand All @@ -445,6 +451,13 @@ impl<'tcx, Tag> Scalar<Tag> {
Ok(b as i8)
}

pub fn to_i16(self) -> InterpResult<'static, i16> {
Centril marked this conversation as resolved.
Show resolved Hide resolved
let sz = Size::from_bits(16);
let b = self.to_bits(sz)?;
let b = sign_extend(b, sz) as i128;
Ok(b as i16)
}

pvdrz marked this conversation as resolved.
Show resolved Hide resolved
pub fn to_i32(self) -> InterpResult<'static, i32> {
let sz = Size::from_bits(32);
let b = self.to_bits(sz)?;
Expand Down