Add alocation to smir
This commit is contained in:
parent
5cbfee5455
commit
b9a539e0a3
@ -1063,3 +1063,34 @@ fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
|
|||||||
BoundTy { var: self.var.as_usize(), kind: self.kind.stable(tables) }
|
BoundTy { var: self.var.as_usize(), kind: self.kind.stable(tables) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'tcx> Stable<'tcx> for mir::interpret::Allocation {
|
||||||
|
type T = stable_mir::ty::Allocation;
|
||||||
|
|
||||||
|
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
|
||||||
|
let size = self.size();
|
||||||
|
let mut bytes: Vec<Option<u8>> = self
|
||||||
|
.inspect_with_uninit_and_ptr_outside_interpreter(0..size.bytes_usize())
|
||||||
|
.iter()
|
||||||
|
.copied()
|
||||||
|
.map(Some)
|
||||||
|
.collect();
|
||||||
|
for (i, b) in bytes.iter_mut().enumerate() {
|
||||||
|
if !self.init_mask().get(rustc_target::abi::Size::from_bytes(i)) {
|
||||||
|
*b = None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stable_mir::ty::Allocation {
|
||||||
|
bytes: bytes,
|
||||||
|
provenance: {
|
||||||
|
let mut ptrs = Vec::new();
|
||||||
|
for (size, prov) in self.provenance().ptrs().iter() {
|
||||||
|
ptrs.push((size.bytes_usize(), opaque(prov)));
|
||||||
|
}
|
||||||
|
stable_mir::ty::ProvenanceMap { ptrs }
|
||||||
|
},
|
||||||
|
align: self.align.bytes(),
|
||||||
|
mutability: self.mutability.stable(tables),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -242,3 +242,25 @@ pub struct BoundTy {
|
|||||||
pub var: usize,
|
pub var: usize,
|
||||||
pub kind: BoundTyKind,
|
pub kind: BoundTyKind,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub type Bytes = Vec<Option<u8>>;
|
||||||
|
pub type Size = usize;
|
||||||
|
pub type Prov = Opaque;
|
||||||
|
pub type Align = u64;
|
||||||
|
pub type InitMaskMaterialized = Vec<u64>;
|
||||||
|
|
||||||
|
/// Stores the provenance information of pointers stored in memory.
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub struct ProvenanceMap {
|
||||||
|
/// Provenance in this map applies from the given offset for an entire pointer-size worth of
|
||||||
|
/// bytes. Two entries in this map are always at least a pointer size apart.
|
||||||
|
pub ptrs: Vec<(Size, Prov)>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub struct Allocation {
|
||||||
|
pub bytes: Bytes,
|
||||||
|
pub provenance: ProvenanceMap,
|
||||||
|
pub align: Align,
|
||||||
|
pub mutability: Mutability,
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user