Struct lc3_ensemble::sim::mem::Word

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

A memory location that can be read and written to.

§Reading

A word’s value can be read with Word::get to return its representation as an unsigned integer.

This can be converted to a signed integer with typical as casting (data as i16).

§Writing

A word can be written into with a value or with another word.

Word::copy_word may be more useful in situations where initialization state may want to be preserved. See the respective functions for more details.

Words can also be written to by applying assign operations (e.g., add, sub, and, etc.). All arithmetic operations that can be applied to words are assumed to be wrapping. See those implementations for more details.

§Initialization

Internally, each memory location keeps track of two fields:

  1. its data (i.e., the value stored at this location)
  2. which bits of its data are truly “initialized” (as in the program knows what values are present there)

This second field is not used except for when the simulator is set to strict mode. Then, this second field is leveraged to detect if uninitialized memory is being written to places it shouldn’t be (e.g., PC, addresses, registers and memory).

When a Word is created for memory/register files (i.e., via Word::new_uninit), it is created with the initialization bits set to fully uninitialized. The data associated with this Word is decided by the creation strategy (see WordCreateStrategy for details).

Implementations§

source§

impl Word

source

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

Creates a new word that is considered uninitialized.

source

pub fn new_init(data: u16) -> Self

Creates a new word that is initialized with a given data value.

source

pub fn get(&self) -> u16

Reads the word, returning its unsigned representation.

source

pub fn is_init(&self) -> bool

Checks that a word is fully initialized

source

pub fn clear_init(&mut self)

Clears initialization of this word.

source

pub fn set(&mut self, data: u16)

Writes to the word.

The data provided is assumed to be FULLY initialized, and will set the initialization state of this word to be fully initialized.

If the data is not fully initialized (e.g., if it is a partially initialized word), Word::copy_word can be used instead.

source

pub fn copy_word( &mut self, word: Word, strict: bool, err: SimErr ) -> Result<(), SimErr>

Copies the data from one word into another.

This function is more cognizant of word initialization than Word::set.

  • In non-strict mode, this function preserves the initialization data of the given word.
  • In strict mode, this function verifies the word copied is fully initialized, raising the provided error if not.

Trait Implementations§

source§

impl Add for Word

source§

fn add(self, rhs: Self) -> Self::Output

Adds two words together (wrapping if overflow occurs).

If the two words are fully initialized, the resulting word will also be fully initialized. Otherwise, the resulting word is fully uninitialized.

§

type Output = Word

The resulting type after applying the + operator.
source§

impl AddAssign<i16> for Word

source§

fn add_assign(&mut self, rhs: i16)

Increments the word by the provided value.

If the word was fully initialized, its updated value is also fully initialized. Otherwise, the resulting word is fully uninitialized.

source§

impl AddAssign<u16> for Word

source§

fn add_assign(&mut self, rhs: u16)

Increments the word by the provided value.

If the word was fully initialized, its updated value is also fully initialized. Otherwise, the resulting word is fully uninitialized.

source§

impl AddAssign for Word

source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
source§

impl BitAnd for Word

source§

fn bitand(self, rhs: Self) -> Self::Output

Applies a bitwise AND across two words.

This will also compute the correct initialization for the resulting word, taking into account bit clearing.

§

type Output = Word

The resulting type after applying the & operator.
source§

impl BitAndAssign for Word

source§

fn bitand_assign(&mut self, rhs: Self)

Performs the &= operation. Read more
source§

impl Clone for Word

source§

fn clone(&self) -> Word

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Word

source§

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

Formats the value using the given formatter. Read more
source§

impl From<i16> for Word

source§

fn from(value: i16) -> Self

Creates a fully initialized word.

source§

impl From<u16> for Word

source§

fn from(value: u16) -> Self

Creates a fully initialized word.

source§

impl Not for Word

source§

fn not(self) -> Self::Output

Inverts the data on this word, preserving any initialization state.

§

type Output = Word

The resulting type after applying the ! operator.
source§

impl Sub for Word

source§

fn sub(self, rhs: Self) -> Self::Output

Subtracts two words together (wrapping if overflow occurs).

If the two words are fully initialized, the resulting word will also be fully initialized. Otherwise, the resulting word is fully uninitialized.

§

type Output = Word

The resulting type after applying the - operator.
source§

impl SubAssign<i16> for Word

source§

fn sub_assign(&mut self, rhs: i16)

Decrements the word by the provided value.

If the word was fully initialized, its updated value is also fully initialized. Otherwise, the resulting word is fully uninitialized.

source§

impl SubAssign<u16> for Word

source§

fn sub_assign(&mut self, rhs: u16)

Decrements the word by the provided value.

If the word was fully initialized, its updated value is also fully initialized. Otherwise, the resulting word is fully uninitialized.

source§

impl SubAssign for Word

source§

fn sub_assign(&mut self, rhs: Self)

Performs the -= operation. Read more
source§

impl Copy for Word

Auto Trait Implementations§

§

impl Freeze for Word

§

impl RefUnwindSafe for Word

§

impl Send for Word

§

impl Sync for Word

§

impl Unpin for Word

§

impl UnwindSafe for Word

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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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