Struct zingen::MacroAssembler

source ·
pub struct MacroAssembler {
    pub(crate) asm: Assembler,
}
Expand description

EVM MacroAssembler.

Fields§

§asm: Assembler

Low level assembler.

Implementations§

source§

impl MacroAssembler

source

pub fn _ge(&mut self) -> Result<()>

Greater than or equal comparison.

a b ge -> a b-1 gt(lt)

Using lt due to order of stack.

source

pub fn _sge(&mut self) -> Result<()>

Greater than or equal comparison.

a b sge -> a b-1 sgt(slt)

Using lt due to order of stack.

source

pub fn _sle(&mut self) -> Result<()>

Greater than or equal comparison.

a b sge -> a b-1 sgt(slt)

Using lt due to order of stack.

source

pub fn _le(&mut self) -> Result<()>

Greater than or equal comparison.

a b le -> a b-1 lt(gt)

Using gt due to order of stack.

source

pub fn _sgt(&mut self) -> Result<()>

Greater than and equal comparison.

Using slt due to order of stack.

source

pub fn _gt(&mut self) -> Result<()>

Greater than comparison.

Using lt due to order of stack.

source

pub fn _lt(&mut self) -> Result<()>

less than comparison.

Using gt due to order of stack.

source

pub fn _slt(&mut self) -> Result<()>

less than or equal comparison.

Using gt due to order of stack.

source

pub fn _ne(&mut self) -> Result<()>

Sign-agnostic compare unequal.

source

pub fn _eqz(&mut self) -> Result<()>

Simple not operator

source§

impl MacroAssembler

source

pub fn _sstore(&mut self) -> Result<()>

Function sstore from EVM which is not available in WASM.

source

pub fn _sload(&mut self) -> Result<()>

Function sload from EVM which is not available in WASM.

source§

impl MacroAssembler

source

pub fn _max(&mut self) -> Result<()>

Maximum of two values

source

pub fn _min(&mut self) -> Result<()>

Minimum of two values

source

pub fn _ceil(&mut self) -> Result<()>

Ceiling operator

source

pub fn _floor(&mut self) -> Result<()>

Floor operator

source

pub fn _nearest(&mut self) -> Result<()>

Round to nearest integer, ties to even.

source

pub fn _sqrt(&mut self) -> Result<()>

Square root

source

pub fn _abs(&mut self) -> Result<()>

Absolute value

source

pub fn _neg(&mut self) -> Result<()>

Negation

source

pub fn _copysign(&mut self) -> Result<()>

If z1 and z2 have the same sign, return z1, otherwise return z1 with negated sign.

source

pub fn _convert_i32_s(&mut self) -> Result<()>

Convert a signed 32-bit integer to a (32-bit/64-bit) float

source

pub fn _convert_i32_u(&mut self) -> Result<()>

Convert an unsigned 32-bit integer to a (32-bit/64-bit) float

source

pub fn _convert_i64_s(&mut self) -> Result<()>

Convert a signed 32-bit integer to a (32-bit/64-bit) float

source

pub fn _convert_i64_u(&mut self) -> Result<()>

Convert a unsigned 32-bit integer to a (32-bit/64-bit) float

source

pub fn _trunc(&mut self) -> Result<()>

Round to nearest integer towards zero

source§

impl MacroAssembler

source

pub fn _sub(&mut self) -> Result<()>

Sub two numbers.

source

pub fn _i32_const(&mut self, value: i32) -> Result<()>

Push a 32-bit integer value on the stack.

source

pub fn _i64_const(&mut self, value: i64) -> Result<()>

Push a 64-bit integer value on the stack.

source

pub fn _f32_const(&mut self, _value: Ieee32) -> Result<()>

Push a 32-bit float value on the stack.

source

pub fn _f64_const(&mut self, _value: Ieee64) -> Result<()>

Push a 64-bit float value on the stack.

source

pub fn _i32_wrap_i64(&mut self) -> Result<()>

wrap a 64-bit integer to a 32-bit integer.

source

pub fn _i64_extend_i32_s(&mut self) -> Result<()>

Extend a signed 32-bit integer to a 64-bit integer.

source

pub fn _i64_extend_i32_u(&mut self) -> Result<()>

Extend an unsigned 32-bit integer to a 64-bit integer.

source

pub fn _f32_demote_f64(&mut self) -> Result<()>

Truncate a 64-bit float to a signed 32-bit integer.

source

pub fn _f64_promote_f32(&mut self) -> Result<()>

