pub struct FunctionBuilder<'a> { /* private fields */ }Expand description
A builder for constructing MIR functions.
Implementations§
Source§impl<'a> FunctionBuilder<'a>
impl<'a> FunctionBuilder<'a>
Sourcepub fn new(func: &'a mut Function) -> FunctionBuilder<'a>
pub fn new(func: &'a mut Function) -> FunctionBuilder<'a>
Creates a new function builder.
Sourcepub const fn current_block(&self) -> BlockId
pub const fn current_block(&self) -> BlockId
Returns the current block.
Sourcepub fn switch_to_block(&mut self, block: BlockId)
pub fn switch_to_block(&mut self, block: BlockId)
Switches to a different block.
Sourcepub fn create_block(&mut self) -> BlockId
pub fn create_block(&mut self) -> BlockId
Creates a new basic block.
Sourcepub fn add_return(&mut self, ty: MirType)
pub fn add_return(&mut self, ty: MirType)
Adds a return type to the function.
Sourcepub fn error_value(&mut self, guar: ErrorGuaranteed) -> ValueId
pub fn error_value(&mut self, guar: ErrorGuaranteed) -> ValueId
Creates an error sentinel value for an already-reported lowering error.
Sourcepub fn addmod(&mut self, a: ValueId, b: ValueId, n: ValueId) -> ValueId
pub fn addmod(&mut self, a: ValueId, b: ValueId, n: ValueId) -> ValueId
Emits an addmod instruction.
Sourcepub fn mulmod(&mut self, a: ValueId, b: ValueId, n: ValueId) -> ValueId
pub fn mulmod(&mut self, a: ValueId, b: ValueId, n: ValueId) -> ValueId
Emits a mulmod instruction.
Sourcepub fn signextend(&mut self, size: ValueId, value: ValueId) -> ValueId
pub fn signextend(&mut self, size: ValueId, value: ValueId) -> ValueId
Emits a signextend instruction.
Sourcepub fn calldataload(&mut self, offset: ValueId) -> ValueId
pub fn calldataload(&mut self, offset: ValueId) -> ValueId
Emits a calldataload instruction.
Sourcepub fn calldatasize(&mut self) -> ValueId
pub fn calldatasize(&mut self) -> ValueId
Emits a calldatasize instruction.
Sourcepub fn calldatacopy(&mut self, dest: ValueId, offset: ValueId, size: ValueId)
pub fn calldatacopy(&mut self, dest: ValueId, offset: ValueId, size: ValueId)
Emits a calldatacopy instruction.
Sourcepub fn extcodesize(&mut self, addr: ValueId) -> ValueId
pub fn extcodesize(&mut self, addr: ValueId) -> ValueId
Emits an extcodesize instruction.
Sourcepub fn load_immutable(&mut self, offset: u32) -> ValueId
pub fn load_immutable(&mut self, offset: u32) -> ValueId
Emits a loadimmutable instruction for the immutable at offset.
Sourcepub fn extcodecopy(
&mut self,
addr: ValueId,
dest: ValueId,
offset: ValueId,
size: ValueId,
)
pub fn extcodecopy( &mut self, addr: ValueId, dest: ValueId, offset: ValueId, size: ValueId, )
Emits an extcodecopy instruction.
Sourcepub fn extcodehash(&mut self, addr: ValueId) -> ValueId
pub fn extcodehash(&mut self, addr: ValueId) -> ValueId
Emits an extcodehash instruction.
Sourcepub fn returndatasize(&mut self) -> ValueId
pub fn returndatasize(&mut self) -> ValueId
Emits a returndatasize instruction.
Sourcepub fn returndatacopy(&mut self, dest: ValueId, offset: ValueId, size: ValueId)
pub fn returndatacopy(&mut self, dest: ValueId, offset: ValueId, size: ValueId)
Emits a returndatacopy instruction.
Sourcepub fn internal_call(
&mut self,
function: FunctionId,
args: Vec<ValueId>,
result_ty: MirType,
returns: usize,
) -> ValueId
pub fn internal_call( &mut self, function: FunctionId, args: Vec<ValueId>, result_ty: MirType, returns: usize, ) -> ValueId
Emits an internal function call.
Sourcepub fn internal_call_void(
&mut self,
function: FunctionId,
args: Vec<ValueId>,
returns: usize,
)
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.
Sourcepub fn internal_frame_addr(&mut self, offset: u64) -> ValueId
pub fn internal_frame_addr(&mut self, offset: u64) -> ValueId
Emits an address inside the current internal-call frame.
Sourcepub fn prevrandao(&mut self) -> ValueId
pub fn prevrandao(&mut self) -> ValueId
Emits a prevrandao instruction.
Sourcepub fn selfbalance(&mut self) -> ValueId
pub fn selfbalance(&mut self) -> ValueId
Emits a selfbalance instruction.
Sourcepub fn keccak256(&mut self, offset: ValueId, size: ValueId) -> ValueId
pub fn keccak256(&mut self, offset: ValueId, size: ValueId) -> ValueId
Emits a keccak256 instruction.
Sourcepub fn blobbasefee(&mut self) -> ValueId
pub fn blobbasefee(&mut self) -> ValueId
Emits a blobbasefee instruction.
Sourcepub fn call(
&mut self,
gas: ValueId,
addr: ValueId,
value: ValueId,
args_offset: ValueId,
args_size: ValueId,
ret_offset: ValueId,
ret_size: ValueId,
) -> ValueId
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).
Sourcepub fn staticcall(
&mut self,
gas: ValueId,
addr: ValueId,
args_offset: ValueId,
args_size: ValueId,
ret_offset: ValueId,
ret_size: ValueId,
) -> ValueId
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).
Sourcepub fn delegatecall(
&mut self,
gas: ValueId,
addr: ValueId,
args_offset: ValueId,
args_size: ValueId,
ret_offset: ValueId,
ret_size: ValueId,
) -> ValueId
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).
Sourcepub fn create(
&mut self,
value: ValueId,
offset: ValueId,
size: ValueId,
) -> ValueId
pub fn create( &mut self, value: ValueId, offset: ValueId, size: ValueId, ) -> ValueId
Emits a create instruction (deploy a contract).
Sourcepub fn create2(
&mut self,
value: ValueId,
offset: ValueId,
size: ValueId,
salt: ValueId,
) -> ValueId
pub fn create2( &mut self, value: ValueId, offset: ValueId, size: ValueId, salt: ValueId, ) -> ValueId
Emits a create2 instruction (deploy a contract with salt).
Sourcepub fn codecopy(&mut self, dest: ValueId, offset: ValueId, size: ValueId)
pub fn codecopy(&mut self, dest: ValueId, offset: ValueId, size: ValueId)
Emits a codecopy instruction.
Sourcepub fn log0(&mut self, offset: ValueId, size: ValueId)
pub fn log0(&mut self, offset: ValueId, size: ValueId)
Emits a log0 instruction (event with no topics).
Sourcepub fn log1(&mut self, offset: ValueId, size: ValueId, topic1: ValueId)
pub fn log1(&mut self, offset: ValueId, size: ValueId, topic1: ValueId)
Emits a log1 instruction (event with 1 topic).
Sourcepub fn log2(
&mut self,
offset: ValueId,
size: ValueId,
topic1: ValueId,
topic2: ValueId,
)
pub fn log2( &mut self, offset: ValueId, size: ValueId, topic1: ValueId, topic2: ValueId, )
Emits a log2 instruction (event with 2 topics).
Sourcepub fn log3(
&mut self,
offset: ValueId,
size: ValueId,
topic1: ValueId,
topic2: ValueId,
topic3: ValueId,
)
pub fn log3( &mut self, offset: ValueId, size: ValueId, topic1: ValueId, topic2: ValueId, topic3: ValueId, )
Emits a log3 instruction (event with 3 topics).
Sourcepub fn log4(
&mut self,
offset: ValueId,
size: ValueId,
topic1: ValueId,
topic2: ValueId,
topic3: ValueId,
topic4: ValueId,
)
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).
Sourcepub fn select(
&mut self,
cond: ValueId,
then_val: ValueId,
else_val: ValueId,
) -> ValueId
pub fn select( &mut self, cond: ValueId, then_val: ValueId, else_val: ValueId, ) -> ValueId
Emits a select instruction.
Sourcepub fn phi(&mut self, incoming: Vec<(BlockId, ValueId)>) -> ValueId
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.
Sourcepub fn add_phi_incoming(&mut self, phi: ValueId, block: BlockId, value: ValueId)
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.
Sourcepub fn branch(
&mut self,
condition: ValueId,
then_block: BlockId,
else_block: BlockId,
)
pub fn branch( &mut self, condition: ValueId, then_block: BlockId, else_block: BlockId, )
Sets a branch terminator.
Sourcepub fn switch(
&mut self,
value: ValueId,
default: BlockId,
cases: Vec<(ValueId, BlockId)>,
)
pub fn switch( &mut self, value: ValueId, default: BlockId, cases: Vec<(ValueId, BlockId)>, )
Sets a switch terminator.
Sourcepub fn ret(&mut self, values: impl IntoIterator<Item = ValueId>)
pub fn ret(&mut self, values: impl IntoIterator<Item = ValueId>)
Sets a return terminator.
Sourcepub fn ret_data(&mut self, offset: ValueId, size: ValueId)
pub fn ret_data(&mut self, offset: ValueId, size: ValueId)
Sets a return-data terminator: RETURN(offset, size).
Sourcepub fn selfdestruct(&mut self, recipient: ValueId)
pub fn selfdestruct(&mut self, recipient: ValueId)
Sets a selfdestruct terminator.
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T, R> CollectAndApply<T, R> for T
impl<T, R> CollectAndApply<T, R> for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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