mirror of
https://github.com/fluencelabs/parity-wasm
synced 2025-06-27 13:41:58 +00:00
removed extra instruction outcomes
This commit is contained in:
@ -49,16 +49,10 @@ pub struct FunctionContext<'a> {
|
|||||||
/// Interpreter action to execute after executing instruction.
|
/// Interpreter action to execute after executing instruction.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum InstructionOutcome<'a> {
|
pub enum InstructionOutcome<'a> {
|
||||||
/// Continue with current instruction.
|
|
||||||
RunInstruction,
|
|
||||||
/// Continue with next instruction.
|
/// Continue with next instruction.
|
||||||
RunNextInstruction,
|
RunNextInstruction,
|
||||||
/// Branch to given frame.
|
/// Branch to given frame.
|
||||||
Branch(usize),
|
Branch(usize),
|
||||||
/// Skip if-false (aka else) branch.
|
|
||||||
SkipIfFalse,
|
|
||||||
/// Run if-false (aka else) branch (if any).
|
|
||||||
RunIfFalse,
|
|
||||||
/// Execute function call.
|
/// Execute function call.
|
||||||
ExecuteCall(InternalFunctionReference<'a>),
|
ExecuteCall(InternalFunctionReference<'a>),
|
||||||
/// End current frame.
|
/// End current frame.
|
||||||
@ -130,7 +124,6 @@ impl Interpreter {
|
|||||||
|
|
||||||
debug!(target: "interpreter", "running {:?}", instruction);
|
debug!(target: "interpreter", "running {:?}", instruction);
|
||||||
match Interpreter::run_instruction(function_context, instruction)? {
|
match Interpreter::run_instruction(function_context, instruction)? {
|
||||||
InstructionOutcome::RunInstruction => (),
|
|
||||||
InstructionOutcome::RunNextInstruction => function_context.position += 1,
|
InstructionOutcome::RunNextInstruction => function_context.position += 1,
|
||||||
InstructionOutcome::Branch(mut index) => {
|
InstructionOutcome::Branch(mut index) => {
|
||||||
// discard index - 1 blocks
|
// discard index - 1 blocks
|
||||||
@ -144,40 +137,6 @@ impl Interpreter {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
InstructionOutcome::SkipIfFalse => {
|
|
||||||
// skip until else/end is found
|
|
||||||
let mut block_count = 1;
|
|
||||||
loop {
|
|
||||||
function_context.position += 1;
|
|
||||||
debug_assert!(function_context.position < function_body.len());
|
|
||||||
|
|
||||||
let instruction = &function_body[function_context.position];
|
|
||||||
match instruction {
|
|
||||||
&Opcode::End if block_count == 1 => break,
|
|
||||||
&Opcode::Block(_) | &Opcode::Loop(_) | &Opcode::If(_) => block_count += 1,
|
|
||||||
&Opcode::End => block_count -= 1,
|
|
||||||
_ => (),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
function_context.position += 1;
|
|
||||||
},
|
|
||||||
InstructionOutcome::RunIfFalse => {
|
|
||||||
// skip until else/end is found
|
|
||||||
let mut block_count = 1;
|
|
||||||
loop {
|
|
||||||
function_context.position += 1;
|
|
||||||
debug_assert!(function_context.position < function_body.len());
|
|
||||||
|
|
||||||
let instruction = &function_body[function_context.position];
|
|
||||||
match instruction {
|
|
||||||
&Opcode::End | &Opcode::Else if block_count == 1 => break,
|
|
||||||
&Opcode::Block(_) | &Opcode::Loop(_) | &Opcode::If(_) => block_count += 1,
|
|
||||||
&Opcode::End => block_count -= 1,
|
|
||||||
_ => (),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
function_context.position += 1;
|
|
||||||
},
|
|
||||||
InstructionOutcome::ExecuteCall(func_ref) => {
|
InstructionOutcome::ExecuteCall(func_ref) => {
|
||||||
function_context.position += 1;
|
function_context.position += 1;
|
||||||
return Ok(RunResult::NestedCall(function_context.nested(func_ref)?));
|
return Ok(RunResult::NestedCall(function_context.nested(func_ref)?));
|
||||||
@ -186,8 +145,6 @@ impl Interpreter {
|
|||||||
if function_context.frame_stack().is_empty() {
|
if function_context.frame_stack().is_empty() {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
//function_context.position += 1;
|
|
||||||
},
|
},
|
||||||
InstructionOutcome::Return => break,
|
InstructionOutcome::Return => break,
|
||||||
}
|
}
|
||||||
@ -423,18 +380,14 @@ impl Interpreter {
|
|||||||
context.position = else_pos;
|
context.position = else_pos;
|
||||||
BlockFrameType::IfFalse
|
BlockFrameType::IfFalse
|
||||||
};
|
};
|
||||||
context.push_frame(block_frame_type, block_type)?;
|
context.push_frame(block_frame_type, block_type).map(|_| InstructionOutcome::RunNextInstruction)
|
||||||
|
|
||||||
//if branch {
|
|
||||||
Ok(InstructionOutcome::RunNextInstruction)
|
|
||||||
/*} else {
|
|
||||||
Ok(InstructionOutcome::RunIfFalse)
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_else<'a>(context: &mut FunctionContext) -> Result<InstructionOutcome<'a>, Error> {
|
fn run_else<'a>(context: &mut FunctionContext) -> Result<InstructionOutcome<'a>, Error> {
|
||||||
|
let end_pos = context.function_labels[&context.position];
|
||||||
context.pop_frame(false)?;
|
context.pop_frame(false)?;
|
||||||
Ok(InstructionOutcome::SkipIfFalse)
|
context.position = end_pos;
|
||||||
|
Ok(InstructionOutcome::RunNextInstruction)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_end<'a>(context: &mut FunctionContext) -> Result<InstructionOutcome<'a>, Error> {
|
fn run_end<'a>(context: &mut FunctionContext) -> Result<InstructionOutcome<'a>, Error> {
|
||||||
|
@ -114,7 +114,7 @@ impl Validator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn validate_instruction<'a>(context: &mut FunctionValidationContext, opcode: &'a Opcode) -> Result<InstructionOutcome, Error> {
|
fn validate_instruction<'a>(context: &mut FunctionValidationContext, opcode: &'a Opcode) -> Result<InstructionOutcome, Error> {
|
||||||
debug!(target: "validator", "validating {:?}", opcode);
|
debug!(target: "validator", "validating {:?}", opcode);
|
||||||
match opcode {
|
match opcode {
|
||||||
&Opcode::Unreachable => Ok(InstructionOutcome::Unreachable),
|
&Opcode::Unreachable => Ok(InstructionOutcome::Unreachable),
|
||||||
|
Reference in New Issue
Block a user