Truncate a 64-bit float to an unsigned 32-bit integer.

source

pub fn _i32_reinterpret_f32(&mut self) -> Result<()>

Convert a signed 32-bit integer to a 32-bit float.

source

pub fn _i64_reinterpret_f64(&mut self) -> Result<()>

Convert a signed 64-bit integer to a 64-bit float.

source

pub fn _f32_reinterpret_i32(&mut self) -> Result<()>

Convert a 32-bit float to a signed 32-bit integer.

source

pub fn _f64_reinterpret_i64(&mut self) -> Result<()>

Convert a 64-bit float to a signed 64-bit integer.

source

pub fn _rotl(&mut self) -> Result<()>

sign-agnostic rotate left

Return the result of rotating i1 left by k bits.

source

pub fn _rotr(&mut self) -> Result<()>

sign-agnostic rotate right

Return the result of rotating i1 right by k bits.

source

pub fn _clz(&mut self) -> Result<()>

sign-agnostic count leading zero bits

Return the number of leading zero bits in i, all zero bits are considered leading if the value is zero.

source

pub fn _ctz(&mut self) -> Result<()>

sign-agnostic count leading zero bits

Return the number of leading zero bits in i, all zero bits are considered trailing if the value is zero.

source

pub fn _popcnt(&mut self) -> Result<()>

sign-agnostic count number of one bits

Return the count of no zero bits in i.

source

pub fn _trunc_f32(&mut self) -> Result<()>

Truncate a 32-bit float to an integer

source

pub fn _trunc_f64(&mut self) -> Result<()>

Truncate a 64-bit float to an integer

source§

impl MacroAssembler

source

pub(crate) fn _load(&mut self) -> Result<()>

Load n bytes to extend self as another number type.

Just for adapting the WASM instructions, this method makes no sense for EVM since all of the numbers as U256.

source

pub(crate) fn _load8(&mut self) -> Result<()>

Load 1 byte to extend self as another number type.

Just for adapting the WASM instructions, this method makes no sense for EVM since all of the numbers as U256.

source

pub(crate) fn _load16(&mut self) -> Result<()>

Load 2 bytes to extend self as another number type.

Just for adapting the WASM instructions, this method makes no sense for EVM since all of the numbers as U256.

source

pub(crate) fn _load32(&mut self) -> Result<()>

Load 4 bytes to extend self as another number type.

Just for adapting the WASM instructions, this method makes no sense for EVM since all of the numbers as U256.

source

pub fn _store(&mut self) -> Result<()>

Store n bytes in memory.

source

pub fn _store8(&mut self) -> Result<()>

Wrap self to i8 and store 1 byte

source

pub fn _store16(&mut self) -> Result<()>

Wrap self to i16 and store 2 bytes

source

pub fn _store32(&mut self) -> Result<()>

Wrap self to i32 and store 4 bytes

source

pub fn _memory_size(&mut self, _: u32, _: u8) -> Result<()>

The memory size instruction returns the current size of memory.

source

pub fn _memory_grow(&mut self, _: u32, _: u8) -> Result<()>

The memory grow instruction grows memory by a given delta and returns the previous size, or -1 if enough memory cannot be allocated.

source§

impl MacroAssembler

source

pub(crate) fn handle_empty_return(&mut self) -> Result<()>

Return with nothing.

source

pub fn main_return(&mut self, results: &[ValType]) -> Result<()>

Handle the end of the main function.

source

pub fn call_return(&mut self, results: &[ValType]) -> Result<()>

Handle the return of a call.

source§

impl MacroAssembler

source

pub fn _drop(&mut self) -> Result<()>

The drop instruction simply throw away a single operand.

source§

impl MacroAssembler

source

pub fn memory_write(&mut self, ty: impl Type) -> Result<MemoryInfo>

Store data in memory with at current memory byte pointer.

source

pub fn memory_write_bytes(&mut self, bytes: &[u8]) -> Result<MemoryInfo>

Write bytes to memory.

source

pub fn memory_write_at(&mut self, offset: &[u8]) -> Result<()>

Store data in memory at offset.

Returns the size in the lowest significant bytes.

source

pub fn pc_offset(&self) -> u16

Get the current program counter offset.

source

pub fn push(&mut self, bytes: &[u8]) -> Result<()>

Place n bytes on stack.

source

pub fn mp_offset<F>(&self, f: F) -> Result<SmallVec<[u8; 8]>>
where F: Fn(usize) -> Result<usize>,

Get byte offset of the memory pointer.

source

pub fn sp(&self) -> u8

