From 50722d4ee8ae2e91c26af524d785f426f7c7c619 Mon Sep 17 00:00:00 2001 From: Erin Date: Thu, 2 Nov 2023 16:53:44 +0100 Subject: [PATCH] Public accessors --- hbvm/src/lib.rs | 26 +++++++++++++++++++++++++- hbvm/src/vmrun.rs | 28 +--------------------------- 2 files changed, 26 insertions(+), 28 deletions(-) diff --git a/hbvm/src/lib.rs b/hbvm/src/lib.rs index 5b90f83..c520aea 100644 --- a/hbvm/src/lib.rs +++ b/hbvm/src/lib.rs @@ -13,7 +13,10 @@ #![no_std] #![cfg_attr(feature = "nightly", feature(fn_align))] -use mem::{Address, Memory}; +use { + mem::{Address, Memory}, + value::ValueVariant, +}; #[cfg(feature = "alloc")] extern crate alloc; @@ -66,6 +69,27 @@ where copier: None, } } + + /// Read register + #[inline(always)] + pub fn read_reg(&self, n: u8) -> Value { + unsafe { *self.registers.get_unchecked(n as usize) } + } + + /// Write a register. + /// Writing to register 0 is no-op. + #[inline(always)] + pub fn write_reg(&mut self, n: u8, value: T) { + if n != 0 { + unsafe { + core::ptr::copy_nonoverlapping( + (&value as *const T).cast::(), + self.registers.as_mut_ptr().add(n.into()).cast::(), + core::mem::size_of::(), + ); + }; + } + } } /// Virtual machine halt error diff --git a/hbvm/src/vmrun.rs b/hbvm/src/vmrun.rs index 13bcbc3..152a992 100644 --- a/hbvm/src/vmrun.rs +++ b/hbvm/src/vmrun.rs @@ -3,12 +3,7 @@ //! Have fun use { - super::{ - bmc::BlockCopier, - mem::Memory, - value::{Value, ValueVariant}, - Vm, VmRunError, VmRunOk, - }, + super::{bmc::BlockCopier, mem::Memory, value::ValueVariant, Vm, VmRunError, VmRunOk}, crate::{ mem::{addr::AddressOp, Address}, value::CheckedDivRem, @@ -534,27 +529,6 @@ where } } - /// Read register - #[inline(always)] - fn read_reg(&self, n: u8) -> Value { - unsafe { *self.registers.get_unchecked(n as usize) } - } - - /// Write a register. - /// Writing to register 0 is no-op. - #[inline(always)] - fn write_reg(&mut self, n: u8, value: T) { - if n != 0 { - unsafe { - core::ptr::copy_nonoverlapping( - (&value as *const T).cast::(), - self.registers.as_mut_ptr().add(n.into()).cast::(), - core::mem::size_of::(), - ); - }; - } - } - /// Load / Store Address check-computation überfunction #[inline(always)] unsafe fn ldst_addr_uber(