Rollup merge of #105602 - RalfJung:read-convenience, r=oli-obk

interpret: add read_machine_[ui]size convenience methods

We have `read_pointer`, so it felt inconsistent to not also have these.

r? ```@oli-obk```
This commit is contained in:
Yuki Okushi 2022-12-22 08:32:10 +09:00 committed by GitHub
commit 4f29ca386f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 71 additions and 60 deletions

View file

@ -404,6 +404,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
Ok(self.read_immediate(op)?.to_scalar())
}
// Pointer-sized reads are fairly common and need target layout access, so we wrap them in
// convenience functions.
/// Read a pointer from a place.
pub fn read_pointer(
&self,
@ -411,6 +414,14 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
) -> InterpResult<'tcx, Pointer<Option<M::Provenance>>> {
self.read_scalar(op)?.to_pointer(self)
}
/// Read a pointer-sized unsigned integer from a place.
pub fn read_machine_usize(&self, op: &OpTy<'tcx, M::Provenance>) -> InterpResult<'tcx, u64> {
self.read_scalar(op)?.to_machine_usize(self)
}
/// Read a pointer-sized signed integer from a place.
pub fn read_machine_isize(&self, op: &OpTy<'tcx, M::Provenance>) -> InterpResult<'tcx, i64> {
self.read_scalar(op)?.to_machine_isize(self)
}
/// Turn the wide MPlace into a string (must already be dereferenced!)
pub fn read_str(&self, mplace: &MPlaceTy<'tcx, M::Provenance>) -> InterpResult<'tcx, &str> {