From 2c84906d774b6bb1062e9ff6d42d73a4185ccc72 Mon Sep 17 00:00:00 2001 From: Chris Fallin Date: Mon, 17 Apr 2023 16:01:54 -0700 Subject: [PATCH] Better interpreter error results --- src/interp.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/interp.rs b/src/interp.rs index 49ab317..5c68687 100644 --- a/src/interp.rs +++ b/src/interp.rs @@ -26,7 +26,7 @@ type MultiVal = SmallVec<[ConstVal; 2]>; pub enum InterpResult { Ok(MultiVal), Exit, - Trap, + Trap(Func, Block, u32), OutOfFuel, TraceHandlerQuit, } @@ -127,7 +127,7 @@ impl InterpContext { } log::trace!("Interpreting block {}", frame.cur_block); - for &inst in &body.blocks[frame.cur_block].insts { + for (inst_idx, &inst) in body.blocks[frame.cur_block].insts.iter().enumerate() { log::trace!("Evaluating inst {}", inst); let result = match &body.values[inst] { &ValueDef::Alias(_) => smallvec![], @@ -191,7 +191,11 @@ impl InterpContext { Some(result) => result, None => { log::trace!("const_eval failed on {:?} args {:?}", op, args); - return InterpResult::Trap; + return InterpResult::Trap( + frame.func, + frame.cur_block, + inst_idx as u32, + ); } }; smallvec![result] @@ -227,8 +231,12 @@ impl InterpContext { } match &body.blocks[frame.cur_block].terminator { - &Terminator::None => return InterpResult::Trap, - &Terminator::Unreachable => return InterpResult::Trap, + &Terminator::None => { + return InterpResult::Trap(frame.func, frame.cur_block, u32::MAX) + } + &Terminator::Unreachable => { + return InterpResult::Trap(frame.func, frame.cur_block, u32::MAX) + } &Terminator::Br { ref target } => { frame.apply_target(body, target); }