Struct zingen::MacroAssembler

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

EVM MacroAssembler.

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 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 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_pc(&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<()>

EmitSTOP

source

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

EmitADD

source

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

EmitMUL

source

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

EmitSUB

source

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

EmitDIV

source

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

EmitSDIV

source

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

EmitMOD

source

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

EmitSMOD

source

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

EmitADDMOD

source

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

EmitMULMOD

source

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

EmitEXP

source

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

EmitSIGNEXTEND

source

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

EmitLT

source

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

EmitGT

source

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

EmitSLT

source

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

EmitSGT

source

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

EmitEQ

source

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

EmitISZERO

source

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

EmitAND

source

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

EmitOR

source

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

EmitXOR

source

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

EmitNOT

source

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

EmitBYTE

source

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

EmitSHL

source

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

EmitSHR

source

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

EmitSAR

source

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

EmitSHA3

source

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

EmitADDRESS

source

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

EmitBALANCE

source

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

EmitORIGIN

source

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

EmitCALLER

source

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

EmitCALLVALUE

source

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

EmitCALLDATALOAD

source

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

EmitCALLDATASIZE

source

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

EmitCALLDATACOPY

source

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

EmitCODESIZE

source

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

EmitCODECOPY

source

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

EmitGASPRICE

source

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

EmitEXTCODESIZE

source

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

EmitEXTCODECOPY

source

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

EmitRETURNDATASIZE

source

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

EmitRETURNDATACOPY

source

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

EmitBLOCKHASH

source

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

EmitCOINBASE

source

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

EmitTIMESTAMP

source

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

EmitNUMBER

source

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

EmitDIFFICULTY

source

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

EmitGASLIMIT

source

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

EmitPOP

source

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

EmitMLOAD

source

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

EmitMSTORE

source

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

EmitMSTORE8

source

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

EmitSLOAD

source

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

EmitSSTORE

source

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

EmitJUMP

source

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

EmitJUMPI

source

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

EmitPC

source

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

EmitMSIZE

source

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

EmitGAS

source

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

EmitJUMPDEST

source

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

EmitPUSH0

source

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

EmitPUSH1

source

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

EmitPUSH2

source

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

EmitPUSH3

source

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

EmitPUSH4

source

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

EmitPUSH5

source

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

EmitPUSH6

source

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

EmitPUSH7

source

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

EmitPUSH8

source

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

EmitPUSH9

source

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

EmitPUSH10

source

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

EmitPUSH11

source

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

EmitPUSH12

source

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

EmitPUSH13

source

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

EmitPUSH14

source

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

EmitPUSH15

source

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

EmitPUSH16

source

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

EmitPUSH17

source

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

EmitPUSH18

source

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

EmitPUSH19

source

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

EmitPUSH20

source

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

EmitPUSH21

source

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

EmitPUSH22

source

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

EmitPUSH23

source

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

EmitPUSH24

source

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

EmitPUSH25

source

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

EmitPUSH26

source

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

EmitPUSH27

source

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

EmitPUSH28

source

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

EmitPUSH29

source

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

EmitPUSH30

source

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

EmitPUSH31

source

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

EmitPUSH32

source

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

EmitDUP1

source

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

EmitDUP2

source

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

EmitDUP3

source

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

EmitDUP4

source

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

EmitDUP5

source

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

EmitDUP6

source

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

EmitDUP7

source

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

EmitDUP8

source

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

EmitDUP9

source

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

EmitDUP10

source

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

EmitDUP11

source

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

EmitDUP12

source

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

EmitDUP13

source

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

EmitDUP14

source

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

EmitDUP15

source

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

EmitDUP16

source

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

EmitSWAP1

source

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

EmitSWAP2

source

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

EmitSWAP3

source

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

EmitSWAP4

source

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

EmitSWAP5

source

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

EmitSWAP6

source

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

EmitSWAP7

source

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

EmitSWAP8

source

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

EmitSWAP9

source

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

EmitSWAP10

source

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

EmitSWAP11

source

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

EmitSWAP12

source

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

EmitSWAP13

source

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

EmitSWAP14

source

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

EmitSWAP15

source

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

EmitSWAP16

source

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

EmitLOG0

source

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

EmitLOG1

source

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

EmitLOG2

source

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

EmitLOG3

source

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

EmitLOG4

source

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

EmitCREATE

source

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

EmitCALL

source

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

EmitCALLCODE

source

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

EmitRETURN

source

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

EmitDELEGATECALL

source

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

EmitCREATE2

source

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

EmitSTATICCALL

source

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

EmitREVERT

source

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

EmitINVALID

source

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

EmitSELFDESTRUCT

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.

source§

impl<T> Instrument for T

source§

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

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

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.
source§

impl<T> WithSubscriber for T

source§

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
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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