Add instruction visitor, which traverses memory and choosing instructions

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2020-02-10 13:22:54 -05:00
parent c982be553f
commit 6c352396fa
5 changed files with 287 additions and 128 deletions

View File

@@ -1,4 +1,4 @@
use crate::vm::{error::*, flags::*, mem::*, obj::obj::*, reg::*};
use crate::vm::{error::*, flags::*, inst::InstOp, mem::*, obj::obj::*, reg::*};
use byteorder::{WriteBytesExt, LE};
use std::{io::Cursor, mem};
@@ -101,6 +101,11 @@ impl Vm {
Ok(self.mem_cursor(addr as usize).next_u32().unwrap())
}
pub fn get_inst_op(&self, addr: Addr) -> Result<InstOp> {
self.check_read(addr, 2)?;
Ok(self.mem_cursor(addr as usize).next_u16().unwrap())
}
pub fn get_byte(&self, addr: Addr) -> Result<u8> {
self.check_addr(addr)?;
Ok(self.mem_cursor(addr as usize).next_u8().unwrap())