jsmoo
Nick Krichevsky 2022-04-06 22:47:38 -04:00
parent 8734a7fc8e
commit ad62658980
3 changed files with 6 additions and 1 deletions

View File

@ -19,9 +19,13 @@ pub(super) type ParseResult<'a> = Result<(RunnableInstruction, &'a [u8]), Error>
/// `OpcodeParser` takes input data, parses out an opcode (and its associated arguments) if it can, and returns
/// the remaining data after reading it.
trait OpcodeParser {
/// Parse an opcode and all of its data from the given data buffer. Returns either an error, or
/// The parsed instruction, and a slice of all the data after the instruction
fn parse_opcode(data: &[u8]) -> ParseResult;
}
/// `next_instruction` will parse the next instruction from the given data stream. Returns either an error,
/// or the parsed instruction, and a slice of all the data after the instruction
pub fn next_instruction(data: &[u8]) -> ParseResult {
let parse_funcs = &[
load8::immediate::Immediate8BitLoadParser::parse_opcode,

View File

@ -9,6 +9,7 @@ use crate::run::{
pub struct Immediate8BitLoadParser;
impl OpcodeParser for Immediate8BitLoadParser {
/// Parses an opcode that will transfer an immediate 8 bit value into a single register.
fn parse_opcode(data: &[u8]) -> ParseResult {
let opcode = parse::get_opcode_from_data(data)?;

View File

@ -22,7 +22,7 @@ macro_rules! match_opcode {
}
impl OpcodeParser for Between8BitRegisterParser {
#[allow(clippy::too_many_lines)]
/// Parses an opcode that transfers an 8bit values between single registers.
fn parse_opcode(data: &[u8]) -> ParseResult {
let opcode = parse::get_opcode_from_data(data)?;
match_opcode!(