Get the stack pointer.

source

pub fn swap(&mut self, index: u8) -> Result<()>

Swap memory by target index.

source

pub fn dup(&mut self, index: u8) -> Result<()>

Duplicate stack item by target index.

source

pub fn shift_stack(&mut self, count: u8, from_top: bool) -> Result<()>

Shift the program counter to the bottom or the top of the parameters. This is used by the callee function for jumping back to the caller function.

source

pub fn _return(&mut self) -> Result<()>

Return zero or more values from the function.

The return instruction is a shortcut for an unconditional branch to the outermost block, which implicitly is the body of the current function.

NOTE: This return could be different from the return in the EVM.

Methods from Deref<Target = Assembler>§

source

pub fn buffer(&self) -> &[u8]

Buffer of the assembler.

source

pub fn buffer_mut(&mut self) -> &mut Buffer

Mutable buffer of the assembler.

source

pub fn increment_gas(&mut self, gas: u128)

Increment the gas counter.

TODO: use number bigger than u256 for throwing proper errors. (#21)

source

pub fn increment_sp(&mut self, items: u8) -> Result<()>

Increment stack pointer

source

pub fn decrement_sp(&mut self, items: u8) -> Result<()>

Decrement stack pointer

source

pub fn increment_mp(&mut self, offset: usize) -> Result<()>

Increment memory pointer

source

pub fn decrement_mp(&mut self, offset: usize) -> Result<()>

Decrement memory pointer

source

pub fn emit(&mut self, byte: u8)

Emit a byte.

source

pub fn emitn(&mut self, bytes: &[u8])

Emit n bytes.

source

pub fn emit_op(&mut self, opcode: OpCode) -> Result<()>

Emit a single opcode.

Mock the stack input and output for checking the stack usages.

source

pub fn _stop(&mut self) -> Result<()>

Emit STOP

source

pub fn _add(&mut self) -> Result<()>

Emit ADD

source

pub fn _mul(&mut self) -> Result<()>

Emit MUL

source

pub fn _sub(&mut self) -> Result<()>

Emit SUB

source

pub fn _div(&mut self) -> Result<()>

Emit DIV

source

pub fn _sdiv(&mut self) -> Result<()>

Emit SDIV

source

pub fn _mod(&mut self) -> Result<()>

Emit MOD

source

pub fn _smod(&mut self) -> Result<()>

Emit SMOD

source

pub fn _addmod(&mut self) -> Result<()>

Emit ADDMOD

source

pub fn _mulmod(&mut self) -> Result<()>

Emit MULMOD

source

pub fn _exp(&mut self) -> Result<()>

Emit EXP

source

pub fn _signextend(&mut self) -> Result<()>

Emit SIGNEXTEND

source

pub fn _lt(&mut self) -> Result<()>

Emit LT

source

pub fn _gt(&mut self) -> Result<()>

Emit GT

source

pub fn _slt(&mut self) -> Result<()>

Emit SLT

source

pub fn _sgt(&mut self) -> Result<()>

Emit SGT

source

pub fn _eq(&mut self) -> Result<()>

Emit EQ

source

pub fn _iszero(&mut self) -> Result<()>

Emit ISZERO

source

pub fn _and(&mut self) -> Result<()>

Emit AND

source

pub fn _or(&mut self) -> Result<()>

Emit OR

source

pub fn _xor(&mut self) -> Result<()>

Emit XOR

source

pub fn _not(&mut self) -> Result<()>

Emit NOT

source

pub fn _byte(&mut self) -> Result<()>

Emit BYTE

source

pub fn _shl(&mut self) -> Result<()>

Emit SHL

source

pub fn _shr(&mut self) -> Result<()>

Emit SHR

source

pub fn _sar(&mut self) -> Result<()>

Emit SAR

source

pub fn _sha3(&mut self) -> Result<()>

Emit SHA3

source

pub fn _address(&mut self) -> Result<()>

Emit ADDRESS

source

pub fn _balance(&mut self) -> Result<()>

Emit BALANCE

source

pub fn _origin(&mut self) -> Result<()>

Emit ORIGIN

source

pub fn _caller(&mut self) -> Result<()>

Emit CALLER

source

pub fn _callvalue(&mut self) -> Result<()>

Emit CALLVALUE

source

pub fn _calldataload(&mut self) -> Result<()>

Emit CALLDATALOAD

source

pub fn _calldatasize(&mut self) -> Result<()>

Emit CALLDATASIZE

source

pub fn _calldatacopy(&mut self) -> Result<()>

Emit CALLDATACOPY

source

pub fn _codesize(&mut self) -> Result<()>

Emit CODESIZE

source

pub fn _codecopy(&mut self) -> Result<()>

Emit CODECOPY

source

pub fn _gasprice(&mut self) -> Result<()>

Emit GASPRICE

source

pub fn _extcodesize(&mut self) -> Result<()>

Emit EXTCODESIZE

source

pub fn _extcodecopy(&mut self) -> Result<()>

Emit EXTCODECOPY

source

pub fn _returndatasize(&mut self) -> Result<()>

Emit RETURNDATASIZE

source

pub fn _returndatacopy(&mut self) -> Result<()>

Emit RETURNDATACOPY

source

pub fn _blockhash(&mut self) -> Result<()>

Emit BLOCKHASH

source

pub fn _coinbase(&mut self) -> Result<()>

Emit COINBASE

source

pub fn _timestamp(&mut self) -> Result<()>

Emit TIMESTAMP

source

pub fn _number(&mut self) -> Result<()>

Emit NUMBER

source

pub fn _difficulty(&mut self) -> Result<()>

Emit DIFFICULTY

source

pub fn _gaslimit(&mut self) -> Result<()>

Emit GASLIMIT

source

pub fn _pop(&mut self) -> Result<()>

Emit POP

source

pub fn _mload(&mut self) -> Result<()>

Emit MLOAD

source

pub fn _mstore(&mut self) -> Result<()>

Emit MSTORE

source

pub fn _mstore8(&mut self) -> Result<()>

Emit MSTORE8

source

pub fn _sload(&mut self) -> Result<()>

Emit SLOAD

source

pub fn _sstore(&mut self) -> Result<()>

Emit SSTORE

source

pub fn _jump(&mut self) -> Result<()>

Emit JUMP

source

pub fn _jumpi(&mut self) -> Result<()>

Emit JUMPI

source

pub fn _pc(&mut self) -> Result<()>

Emit PC

source

pub fn _msize(&mut self) -> Result<()>

Emit MSIZE

source

pub fn _gas(&mut self) -> Result<()>

Emit GAS

source

pub fn _jumpdest(&mut self) -> Result<()>

Emit JUMPDEST

source

pub fn _push0(&mut self) -> Result<()>

Emit PUSH0

source

pub fn _push1(&mut self) -> Result<()>

Emit PUSH1

source

pub fn _push2(&mut self) -> Result<()>

Emit PUSH2

source

pub fn _push3(&mut self) -> Result<()>

Emit PUSH3

source

pub fn _push4(&mut self) -> Result<()>

Emit PUSH4

source

pub fn _push5(&mut self) -> Result<()>

Emit PUSH5

source

pub fn _push6(&mut self) -> Result<()>

Emit PUSH6

source

pub fn _push7(&mut self) -> Result<()>

Emit PUSH7

source

pub fn _push8(&mut self) -> Result<()>

Emit PUSH8

source

pub fn _push9(&mut self) -> Result<()>

Emit PUSH9

source

pub fn _push10(&mut self) -> Result<()>

Emit PUSH10

source

pub fn _push11(&mut self) -> Result<()>

Emit PUSH11

source

pub fn _push12(&mut self) -> Result<()>

Emit PUSH12

source

pub fn _push13(&mut self) -> Result<()>

Emit PUSH13

source

pub fn _push14(&mut self) -> Result<()>

Emit PUSH14

source

pub fn _push15(&mut self) -> Result<()>

Emit PUSH15

source

pub fn _push16(&mut self) -> Result<()>

Emit PUSH16

source

pub fn _push17(&mut self) -> Result<()>

Emit PUSH17

source

pub fn _push18(&mut self) -> Result<()>

Emit PUSH18

source

pub fn _push19(&mut self) -> Result<()>

Emit PUSH19

source

pub fn _push20(&mut self) -> Result<()>

Emit PUSH20

source

pub fn _push21(&mut self) -> Result<()>

Emit PUSH21

source

pub fn _push22(&mut self) -> Result<()>

Emit PUSH22

source

pub fn _push23(&mut self) -> Result<()>

Emit PUSH23

source

pub fn _push24(&mut self) -> Result<()>

Emit PUSH24

source

pub fn _push25(&mut self) -> Result<()>

Emit PUSH25

source

pub fn _push26(&mut self) -> Result<()>

Emit PUSH26

source

pub fn _push27(&mut self) -> Result<()>

Emit PUSH27

source

pub fn _push28(&mut self) -> Result<()>

Emit PUSH28

source

pub fn _push29(&mut self) -> Result<()>

Emit PUSH29

source

pub fn _push30(&mut self) -> Result<()>

Emit PUSH30

source

pub fn _push31(&mut self) -> Result<()>

Emit PUSH31

source

pub fn _push32(&mut self) -> Result<()>

Emit PUSH32

source

pub fn _dup1(&mut self) -> Result<()>

Emit DUP1

source

pub fn _dup2(&mut self) -> Result<()>

Emit DUP2

source

pub fn _dup3(&mut self) -> Result<()>

Emit DUP3

source

pub fn _dup4(&mut self) -> Result<()>

Emit DUP4

source

pub fn _dup5(&mut self) -> Result<()>

Emit DUP5

source

pub fn _dup6(&mut self) -> Result<()>

Emit DUP6

source

pub fn _dup7(&mut self) -> Result<()>

Emit DUP7

source

pub fn _dup8(&mut self) -> Result<()>

Emit DUP8

source

pub fn _dup9(&mut self) -> Result<()>

Emit DUP9

source

pub fn _dup10(&mut self) -> Result<()>

Emit DUP10

source

pub fn _dup11(&mut self) -> Result<()>

Emit DUP11

source

pub fn _dup12(&mut self) -> Result<()>

Emit DUP12

source

pub fn _dup13(&mut self) -> Result<()>

Emit DUP13

source

pub fn _dup14(&mut self) -> Result<()>

Emit DUP14

source

pub fn _dup15(&mut self) -> Result<()>

Emit DUP15

source

pub fn _dup16(&mut self) -> Result<()>

Emit DUP16

source

pub fn _swap1(&mut self) -> Result<()>

Emit SWAP1

source

pub fn _swap2(&mut self) -> Result<()>

Emit SWAP2

source

pub fn _swap3(&mut self) -> Result<()>

Emit SWAP3

source

pub fn _swap4(&mut self) -> Result<()>

Emit SWAP4

source

pub fn _swap5(&mut self) -> Result<()>

Emit SWAP5

source

pub fn _swap6(&mut self) -> Result<()>

Emit SWAP6

source

pub fn _swap7(&mut self) -> Result<()>

Emit SWAP7

source

pub fn _swap8(&mut self) -> Result<()>

Emit SWAP8

source

pub fn _swap9(&mut self) -> Result<()>

Emit SWAP9

source

pub fn _swap10(&mut self) -> Result<()>

Emit SWAP10

source

pub fn _swap11(&mut self) -> Result<()>

Emit SWAP11

source

pub fn _swap12(&mut self) -> Result<()>

Emit SWAP12

source

pub fn _swap13(&mut self) -> Result<()>

Emit SWAP13

source

pub fn _swap14(&mut self) -> Result<()>

Emit SWAP14

source

pub fn _swap15(&mut self) -> Result<()>

Emit SWAP15

source

pub fn _swap16(&mut self) -> Result<()>

Emit SWAP16

source

pub fn _log0(&mut self) -> Result<()>

Emit LOG0

source

pub fn _log1(&mut self) -> Result<()>

Emit LOG1

source

pub fn _log2(&mut self) -> Result<()>

Emit LOG2

source

pub fn _log3(&mut self) -> Result<()>

Emit LOG3

source

pub fn _log4(&mut self) -> Result<()>

Emit LOG4

source

pub fn _create(&mut self) -> Result<()>

Emit CREATE

source

pub fn _call(&mut self) -> Result<()>

Emit CALL

source

pub fn _callcode(&mut self) -> Result<()>

Emit CALLCODE

source

pub fn _return(&mut self) -> Result<()>

Emit RETURN

source

pub fn _delegatecall(&mut self) -> Result<()>

Emit DELEGATECALL

source

pub fn _create2(&mut self) -> Result<()>

Emit CREATE2

source

pub fn _staticcall(&mut self) -> Result<()>

Emit STATICCALL

source

pub fn _revert(&mut self) -> Result<()>

Emit REVERT

source

pub fn _invalid(&mut self) -> Result<()>

Emit INVALID

source

pub fn _selfdestruct(&mut self) -> Result<()>

Emit SELFDESTRUCT

Trait Implementations§

source§

impl Default for MacroAssembler

source§

fn default() -> MacroAssembler

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

impl Deref for MacroAssembler

§

type Target = Assembler

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl DerefMut for MacroAssembler

source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.

Auto Trait Implementations§

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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more