Struct lc3_ensemble::sim::mem::Mem

source ·
pub struct Mem { /* private fields */ }
Expand description

Memory. This can be addressed with any u16.

Implementations§

source§

impl Mem

source

pub fn new(strat: &mut WordCreateStrategy) -> Self

Creates a new memory with a provided word creation strategy.

source

pub fn copy_obj_block(&mut self, start: u16, data: &[Option<u16>])

Copies an object file block into this memory.

source

pub fn get_raw(&self, addr: u16) -> &Word

Gets a reference to a word from the memory’s current state.

This is only meant to be used to query the state of the memory, not to simulate a read from memory.

Note the differences from Mem::read:

  • This function does not trigger IO effects (and as a result, IO values will not be updated).
  • This function does not require MemAccessCtx.
  • This function does not perform access violation checks.

If any of these effects are necessary (e.g., when trying to execute instructions from the simulator), Mem::read should be used instead.

source

pub fn get_raw_mut(&mut self, addr: u16) -> &mut Word

Gets a mutable reference to a word from the memory’s current state.

This is only meant to be used to query/edit the state of the memory, not to simulate a write from memory.

Note the differences from Mem::write:

  • This function does not trigger IO effects (and as a result, IO values will not be updated).
  • This function does not require MemAccessCtx.
  • This function does not perform access violation checks or strict uninitialized memory checking.

If any of these effects are necessary (e.g., when trying to execute instructions from the simulator), Mem::write should be used instead.

source

pub fn read(&mut self, addr: u16, ctx: MemAccessCtx) -> Result<Word, SimErr>

Fallibly reads the word at the provided index, erroring if not possible.

This accepts a MemAccessCtx, that describes the parameters of the memory access. The simulator provides a default MemAccessCtx under super::Simulator::default_mem_ctx.

The flags are used as follows:

  • privileged: if false, this access errors if the address is a memory location outside of the user range.
  • strict: not used for read

Note that this method is used for simulating a read. If you would like to query the memory’s state, consider Mem::get_raw.

source

pub fn write( &mut self, addr: u16, data: Word, ctx: MemAccessCtx ) -> Result<(), SimErr>

Fallibly writes the word at the provided index, erroring if not possible.

This accepts a MemAccessCtx, that describes the parameters of the memory access. The simulator provides a default MemAccessCtx under super::Simulator::default_mem_ctx.

The flags are used as follows:

  • privileged: if false, this access errors if the address is a memory location outside of the user range.
  • strict: If true, all accesses that would cause a memory location to be set with uninitialized data causes an error.

Note that this method is used for simulating a write. If you would like to edit the memory’s state, consider Mem::get_raw_mut.

Trait Implementations§

source§

impl Debug for Mem

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Mem

§

impl !RefUnwindSafe for Mem

§

impl Send for Mem

§

impl Sync for Mem

§

impl Unpin for Mem

§

impl !UnwindSafe for Mem

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V