Struct fuel_asm::Instruction

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

A version of Opcode that can be used without unnecessary branching

Implementations§

source§

impl Instruction

source

pub const LEN: usize = 4usize

Size of an opcode in bytes

source

pub const fn new(instruction: u32) -> Self

Extracts fields from a raw instruction

source

pub const fn op(&self) -> u8

Opcode

source

pub const fn ra(&self) -> RegisterId

Register A

source

pub const fn rb(&self) -> RegisterId

Register B

source

pub const fn rc(&self) -> RegisterId

Register C

source

pub const fn rd(&self) -> RegisterId

Register D

source

pub const fn imm06(&self) -> Immediate06

Immediate with 6 bits

source

pub const fn imm12(&self) -> Immediate12

Immediate with 12 bits

source

pub const fn imm18(&self) -> Immediate18

Immediate with 18 bits

source

pub const fn imm24(&self) -> Immediate24

Immediate with 24 bits

source

pub unsafe fn from_slice_unchecked(buf: &[u8]) -> Self

Create a Instruction from a slice of bytes

Safety

The caller must ensure that the slice is has at least Self::LEN bytes.

source

pub fn to_bytes(self) -> [u8; 4]

Convert the opcode to bytes representation

source

pub const fn parse_word(word: Word) -> (Instruction, Instruction)

Splits a Word into two Instruction that can be used to construct crate::Opcode

source

pub const fn into_inner(
    self
) -> (OpcodeRepr, RegisterId, RegisterId, RegisterId, RegisterId, Word)

Convert the instruction into its internal representation

(repr, $ra, $rb, $rc, $rd, immediate)

source§

impl Instruction

source

pub fn from_bytes(bytes: &[u8]) -> Result<Self>

Available on crate feature std only.

Create a Instruction from a slice of bytes

This function will fail if the length of the bytes is smaller than Instruction::LEN.

source

pub fn from_bytes_iter<I>(bytes: I) -> Vec<Self>where
    I: IntoIterator<Item = u8>,

Available on crate feature std only.

Create a set of Instruction from an iterator of bytes

If not padded to Self::LEN, will consume the unaligned bytes but won’t try to parse an instruction from them.

Trait Implementations§

source§

impl<'arbitrary> Arbitrary<'arbitrary> for Instruction

source§

fn arbitrary(u: &mut Unstructured<'arbitrary>) -> Result<Self>

Generate an arbitrary value of Self from the given unstructured data. Read more
source§

fn arbitrary_take_rest(u: Unstructured<'arbitrary>) -> Result<Self>

Generate an arbitrary value of Self from the entirety of the given unstructured data. Read more
source§

fn size_hint(depth: usize) -> (usize, Option<usize>)

Get a size hint for how many bytes out of an Unstructured this type needs to construct itself. Read more
source§

impl Clone for Instruction

source§

fn clone(&self) -> Instruction

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 Instruction

source§

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

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

impl Default for Instruction

source§

fn default() -> Instruction

Returns the “default value” for a type. Read more
source§

impl<'de> Deserialize<'de> for Instruction

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
    __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl From<[u8; 4]> for Instruction

source§

fn from(instruction: [u8; 4]) -> Self

Converts to this type from the input type.
source§

impl From<Instruction> for Opcode

source§

fn from(parsed: Instruction) -> Self

Converts to this type from the input type.
source§

impl From<Instruction> for u32

source§

fn from(parsed: Instruction) -> u32

Converts to this type from the input type.
source§

impl From<InstructionResult> for Instruction

source§

fn from(r: InstructionResult) -> Self

Converts to this type from the input type.
source§

impl From<Opcode> for Instruction

source§

fn from(op: Opcode) -> Self

Converts to this type from the input type.
source§

impl From<u32> for Instruction

source§

fn from(instruction: u32) -> Self

Converts to this type from the input type.
source§

impl FromIterator<Instruction> for Vec<Opcode>

Available on crate feature std only.
source§

fn from_iter<T>(iter: T) -> Selfwhere
    T: IntoIterator<Item = Instruction>,

Creates a value from an iterator. Read more
source§

impl FromIterator<Instruction> for Vec<u8>

Available on crate feature std only.
source§

fn from_iter<T>(iter: T) -> Selfwhere
    T: IntoIterator<Item = Instruction>,

Creates a value from an iterator. Read more
source§

impl Hash for Instruction

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where
    H: Hasher,
    Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl PartialEq<Instruction> for Instruction

source§

fn eq(&self, other: &Instruction) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for Instruction

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>where
    __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Copy for Instruction

source§

impl Eq for Instruction

source§

impl StructuralEq for Instruction

source§

impl StructuralPartialEq for Instruction

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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 Twhere
    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 Twhere
    U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

impl<T> DeserializeOwned for Twhere
    T: for<'de> Deserialize<'de>,