Enum fuel_asm::Opcode

source ·
pub enum Opcode {
Show 80 variants ADD(RegisterIdRegisterIdRegisterId), ADDI(RegisterIdRegisterIdImmediate12), AND(RegisterIdRegisterIdRegisterId), ANDI(RegisterIdRegisterIdImmediate12), DIV(RegisterIdRegisterIdRegisterId), DIVI(RegisterIdRegisterIdImmediate12), EQ(RegisterIdRegisterIdRegisterId), EXP(RegisterIdRegisterIdRegisterId), EXPI(RegisterIdRegisterIdImmediate12), GT(RegisterIdRegisterIdRegisterId), LT(RegisterIdRegisterIdRegisterId), MLOG(RegisterIdRegisterIdRegisterId), MROO(RegisterIdRegisterIdRegisterId), MOD(RegisterIdRegisterIdRegisterId), MODI(RegisterIdRegisterIdImmediate12), MOVE(RegisterIdRegisterId), MOVI(RegisterIdImmediate18), MUL(RegisterIdRegisterIdRegisterId), MULI(RegisterIdRegisterIdImmediate12), NOT(RegisterIdRegisterId), OR(RegisterIdRegisterIdRegisterId), ORI(RegisterIdRegisterIdImmediate12), SLL(RegisterIdRegisterIdRegisterId), SLLI(RegisterIdRegisterIdImmediate12), SRL(RegisterIdRegisterIdRegisterId), SRLI(RegisterIdRegisterIdImmediate12), SUB(RegisterIdRegisterIdRegisterId), SUBI(RegisterIdRegisterIdImmediate12), XOR(RegisterIdRegisterIdRegisterId), XORI(RegisterIdRegisterIdImmediate12), JI(Immediate24), JNEI(RegisterIdRegisterIdImmediate12), JNZI(RegisterIdImmediate18), JMP(RegisterId), JNE(RegisterIdRegisterIdRegisterId), RET(RegisterId), RETD(RegisterIdRegisterId), CFEI(Immediate24), CFSI(Immediate24), LB(RegisterIdRegisterIdImmediate12), LW(RegisterIdRegisterIdImmediate12), ALOC(RegisterId), MCL(RegisterIdRegisterId), MCLI(RegisterIdImmediate18), MCP(RegisterIdRegisterIdRegisterId), MCPI(RegisterIdRegisterIdImmediate12), MEQ(RegisterIdRegisterIdRegisterIdRegisterId), SB(RegisterIdRegisterIdImmediate12), SW(RegisterIdRegisterIdImmediate12), BAL(RegisterIdRegisterIdRegisterId), BHSH(RegisterIdRegisterId), BHEI(RegisterId), BURN(RegisterId), CALL(RegisterIdRegisterIdRegisterIdRegisterId), CCP(RegisterIdRegisterIdRegisterIdRegisterId), CROO(RegisterIdRegisterId), CSIZ(RegisterIdRegisterId), CB(RegisterId), LDC(RegisterIdRegisterIdRegisterId), LOG(RegisterIdRegisterIdRegisterIdRegisterId), LOGD(RegisterIdRegisterIdRegisterIdRegisterId), MINT(RegisterId), RVRT(RegisterId), SMO(RegisterIdRegisterIdRegisterIdRegisterId), SCWQ(RegisterIdRegisterIdRegisterId), SRW(RegisterIdRegisterIdRegisterId), SRWQ(RegisterIdRegisterIdRegisterIdRegisterId), SWW(RegisterIdRegisterIdRegisterId), SWWQ(RegisterIdRegisterIdRegisterIdRegisterId), TIME(RegisterIdRegisterId), TR(RegisterIdRegisterIdRegisterId), TRO(RegisterIdRegisterIdRegisterIdRegisterId), ECR(RegisterIdRegisterIdRegisterId), K256(RegisterIdRegisterIdRegisterId), S256(RegisterIdRegisterIdRegisterId), NOOP, FLAG(RegisterId), GM(RegisterIdImmediate18), GTF(RegisterIdRegisterIdImmediate12), Undefined,
}
Expand description

Instruction representation for the interpreter.

Memory Opcodes

All these opcodes advance the program counter $pc by 4 after performing their operation. Every instruction is guaranteed to fit in u32 representation.

Arithmetic/Logic (ALU) Opcodes

