Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: shrink OpCodeInfo and add more methods #1307

Merged
merged 4 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions crates/interpreter/src/interpreter/analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ pub fn validate_eof_code(
return Err(EofValidationError::UnknownOpcode);
};

if !opcode.is_eof {
if opcode.is_disabled_in_eof() {
// Opcode is disabled in EOF
return Err(EofValidationError::OpcodeDisabled);
}
Expand All @@ -324,26 +324,26 @@ pub fn validate_eof_code(
// opcode after termination was not accessed.
return Err(EofValidationError::InstructionNotForwardAccessed);
}
is_after_termination = opcode.is_terminating_opcode;
is_after_termination = opcode.is_terminating();

// mark immediate as non-jumpable. RJUMPV is special case covered later.
if opcode.immediate_size != 0 {
if opcode.immediate_size() != 0 {
// check if the opcode immediate are within the bounds of the code
if i + opcode.immediate_size as usize >= code.len() {
if i + opcode.immediate_size() as usize >= code.len() {
// Malfunctional code
return Err(EofValidationError::MissingImmediateBytes);
}

// mark immediate bytes as non-jumpable.
for imm in 1..opcode.immediate_size as usize + 1 {
for imm in 1..opcode.immediate_size() as usize + 1 {
// SAFETY: immediate size is checked above.
jumps[i + imm].mark_as_immediate()?;
}
}
// IO diff used to generate next instruction smallest/biggest value.
let mut stack_io_diff = opcode.io_diff() as i32;
// how many stack items are required for this opcode.
let mut stack_requirement = opcode.inputs as i32;
let mut stack_requirement = opcode.inputs() as i32;
// additional immediate bytes for RJUMPV, it has dynamic vtable.
let mut rjumpv_additional_immediates = 0;
// If opcodes is RJUMP, RJUMPI or RJUMPV then this will have absolute jumpdest.
Expand Down Expand Up @@ -534,7 +534,7 @@ pub fn validate_eof_code(
}

// additional immediate are from RJUMPV vtable.
i += 1 + opcode.immediate_size as usize + rjumpv_additional_immediates;
i += 1 + opcode.immediate_size() as usize + rjumpv_additional_immediates;
}

// last opcode should be terminating
Expand Down
Loading
Loading