提交 3bbf2fd7 编写于 作者: O Oliver Schneider

Remove Pointer::zero in favor of Pointer::from

上级 d7324631
......@@ -115,15 +115,18 @@ pub struct Pointer {
pub offset: Size,
}
/// Produces a `Pointer` which points to the beginning of the Allocation
impl From<AllocId> for Pointer {
fn from(alloc_id: AllocId) -> Self {
Pointer::new(alloc_id, Size::ZERO)
}
}
impl<'tcx> Pointer {
pub fn new(alloc_id: AllocId, offset: Size) -> Self {
Pointer { alloc_id, offset }
}
pub fn zero(alloc_id: AllocId) -> Self {
Pointer::new(alloc_id, Size::ZERO)
}
pub(crate) fn wrapping_signed_offset<C: HasDataLayout>(self, i: i64, cx: C) -> Self {
Pointer::new(
self.alloc_id,
......
......@@ -182,16 +182,14 @@ pub fn const_eval_literal(
LitKind::Str(ref s, _) => {
let s = s.as_str();
let id = self.tcx.allocate_bytes(s.as_bytes());
let ptr = Pointer::zero(id);
ConstValue::ScalarPair(
Scalar::Ptr(ptr),
Scalar::Ptr(id.into()),
Scalar::from_u128(s.len() as u128),
)
},
LitKind::ByteStr(ref data) => {
let id = self.tcx.allocate_bytes(data);
let ptr = Pointer::zero(id);
ConstValue::Scalar(ptr.into())
ConstValue::Scalar(Scalar::Ptr(id.into()))
},
LitKind::Byte(n) => ConstValue::Scalar(Scalar::Bytes(n as u128)),
LitKind::Int(n, _) if neg => {
......
......@@ -1128,16 +1128,14 @@ fn lit_to_const<'a, 'tcx>(lit: &'tcx ast::LitKind,
LitKind::Str(ref s, _) => {
let s = s.as_str();
let id = tcx.allocate_bytes(s.as_bytes());
let ptr = Pointer::zero(id);
ConstValue::ScalarPair(
Scalar::Ptr(ptr),
Scalar::Ptr(id.into()),
Scalar::from_u128(s.len() as u128),
)
},
LitKind::ByteStr(ref data) => {
let id = tcx.allocate_bytes(data);
let ptr = Pointer::zero(id);
ConstValue::Scalar(ptr.into())
ConstValue::Scalar(Scalar::Ptr(id.into()))
},
LitKind::Byte(n) => ConstValue::Scalar(Scalar::Bytes(n as u128)),
LitKind::Int(n, _) => {
......
......@@ -1019,8 +1019,7 @@ pub fn read_global_as_value(&mut self, gid: GlobalId<'tcx>, ty: Ty<'tcx>) -> Eva
.lock()
.intern_static(gid.instance.def_id());
let layout = self.layout_of(ty)?;
let ptr = Pointer::zero(alloc_id);
return Ok(Value::ByRef(ptr.into(), layout.align))
return Ok(Value::ByRef(Scalar::Ptr(alloc_id.into()), layout.align))
}
let cv = self.const_eval(gid)?;
self.const_to_value(&cv.val, ty)
......
......@@ -72,13 +72,11 @@ pub fn allocations<'x>(
}
pub fn create_fn_alloc(&mut self, instance: Instance<'tcx>) -> Pointer {
let id = self.tcx.alloc_map.lock().create_fn_alloc(instance);
Pointer::zero(id)
self.tcx.alloc_map.lock().create_fn_alloc(instance).into()
}
pub fn allocate_bytes(&mut self, bytes: &[u8]) -> Pointer {
let id = self.tcx.allocate_bytes(bytes);
Pointer::zero(id)
self.tcx.allocate_bytes(bytes).into()
}
/// kind is `None` for statics
......@@ -109,8 +107,7 @@ pub fn allocate(
align: Align,
kind: Option<MemoryKind<M::MemoryKinds>>,
) -> EvalResult<'tcx, Pointer> {
let id = self.allocate_value(Allocation::undef(size, align), kind)?;
Ok(Pointer::zero(id))
self.allocate_value(Allocation::undef(size, align), kind).map(Pointer::from)
}
pub fn reallocate(
......
......@@ -210,7 +210,7 @@ pub fn eval_place(&mut self, mir_place: &mir::Place<'tcx>) -> EvalResult<'tcx, P
};
let alloc = Machine::init_static(self, cid)?;
Place::Ptr {
ptr: Pointer::zero(alloc).into(),
ptr: Scalar::Ptr(alloc.into()),
align: layout.align,
extra: PlaceExtra::None,
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册