All these opcodes advance the program counter $pc by 4 after performing their operation.

If the F_UNSAFEMATH flag is unset, an operation that would have set $err to true is instead a panic.

If the F_WRAPPING flag is unset, an operation that would have set $of to a non-zero value is instead a panic. ## Contract Opcodes

All these opcodes advance the program counter $pc by 4 after performing their operation, except for CALL and REVERT.

Cryptographic Opcodes

All these opcodes advance the program counter $pc by 4 after performing their operation.

Variants§

§

ADD(RegisterIdRegisterIdRegisterId)

Adds two registers.

§

ADDI(RegisterIdRegisterIdImmediate12)

Adds a register and an immediate value.

§

AND(RegisterIdRegisterIdRegisterId)

Bitwise ANDs two registers.

§

ANDI(RegisterIdRegisterIdImmediate12)

Bitwise ANDs a register and an immediate value.

§

DIV(RegisterIdRegisterIdRegisterId)

Divides two registers.

§

DIVI(RegisterIdRegisterIdImmediate12)

Divides a register and an immediate value.

§

EQ(RegisterIdRegisterIdRegisterId)

Compares two registers for equality.

§

EXP(RegisterIdRegisterIdRegisterId)

Raises one register to the power of another.

§

EXPI(RegisterIdRegisterIdImmediate12)

Raises one register to the power of an immediate value.

§

GT(RegisterIdRegisterIdRegisterId)

Compares two registers for greater-than.

§

LT(RegisterIdRegisterIdRegisterId)

Compares two registers for less-than.

§

MLOG(RegisterIdRegisterIdRegisterId)

The integer logarithm of a register.

§

MROO(RegisterIdRegisterIdRegisterId)

The integer root of a register.

§

MOD(RegisterIdRegisterIdRegisterId)

Modulo remainder of two registers.

§

MODI(RegisterIdRegisterIdImmediate12)

Modulo remainder of a register and an immediate value.

§

MOVE(RegisterIdRegisterId)

Copy from one register to another.

§

MOVI(RegisterIdImmediate18)

Copy immediate value into a register

§

MUL(RegisterIdRegisterIdRegisterId)

Multiplies two registers.

§

MULI(RegisterIdRegisterIdImmediate12)

Multiplies a register and an immediate value.

§

NOT(RegisterIdRegisterId)

Bitwise NOT a register.

§

OR(RegisterIdRegisterIdRegisterId)

Bitwise ORs two registers.

§

ORI(RegisterIdRegisterIdImmediate12)

Bitwise ORs a register and an immediate value.

§

SLL(RegisterIdRegisterIdRegisterId)

Left shifts a register by a register.

§

SLLI(RegisterIdRegisterIdImmediate12)

Left shifts a register by an immediate value.

§

SRL(RegisterIdRegisterIdRegisterId)

Right shifts a register by a register.

§

SRLI(RegisterIdRegisterIdImmediate12)

Right shifts a register by an immediate value.

§

SUB(RegisterIdRegisterIdRegisterId)

Subtracts two registers.

§

SUBI(RegisterIdRegisterIdImmediate12)

Subtracts a register and an immediate value.

§

XOR(RegisterIdRegisterIdRegisterId)

Bitwise XORs two registers.

§

XORI(RegisterIdRegisterIdImmediate12)

Bitwise XORs a register and an immediate value.

§

JI(Immediate24)

Jump.

§

JNEI(RegisterIdRegisterIdImmediate12)

Conditional jump.

§

JNZI(RegisterIdImmediate18)

Conditional jump against zero.

§

JMP(RegisterId)

Dynamic jump.

§

JNE(RegisterIdRegisterIdRegisterId)

Conditional dynamic jump.

§

RET(RegisterId)

Return from context.

§

RETD(RegisterIdRegisterId)

Return from context with data.

§

CFEI(Immediate24)

Extend the current call frame’s stack by an immediate value.

§

CFSI(Immediate24)

Shrink the current call frame’s stack by an immediate value.

§

LB(RegisterIdRegisterIdImmediate12)

A byte is loaded from the specified address offset by an immediate value.

§

LW(RegisterIdRegisterIdImmediate12)

A word is loaded from the specified address offset by an immediate value.

§

ALOC(RegisterId)

Allocate a number of bytes from the heap.

§

MCL(RegisterIdRegisterId)

Clear a variable number of bytes in memory.

§

