From 16f778ad207650c0c9f4e049953f5dda2c48ec12 Mon Sep 17 00:00:00 2001 From: Scott Olson Date: Tue, 14 Jun 2016 20:13:59 -0600 Subject: [PATCH] Rename next_block to block and reorganize Frame fields. --- src/bin/miri.rs | 2 +- src/interpreter/mod.rs | 51 ++++++++++++++++++++++++-------------- src/interpreter/stepper.rs | 4 +-- 3 files changed, 35 insertions(+), 22 deletions(-) diff --git a/src/bin/miri.rs b/src/bin/miri.rs index a29e44cf960..2d6cf22d589 100644 --- a/src/bin/miri.rs +++ b/src/bin/miri.rs @@ -90,7 +90,7 @@ fn interpret_start_points<'a, 'tcx>( fn report(tcx: TyCtxt, ecx: &EvalContext, e: EvalError) { let frame = ecx.stack().last().expect("stackframe was empty"); - let block = &frame.mir.basic_blocks()[frame.next_block]; + let block = &frame.mir.basic_blocks()[frame.block]; let span = if frame.stmt < block.statements.len() { block.statements[frame.stmt].source_info.span } else { diff --git a/src/interpreter/mod.rs b/src/interpreter/mod.rs index 1b0b416e0e1..8b69fc6c248 100644 --- a/src/interpreter/mod.rs +++ b/src/interpreter/mod.rs @@ -42,7 +42,7 @@ pub struct EvalContext<'a, 'tcx: 'a> { /// The virtual memory system. memory: Memory<'tcx>, - /// Precomputed statics, constants and promoteds + /// Precomputed statics, constants and promoteds. statics: HashMap, Pointer>, /// The virtual call stack. @@ -51,20 +51,25 @@ pub struct EvalContext<'a, 'tcx: 'a> { /// A stack frame. pub struct Frame<'a, 'tcx: 'a> { - /// The def_id of the current function - pub def_id: DefId, + //////////////////////////////////////////////////////////////////////////////// + // Function and callsite information + //////////////////////////////////////////////////////////////////////////////// - /// The span of the call site - pub span: codemap::Span, + /// The MIR for the function called on this frame. + pub mir: CachedMir<'a, 'tcx>, + + /// The def_id of the current function. + pub def_id: DefId, - /// type substitutions for the current function invocation + /// type substitutions for the current function invocation. pub substs: &'tcx Substs<'tcx>, - /// The MIR for the function called on this frame. - pub mir: CachedMir<'a, 'tcx>, + /// The span of the call site. + pub span: codemap::Span, - /// The block that is currently executed (or will be executed after the above call stacks return) - pub next_block: mir::BasicBlock, + //////////////////////////////////////////////////////////////////////////////// + // Return pointer and local allocations + //////////////////////////////////////////////////////////////////////////////// /// A pointer for writing the return value of the current call if it's not a diverging call. pub return_ptr: Option, @@ -80,7 +85,15 @@ pub struct Frame<'a, 'tcx: 'a> { /// The offset of the first temporary in `self.locals`. pub temp_offset: usize, - /// The index of the currently evaluated statment + //////////////////////////////////////////////////////////////////////////////// + // Current position within the function + //////////////////////////////////////////////////////////////////////////////// + + /// The block that is currently executed (or will be executed after the above call stacks + /// return). + pub block: mir::BasicBlock, + + /// The index of the currently evaluated statment. pub stmt: usize, } @@ -349,7 +362,7 @@ pub fn push_stack_frame(&mut self, def_id: DefId, span: codemap::Span, mir: Cach self.stack.push(Frame { mir: mir.clone(), - next_block: mir::START_BLOCK, + block: mir::START_BLOCK, return_ptr: return_ptr, locals: locals, var_offset: num_args, @@ -374,13 +387,13 @@ fn eval_terminator(&mut self, terminator: &mir::Terminator<'tcx>) Return => self.pop_stack_frame(), Goto { target } => { - self.frame_mut().next_block = target; + self.frame_mut().block = target; }, If { ref cond, targets: (then_target, else_target) } => { let cond_ptr = self.eval_operand(cond)?; let cond_val = self.memory.read_bool(cond_ptr)?; - self.frame_mut().next_block = if cond_val { then_target } else { else_target }; + self.frame_mut().block = if cond_val { then_target } else { else_target }; } SwitchInt { ref discr, ref values, ref targets, .. } => { @@ -403,7 +416,7 @@ fn eval_terminator(&mut self, terminator: &mir::Terminator<'tcx>) } } - self.frame_mut().next_block = target_block; + self.frame_mut().block = target_block; } Switch { ref discr, ref targets, adt_def } => { @@ -415,7 +428,7 @@ fn eval_terminator(&mut self, terminator: &mir::Terminator<'tcx>) match matching { Some(i) => { - self.frame_mut().next_block = targets[i]; + self.frame_mut().block = targets[i]; }, None => return Err(EvalError::InvalidDiscriminant), } @@ -424,7 +437,7 @@ fn eval_terminator(&mut self, terminator: &mir::Terminator<'tcx>) Call { ref func, ref args, ref destination, .. } => { let mut return_ptr = None; if let Some((ref lv, target)) = *destination { - self.frame_mut().next_block = target; + self.frame_mut().block = target; return_ptr = Some(self.eval_lvalue(lv)?.to_ptr()); } @@ -451,14 +464,14 @@ fn eval_terminator(&mut self, terminator: &mir::Terminator<'tcx>) let ptr = self.eval_lvalue(location)?.to_ptr(); let ty = self.lvalue_ty(location); self.drop(ptr, ty)?; - self.frame_mut().next_block = target; + self.frame_mut().block = target; } Assert { ref cond, expected, ref msg, target, cleanup } => { let actual_ptr = self.eval_operand(cond)?; let actual = self.memory.read_bool(actual_ptr)?; if actual == expected { - self.frame_mut().next_block = target; + self.frame_mut().block = target; } else { panic!("unimplemented: jump to {:?} and print {:?}", cleanup, msg); } diff --git a/src/interpreter/stepper.rs b/src/interpreter/stepper.rs index 8603054d124..e92ddd1faa2 100644 --- a/src/interpreter/stepper.rs +++ b/src/interpreter/stepper.rs @@ -37,7 +37,7 @@ fn terminator(&mut self, terminator: &mir::Terminator<'tcx>) -> EvalResult<()> { trace!("{:?}", terminator.kind); self.ecx.eval_terminator(terminator)?; if !self.ecx.stack.is_empty() { - trace!("// {:?}", self.ecx.frame().next_block); + trace!("// {:?}", self.ecx.frame().block); } Ok(()) } @@ -48,7 +48,7 @@ pub(super) fn step(&mut self) -> EvalResult { return Ok(false); } - let block = self.ecx.frame().next_block; + let block = self.ecx.frame().block; let stmt = self.ecx.frame().stmt; let mir = self.ecx.mir(); let basic_block = &mir.basic_blocks()[block]; -- 2.44.0