Skip to main content

FunctionBuilder

Struct FunctionBuilder 

Source
pub struct FunctionBuilder<'a> { /* private fields */ }
Expand description

A builder for constructing MIR functions.

Implementations§

Source§

impl<'a> FunctionBuilder<'a>

Source

pub fn new(func: &'a mut Function) -> FunctionBuilder<'a>

Creates a new function builder.

Source

pub const fn current_block(&self) -> BlockId

Returns the current block.

Source

pub fn switch_to_block(&mut self, block: BlockId)

Switches to a different block.

Source

pub fn create_block(&mut self) -> BlockId

Creates a new basic block.

Source

pub fn add_param(&mut self, ty: MirType) -> ValueId

Adds an argument to the function.

Source

pub fn add_return(&mut self, ty: MirType)

Adds a return type to the function.

Source

pub fn imm_u256(&mut self, value: Uint<256, 4>) -> ValueId

Creates an immediate value.

Source

pub fn imm_u64(&mut self, value: u64) -> ValueId

Creates a u64 immediate value.

Source

pub fn imm_bool(&mut self, value: bool) -> ValueId

Creates a boolean immediate.

Source

pub fn undef(&mut self, ty: MirType) -> ValueId

Creates an undefined value.

Source

pub fn error_value(&mut self, guar: ErrorGuaranteed) -> ValueId

Creates an error sentinel value for an already-reported lowering error.

Source

pub fn add(&mut self, a: ValueId, b: ValueId) -> ValueId

Emits an add instruction.

Source

pub fn sub(&mut self, a: ValueId, b: ValueId) -> ValueId

Emits a sub instruction.

Source

pub fn mul(&mut self, a: ValueId, b: ValueId) -> ValueId

Emits a mul instruction.

Source

pub fn div(&mut self, a: ValueId, b: ValueId) -> ValueId

Emits a div instruction.

Source

pub fn sdiv(&mut self, a: ValueId, b: ValueId) -> ValueId

Emits a sdiv instruction.

Source

pub fn mod_(&mut self, a: ValueId, b: ValueId) -> ValueId

Emits a mod instruction.

Source

pub fn addmod(&mut self, a: ValueId, b: ValueId, n: ValueId) -> ValueId

Emits an addmod instruction.

Source

pub fn mulmod(&mut self, a: ValueId, b: ValueId, n: ValueId) -> ValueId

Emits a mulmod instruction.

Source

pub fn smod(&mut self, a: ValueId, b: ValueId) -> ValueId

Emits a smod instruction.

Source

pub fn exp(&mut self, a: ValueId, b: ValueId) -> ValueId

Emits an exp instruction.

Source

pub fn and(&mut self, a: ValueId, b: ValueId) -> ValueId

Emits an and instruction.

Source

pub fn or(&mut self, a: ValueId, b: ValueId) -> ValueId

Emits an or instruction.

Source

pub fn xor(&mut self, a: ValueId, b: ValueId) -> ValueId

Emits a xor instruction.

Source

pub fn not(&mut self, a: ValueId) -> ValueId

Emits a not instruction.

Source

pub fn shl(&mut self, shift: ValueId, value: ValueId) -> ValueId

Emits a shl instruction.

Source

pub fn shr(&mut self, shift: ValueId, value: ValueId) -> ValueId

Emits a shr instruction.

Source

pub fn sar(&mut self, shift: ValueId, value: ValueId) -> ValueId

Emits a sar instruction.

Source

pub fn lt(&mut self, a: ValueId, b: ValueId) -> ValueId

Emits a lt instruction.

Source

pub fn gt(&mut self, a: ValueId, b: ValueId) -> ValueId

Emits a gt instruction.

Source

pub fn slt(&mut self, a: ValueId, b: ValueId) -> ValueId

Emits a slt instruction.

Source

pub fn sgt(&mut self, a: ValueId, b: ValueId) -> ValueId

Emits a sgt instruction.

Source

pub fn eq(&mut self, a: ValueId, b: ValueId) -> ValueId

Emits an eq instruction.

Source

pub fn iszero(&mut self, a: ValueId) -> ValueId

Emits an iszero instruction.

Source

pub fn byte(&mut self, index: ValueId, value: ValueId) -> ValueId

Emits a byte instruction.

Source

pub fn signextend(&mut self, size: ValueId, value: ValueId) -> ValueId

Emits a signextend instruction.

Source

pub fn mload(&mut self, offset: ValueId) -> ValueId

Emits an mload instruction.

Source

pub fn mstore(&mut self, offset: ValueId, value: ValueId)

Emits an mstore instruction.

Source

pub fn mstore8(&mut self, offset: ValueId, value: ValueId)

Emits an mstore8 instruction.

Source

pub fn msize(&mut self) -> ValueId

Emits an msize instruction.

Source

pub fn mcopy(&mut self, dest: ValueId, src: ValueId, len: ValueId)

Emits an mcopy instruction.

Source

pub fn sload(&mut self, slot: ValueId) -> ValueId

Emits an sload instruction.

Source

pub fn sstore(&mut self, slot: ValueId, value: ValueId)

Emits an sstore instruction.

Source

pub fn tload(&mut self, slot: ValueId) -> ValueId

Emits a tload instruction.

Source

pub fn tstore(&mut self, slot: ValueId, value: ValueId)

Emits a tstore instruction.

Source

pub fn calldataload(&mut self, offset: ValueId) -> ValueId

Emits a calldataload instruction.

Source

pub fn calldatasize(&mut self) -> ValueId

Emits a calldatasize instruction.

Source

pub fn calldatacopy(&mut self, dest: ValueId, offset: ValueId, size: ValueId)

Emits a calldatacopy instruction.

Source

pub fn codesize(&mut self) -> ValueId

Emits a codesize instruction.

Source

pub fn extcodesize(&mut self, addr: ValueId) -> ValueId

Emits an extcodesize instruction.

Source

pub fn load_immutable(&mut self, offset: u32) -> ValueId

Emits a loadimmutable instruction for the immutable at offset.

Source

pub fn extcodecopy( &mut self, addr: ValueId, dest: ValueId, offset: ValueId, size: ValueId, )

Emits an extcodecopy instruction.

Source

pub fn extcodehash(&mut self, addr: ValueId) -> ValueId

Emits an extcodehash instruction.

Source

pub fn returndatasize(&mut self) -> ValueId

Emits a returndatasize instruction.

Source

pub fn returndatacopy(&mut self, dest: ValueId, offset: ValueId, size: ValueId)

Emits a returndatacopy instruction.

Source

pub fn internal_call( &mut self, function: FunctionId, args: Vec<ValueId>, result_ty: MirType, returns: usize, ) -> ValueId

Emits an internal function call.

Source

pub fn internal_call_void( &mut self, function: FunctionId, args: Vec<ValueId>, returns: usize, )

Emits an internal function call whose result, if any, is not used as a value.

Source

pub fn internal_frame_addr(&mut self, offset: u64) -> ValueId

Emits an address inside the current internal-call frame.

Source

pub fn caller(&mut self) -> ValueId

Emits a caller instruction.

Source

pub fn callvalue(&mut self) -> ValueId

Emits a callvalue instruction.

Source

pub fn origin(&mut self) -> ValueId

Emits an origin instruction.

Source

pub fn gasprice(&mut self) -> ValueId

Emits a gasprice instruction.

Source

pub fn blockhash(&mut self, block_num: ValueId) -> ValueId

Emits a blockhash instruction.

Source

pub fn coinbase(&mut self) -> ValueId

Emits a coinbase instruction.

Source

pub fn timestamp(&mut self) -> ValueId

Emits a timestamp instruction.

Source

pub fn number(&mut self) -> ValueId

Emits a number instruction.

Source

pub fn prevrandao(&mut self) -> ValueId

Emits a prevrandao instruction.

Source

pub fn gaslimit(&mut self) -> ValueId

Emits a gaslimit instruction.

Source

pub fn chainid(&mut self) -> ValueId

Emits a chainid instruction.

Source

pub fn address(&mut self) -> ValueId

Emits an address instruction.

Source

pub fn balance(&mut self, addr: ValueId) -> ValueId

Emits a balance instruction.

Source

pub fn selfbalance(&mut self) -> ValueId

Emits a selfbalance instruction.

Source

pub fn gas(&mut self) -> ValueId

Emits a gas instruction.

Source

pub fn keccak256(&mut self, offset: ValueId, size: ValueId) -> ValueId

Emits a keccak256 instruction.

Source

pub fn basefee(&mut self) -> ValueId

Emits a basefee instruction.

Source

pub fn blobbasefee(&mut self) -> ValueId

Emits a blobbasefee instruction.

Source

pub fn blobhash(&mut self, index: ValueId) -> ValueId

Emits a blobhash instruction.

Source

pub fn call( &mut self, gas: ValueId, addr: ValueId, value: ValueId, args_offset: ValueId, args_size: ValueId, ret_offset: ValueId, ret_size: ValueId, ) -> ValueId

Emits a call instruction (external call).

Source

pub fn staticcall( &mut self, gas: ValueId, addr: ValueId, args_offset: ValueId, args_size: ValueId, ret_offset: ValueId, ret_size: ValueId, ) -> ValueId

Emits a staticcall instruction (read-only external call).

Source

pub fn delegatecall( &mut self, gas: ValueId, addr: ValueId, args_offset: ValueId, args_size: ValueId, ret_offset: ValueId, ret_size: ValueId, ) -> ValueId

Emits a delegatecall instruction (call with caller’s context).

Source

pub fn create( &mut self, value: ValueId, offset: ValueId, size: ValueId, ) -> ValueId

Emits a create instruction (deploy a contract).

Source

pub fn create2( &mut self, value: ValueId, offset: ValueId, size: ValueId, salt: ValueId, ) -> ValueId

Emits a create2 instruction (deploy a contract with salt).

Source

pub fn codecopy(&mut self, dest: ValueId, offset: ValueId, size: ValueId)

Emits a codecopy instruction.

Source

pub fn log0(&mut self, offset: ValueId, size: ValueId)

Emits a log0 instruction (event with no topics).

Source

pub fn log1(&mut self, offset: ValueId, size: ValueId, topic1: ValueId)

Emits a log1 instruction (event with 1 topic).

Source

pub fn log2( &mut self, offset: ValueId, size: ValueId, topic1: ValueId, topic2: ValueId, )

Emits a log2 instruction (event with 2 topics).

Source

pub fn log3( &mut self, offset: ValueId, size: ValueId, topic1: ValueId, topic2: ValueId, topic3: ValueId, )

Emits a log3 instruction (event with 3 topics).

Source

pub fn log4( &mut self, offset: ValueId, size: ValueId, topic1: ValueId, topic2: ValueId, topic3: ValueId, topic4: ValueId, )

Emits a log4 instruction (event with 4 topics).

Source

pub fn select( &mut self, cond: ValueId, then_val: ValueId, else_val: ValueId, ) -> ValueId

Emits a select instruction.

Source

pub fn phi(&mut self, incoming: Vec<(BlockId, ValueId)>) -> ValueId

Emits a phi instruction. incoming pairs each predecessor block of the current block with the value the phi takes when control arrives from that block. Emit phis before any other instruction in their block.

Source

pub fn add_phi_incoming(&mut self, phi: ValueId, block: BlockId, value: ValueId)

Adds an incoming (block, value) edge to an existing phi. This is used to patch loop-carried phis whose back-edge values are only known after the loop body has been built.

§Panics

Panics if phi does not refer to a phi instruction result.

Source

pub fn jump(&mut self, target: BlockId)

Sets a jump terminator.

Source

pub fn branch( &mut self, condition: ValueId, then_block: BlockId, else_block: BlockId, )

Sets a branch terminator.

Source

pub fn switch( &mut self, value: ValueId, default: BlockId, cases: Vec<(ValueId, BlockId)>, )

Sets a switch terminator.

Source

pub fn ret(&mut self, values: impl IntoIterator<Item = ValueId>)

Sets a return terminator.

Source

pub fn revert(&mut self, offset: ValueId, size: ValueId)

Sets a revert terminator.

Source

pub fn ret_data(&mut self, offset: ValueId, size: ValueId)

Sets a return-data terminator: RETURN(offset, size).

Source

pub fn stop(&mut self)

Sets a stop terminator.

Source

pub fn invalid(&mut self)

Sets an invalid terminator.

Source

pub fn selfdestruct(&mut self, recipient: ValueId)

Sets a selfdestruct terminator.

Source

pub fn func(&self) -> &Function

Returns a reference to the function.

Source

pub fn func_mut(&mut self) -> &mut Function

Returns a mutable reference to the function.

Auto Trait Implementations§

§

impl<'a> !UnwindSafe for FunctionBuilder<'a>

§

impl<'a> Freeze for FunctionBuilder<'a>

§

impl<'a> RefUnwindSafe for FunctionBuilder<'a>

§

impl<'a> Send for FunctionBuilder<'a>

§

impl<'a> Sync for FunctionBuilder<'a>

§

impl<'a> Unpin for FunctionBuilder<'a>

§

impl<'a> UnsafeUnpin for FunctionBuilder<'a>

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, R> CollectAndApply<T, R> for T

Source§

fn collect_and_apply<I, F>(iter: I, f: F) -> R
where I: Iterator<Item = T>, F: FnOnce(&[T]) -> R,

Equivalent to f(&iter.collect::<Vec<_>>()).

Source§

type Output = R

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

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

Source§

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