diff options
| author | Ralf Jung <post@ralfj.de> | 2020-03-14 11:12:32 +0100 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2020-03-14 11:12:32 +0100 |
| commit | 62087439a46f09b6a6716fc25b4a032f3d76eb71 (patch) | |
| tree | f54786cd6a319fdcfc6083412717aa2f4d08b117 /src | |
| parent | 5ed3453af9db9c516e564e25ba9ee28056d48103 (diff) | |
| download | rust-62087439a46f09b6a6716fc25b4a032f3d76eb71.tar.gz rust-62087439a46f09b6a6716fc25b4a032f3d76eb71.zip | |
add Scalar::from methods for signed integers
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc/mir/interpret/value.rs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/librustc/mir/interpret/value.rs b/src/librustc/mir/interpret/value.rs index 9dc0b24cd2f..1e630c96dd4 100644 --- a/src/librustc/mir/interpret/value.rs +++ b/src/librustc/mir/interpret/value.rs @@ -272,11 +272,13 @@ impl<'tcx, Tag> Scalar<Tag> { #[inline] pub fn from_bool(b: bool) -> Self { + // Guaranteed to be truncated and does not need sign extension. Scalar::Raw { data: b as u128, size: 1 } } #[inline] pub fn from_char(c: char) -> Self { + // Guaranteed to be truncated and does not need sign extension. Scalar::Raw { data: c as u128, size: 4 } } @@ -299,21 +301,25 @@ impl<'tcx, Tag> Scalar<Tag> { #[inline] pub fn from_u8(i: u8) -> Self { + // Guaranteed to be truncated and does not need sign extension. Scalar::Raw { data: i as u128, size: 1 } } #[inline] pub fn from_u16(i: u16) -> Self { + // Guaranteed to be truncated and does not need sign extension. Scalar::Raw { data: i as u128, size: 2 } } #[inline] pub fn from_u32(i: u32) -> Self { + // Guaranteed to be truncated and does not need sign extension. Scalar::Raw { data: i as u128, size: 4 } } #[inline] pub fn from_u64(i: u64) -> Self { + // Guaranteed to be truncated and does not need sign extension. Scalar::Raw { data: i as u128, size: 8 } } @@ -342,6 +348,26 @@ impl<'tcx, Tag> Scalar<Tag> { } #[inline] + pub fn from_i8(i: i8) -> Self { + Self::from_int(i, Size::from_bits(8)) + } + + #[inline] + pub fn from_i16(i: i16) -> Self { + Self::from_int(i, Size::from_bits(16)) + } + + #[inline] + pub fn from_i32(i: i32) -> Self { + Self::from_int(i, Size::from_bits(32)) + } + + #[inline] + pub fn from_i64(i: i64) -> Self { + Self::from_int(i, Size::from_bits(64)) + } + + #[inline] pub fn from_machine_isize(i: i64, cx: &impl HasDataLayout) -> Self { Self::from_int(i, cx.data_layout().pointer_size) } |