MCLI(RegisterIdImmediate18)

Clear an immediate number of bytes in memory.

§

MCP(RegisterIdRegisterIdRegisterId)

Copy a variable number of bytes in memory.

§

MCPI(RegisterIdRegisterIdImmediate12)

Copy an immediate number of bytes in memory.

§

MEQ(RegisterIdRegisterIdRegisterIdRegisterId)

Compare bytes in memory.

§

SB(RegisterIdRegisterIdImmediate12)

Write the least significant byte of a register to memory.

§

SW(RegisterIdRegisterIdImmediate12)

Write a register to memory.

§

BAL(RegisterIdRegisterIdRegisterId)

Get the balance of contract of an asset ID.

§

BHSH(RegisterIdRegisterId)

Get block header hash for height.

§

BHEI(RegisterId)

Get current block height.

§

BURN(RegisterId)

Burn coins of the current contract’s asset ID.

§

CALL(RegisterIdRegisterIdRegisterIdRegisterId)

Call a contract.

§

CCP(RegisterIdRegisterIdRegisterIdRegisterId)

Copy contract code for a contract.

§

CROO(RegisterIdRegisterId)

Get code root of a contract.

§

CSIZ(RegisterIdRegisterId)

Get code size of a contract.

§

CB(RegisterId)

Get current block proposer’s address.

§

LDC(RegisterIdRegisterIdRegisterId)

Load a contract’s code as executable.

§

LOG(RegisterIdRegisterIdRegisterIdRegisterId)

Log an event.

§

LOGD(RegisterIdRegisterIdRegisterIdRegisterId)

Log data.

§

MINT(RegisterId)

Mint coins of the current contract’s asset ID.

§

RVRT(RegisterId)

Halt execution, reverting state changes and returning a value.

§

SMO(RegisterIdRegisterIdRegisterIdRegisterId)

Send a message to recipient address with call abi, coins, and output.

§

SCWQ(RegisterIdRegisterIdRegisterId)

Clear a series of slots from contract storage.

§

SRW(RegisterIdRegisterIdRegisterId)

Load a word from contract storage.

§

SRWQ(RegisterIdRegisterIdRegisterIdRegisterId)

Load a series of 32 byte slots from contract storage.

§

SWW(RegisterIdRegisterIdRegisterId)

Store a word in contract storage.

§

SWWQ(RegisterIdRegisterIdRegisterIdRegisterId)

Store a series of 32 byte slots in contract storage.

§

TIME(RegisterIdRegisterId)

Get timestamp of block at given height.

§

TR(RegisterIdRegisterIdRegisterId)

Transfer coins to a contract unconditionally.

§

TRO(RegisterIdRegisterIdRegisterIdRegisterId)

Transfer coins to a variable output.

§

ECR(RegisterIdRegisterIdRegisterId)

The 64-byte public key (x, y) recovered from 64-byte signature on 32-byte message.

§

K256(RegisterIdRegisterIdRegisterId)

The keccak-256 hash of a slice.

§

S256(RegisterIdRegisterIdRegisterId)

The SHA-2-256 hash of a slice.

§

NOOP

Performs no operation.

§

FLAG(RegisterId)

Set flag register to a register.

§

GM(RegisterIdImmediate18)

Get metadata from memory.

§

GTF(RegisterIdRegisterIdImmediate12)

Get transaction fields.

§

Undefined

Undefined opcode, potentially from inconsistent serialization.

Implementations§

source§

impl Opcode

source

pub const LEN: usize = 4usize

Size of the struct when serialized into bytes

source

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

Create a new Opcode given the internal attributes

source

pub unsafe fn from_bytes_unchecked(bytes: &[u8]) -> Self

Create a Opcode from a slice of bytes

Safety

Reflects the requirements of bytes::from_slice_unchecked

source

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

Convert the opcode to bytes representation

source

pub const fn registers(&self) -> [Option<RegisterId>; 4]

Transform the Opcode into an optional array of 4 register identifiers

source

pub const fn immediate(&self) -> Option<Word>

Return the underlying immediate value, if present

source

pub const fn gm(ra: RegisterId, args: GMArgs) -> Self

Create a new Opcode::GM instruction from its args

source

pub const fn gtf(ra: RegisterId, rb: RegisterId, args: GTFArgs) -> Self

Create a new Opcode::GTF instruction from its args

source§

impl Opcode

source

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

Available on crate feature std only.

Create a Opcode from a slice of bytes

This function will fail if the length of the bytes is smaller than Opcode::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 Opcode from an iterator of bytes

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

Trait Implementations§

source§

impl<'arbitrary> Arbitrary<'arbitrary> for Opcode

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 Opcode

source§

fn clone(&self) -> Opcode

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 Opcode

source§

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

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

impl<'de> Deserialize<'de> for Opcode

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 Opcode

source§

fn from(b: [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<InstructionResult> for Opcode

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<Opcode> for u32

source§

fn from(opcode: Opcode) -> u32

Converts to this type from the input type.
source§

impl From<u32> for Opcode

source§

fn from(instruction: u32) -> Self

Converts to this type from the input type.
source§

impl FromIterator<Opcode> for Vec<Instruction>

Available on crate feature std only.
source§

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

Creates a value from an iterator. Read more
source§

impl FromIterator<Opcode> for Vec<u8>

Available on crate feature std only.
source§

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

Creates a value from an iterator. Read more
source§

impl Hash for Opcode

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<Opcode> for Opcode

source§

fn eq(&self, other: &Opcode) -> 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 Read for Opcode

Available on crate feature std only.
source§

fn read(&mut self, buf: &mut [u8]) -> Result<usize>

Pull some bytes from this source into the specified buffer, returning how many bytes were read. Read more
1.36.0 · source§

fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>

Like read, except that it reads into a slice of buffers. Read more
source§

fn is_read_vectored(&self) -> bool

🔬This is a nightly-only experimental API. (can_vector)
Determines if this Reader has an efficient read_vectored implementation. Read more
1.0.0 · source§

fn read_to_end(&mut self, buf: &mut Vec<u8, Global>) -> Result<usize, Error>

Read all bytes until EOF in this source, placing them into buf. Read more
1.0.0 · source§

fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>

Read all bytes until EOF in this source, appending them to buf. Read more
1.6.0 · source§

fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>

Read the exact number of bytes required to fill buf. Read more
source§

fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>

🔬This is a nightly-only experimental API. (read_buf)
Pull some bytes from this source into the specified buffer. Read more
source§

fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>

🔬This is a nightly-only experimental API. (read_buf)
Read the exact number of bytes required to fill cursor. Read more
1.0.0 · source§

fn by_ref(&mut self) -> &mut Selfwhere
    Self: Sized,

Creates a “by reference” adaptor for this instance of Read. Read more
1.0.0 · source§

fn bytes(self) -> Bytes<Self>where
    Self: Sized,

Transforms this Read instance to an Iterator over its bytes. Read more
1.0.0 · source§

fn chain<R>(self, next: R) -> Chain<Self, R>where
    R: Read,
    Self: Sized,

Creates an adapter which will chain this stream with another. Read more
1.0.0 · source§

fn take(self, limit: u64) -> Take<Self>where
    Self: Sized,

Creates an adapter which will read at most limit bytes from it. Read more
source§

impl Serialize for Opcode

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 Write for Opcode

Available on crate feature std only.
source§

fn write(&mut self, buf: &[u8]) -> Result<usize>

Write a buffer into this writer, returning how many bytes were written. Read more
source§

fn flush(&mut self) -> Result<()>

Flush this output stream, ensuring that all intermediately buffered contents reach their destination. Read more
1.36.0 · source§

fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> Result<usize, Error>

Like write, except that it writes from a slice of buffers. Read more
source§

fn is_write_vectored(&self) -> bool

🔬This is a nightly-only experimental API. (can_vector)
Determines if this Writer has an efficient write_vectored implementation. Read more
1.0.0 · source§

fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>

Attempts to write an entire buffer into this writer. Read more
source§

fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>

🔬This is a nightly-only experimental API. (write_all_vectored)
Attempts to write multiple buffers into this writer. Read more
1.0.0 · source§

fn write_fmt(&mut self, fmt: Arguments<'_>) -> Result<(), Error>

Writes a formatted string into this writer, returning any error encountered. Read more
1.0.0 · source§

fn by_ref(&mut self) -> &mut Selfwhere
    Self: Sized,

Creates a “by reference” adapter for this instance of Write. Read more
source§

impl Copy for Opcode

source§

impl Eq for Opcode

source§

impl StructuralEq for Opcode

source§

impl StructuralPartialEq for Opcode

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>,