store full TargetDataLayout in Memory instead of just pointer size
This commit is contained in:
parent
b33a9f3431
commit
055b6a8d38
4 changed files with 11 additions and 15 deletions
|
@ -16,7 +16,7 @@ pub enum EvalError<'tcx> {
|
|||
PointerOutOfBounds {
|
||||
ptr: Pointer,
|
||||
size: usize,
|
||||
allocation_size: usize,
|
||||
allocation_size: u64,
|
||||
},
|
||||
ReadPointerAsBytes,
|
||||
ReadBytesAsPointer,
|
||||
|
|
|
@ -35,7 +35,7 @@ pub struct EvalContext<'a, 'tcx: 'a> {
|
|||
mir_cache: RefCell<DefIdMap<Rc<mir::Mir<'tcx>>>>,
|
||||
|
||||
/// The virtual memory system.
|
||||
memory: Memory<'tcx>,
|
||||
memory: Memory<'a, 'tcx>,
|
||||
|
||||
/// Precomputed statics, constants and promoteds.
|
||||
statics: HashMap<ConstantId<'tcx>, Pointer>,
|
||||
|
@ -138,11 +138,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
|
|||
tcx: tcx,
|
||||
mir_map: mir_map,
|
||||
mir_cache: RefCell::new(DefIdMap()),
|
||||
memory: Memory::new(tcx.sess
|
||||
.target
|
||||
.uint_type
|
||||
.bit_width()
|
||||
.expect("Session::target::uint_type was usize")/8),
|
||||
memory: Memory::new(&tcx.data_layout),
|
||||
statics: HashMap::new(),
|
||||
stack: Vec::new(),
|
||||
}
|
||||
|
@ -162,7 +158,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
|
|||
&self.memory
|
||||
}
|
||||
|
||||
pub fn memory_mut(&mut self) -> &mut Memory<'tcx> {
|
||||
pub fn memory_mut(&mut self) -> &mut Memory<'a, 'tcx> {
|
||||
&mut self.memory
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ use std::{fmt, iter, mem, ptr};
|
|||
use rustc::hir::def_id::DefId;
|
||||
use rustc::ty::BareFnTy;
|
||||
use rustc::ty::subst::Substs;
|
||||
use rustc::ty::layout::{Size, TargetDataLayout};
|
||||
|
||||
use error::{EvalError, EvalResult};
|
||||
use primval::PrimVal;
|
||||
|
@ -53,7 +54,7 @@ pub struct FunctionDefinition<'tcx> {
|
|||
// Top-level interpreter memory
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
pub struct Memory<'tcx> {
|
||||
pub struct Memory<'a, 'tcx> {
|
||||
/// Actual memory allocations (arbitrary bytes, may contain pointers into other allocations)
|
||||
alloc_map: HashMap<AllocId, Allocation>,
|
||||
/// Function "allocations". They exist solely so pointers have something to point to, and
|
||||
|
@ -62,18 +63,17 @@ pub struct Memory<'tcx> {
|
|||
/// Inverse map of `functions` so we don't allocate a new pointer every time we need one
|
||||
function_alloc_cache: HashMap<FunctionDefinition<'tcx>, AllocId>,
|
||||
next_id: AllocId,
|
||||
pub pointer_size: usize,
|
||||
pub layout: &'a TargetDataLayout,
|
||||
}
|
||||
|
||||
impl<'tcx> Memory<'tcx> {
|
||||
// FIXME: pass tcx.data_layout (This would also allow it to use primitive type alignments to diagnose unaligned memory accesses.)
|
||||
pub fn new(pointer_size: usize) -> Self {
|
||||
impl<'a, 'tcx> Memory<'a, 'tcx> {
|
||||
pub fn new(layout: &'a TargetDataLayout) -> Self {
|
||||
Memory {
|
||||
alloc_map: HashMap::new(),
|
||||
functions: HashMap::new(),
|
||||
function_alloc_cache: HashMap::new(),
|
||||
next_id: AllocId(0),
|
||||
pointer_size: pointer_size,
|
||||
layout: layout,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -77,7 +77,7 @@ fn compile_test() {
|
|||
match cmd.output() {
|
||||
Ok(ref output) if output.status.success() => writeln!(stderr.lock(), "ok").unwrap(),
|
||||
Ok(output) => {
|
||||
writeln!(stderr.lock(), "FAILED with exit code {}", output.status.code().unwrap_or(0)).unwrap();
|
||||
writeln!(stderr.lock(), "FAILED with exit code {:?}", output.status.code()).unwrap();
|
||||
writeln!(stderr.lock(), "stdout: \n {}", std::str::from_utf8(&output.stdout).unwrap()).unwrap();
|
||||
writeln!(stderr.lock(), "stderr: \n {}", std::str::from_utf8(&output.stderr).unwrap()).unwrap();
|
||||
panic!("some tests failed");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue