Skip to content

Commit 415ecc8

Browse files
committed
Add Scalar::to_(u|i)16 methods
1 parent 7bc1665 commit 415ecc8

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/librustc/mir/interpret/value.rs

+13
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,12 @@ impl<'tcx, Tag> Scalar<Tag> {
421421
Ok(b as u8)
422422
}
423423

424+
pub fn to_u16(self) -> InterpResult<'static, u16> {
425+
let sz = Size::from_bits(16);
426+
let b = self.to_bits(sz)?;
427+
Ok(b as u16)
428+
}
429+
424430
pub fn to_u32(self) -> InterpResult<'static, u32> {
425431
let sz = Size::from_bits(32);
426432
let b = self.to_bits(sz)?;
@@ -445,6 +451,13 @@ impl<'tcx, Tag> Scalar<Tag> {
445451
Ok(b as i8)
446452
}
447453

454+
pub fn to_i16(self) -> InterpResult<'static, i16> {
455+
let sz = Size::from_bits(16);
456+
let b = self.to_bits(sz)?;
457+
let b = sign_extend(b, sz) as i128;
458+
Ok(b as i16)
459+
}
460+
448461
pub fn to_i32(self) -> InterpResult<'static, i32> {
449462
let sz = Size::from_bits(32);
450463
let b = self.to_bits(sz)?;

0 commit comments

Comments
 (0)