pub struct Function(pub Index);
Tuple Fields§
§0: Index
Implementations§
source§impl Function
impl Function
sourcepub fn new(
context: &mut Context,
module: Module,
name: String,
args: Vec<(String, Type, Option<MetadataIndex>)>,
return_type: Type,
selector: Option<[u8; 4]>,
is_public: bool,
is_entry: bool,
metadata: Option<MetadataIndex>
) -> Function
pub fn new( context: &mut Context, module: Module, name: String, args: Vec<(String, Type, Option<MetadataIndex>)>, return_type: Type, selector: Option<[u8; 4]>, is_public: bool, is_entry: bool, metadata: Option<MetadataIndex> ) -> Function
sourcepub fn create_block(&self, context: &mut Context, label: Option<Label>) -> Block
pub fn create_block(&self, context: &mut Context, label: Option<Label>) -> Block
Create and append a new Block
to this function.
sourcepub fn create_block_before(
&self,
context: &mut Context,
other: &Block,
label: Option<Label>
) -> Result<Block, IrError>
pub fn create_block_before( &self, context: &mut Context, other: &Block, label: Option<Label> ) -> Result<Block, IrError>
Create and insert a new Block
into this function.
The new block is inserted before other
.
sourcepub fn create_block_after(
&self,
context: &mut Context,
other: &Block,
label: Option<Label>
) -> Result<Block, IrError>
pub fn create_block_after( &self, context: &mut Context, other: &Block, label: Option<Label> ) -> Result<Block, IrError>
Create and insert a new Block
into this function.
The new block is inserted after other
.
sourcepub fn remove_block(
&self,
context: &mut Context,
block: &Block
) -> Result<(), IrError>
pub fn remove_block( &self, context: &mut Context, block: &Block ) -> Result<(), IrError>
Remove a Block
from this function.
Care must be taken to ensure the block has no predecessors otherwise the function will be made invalid.
sourcepub fn get_unique_label(
&self,
context: &mut Context,
hint: Option<String>
) -> String
pub fn get_unique_label( &self, context: &mut Context, hint: Option<String> ) -> String
Get a new unique block label.
If hint
is None
then the label will be in the form "blockN"
where N is an
incrementing decimal.
Otherwise if the hint is already unique to this function it will be returned. If not already unique it will have N appended to it until it is unique.
sourcepub fn num_blocks(&self, context: &Context) -> usize
pub fn num_blocks(&self, context: &Context) -> usize
Return the number of blocks in this function.
sourcepub fn num_instructions(&self, context: &Context) -> usize
pub fn num_instructions(&self, context: &Context) -> usize
Return the number of instructions in this function.
sourcepub fn get_entry_block(&self, context: &Context) -> Block
pub fn get_entry_block(&self, context: &Context) -> Block
Return the function entry (i.e., the first) block.
sourcepub fn get_metadata(&self, context: &Context) -> Option<MetadataIndex>
pub fn get_metadata(&self, context: &Context) -> Option<MetadataIndex>
Return the attached metadata.
sourcepub fn has_selector(&self, context: &Context) -> bool
pub fn has_selector(&self, context: &Context) -> bool
Whether this function has a valid selector.
sourcepub fn get_selector(&self, context: &Context) -> Option<[u8; 4]>
pub fn get_selector(&self, context: &Context) -> Option<[u8; 4]>
Return the function selector, if it has one.
sourcepub fn is_entry(&self, context: &Context) -> bool
pub fn is_entry(&self, context: &Context) -> bool
Whether or not the function is a program entry point, i.e. main
, #[test]
fns or abi
methods.
pub fn get_return_type(&self, context: &Context) -> Type
pub fn set_return_type(&self, context: &mut Context, new_ret_type: Type)
sourcepub fn get_arg(&self, context: &Context, name: &str) -> Option<Value>
pub fn get_arg(&self, context: &Context, name: &str) -> Option<Value>
Get an arg value by name, if found.
sourcepub fn add_arg<S: Into<String>>(
&self,
context: &mut Context,
name: S,
arg: Value
)
pub fn add_arg<S: Into<String>>( &self, context: &mut Context, name: S, arg: Value )
Append an extra argument to the function signature.
NOTE: arg
must be a BlockArgument
value with the correct index otherwise add_arg
will
panic.
sourcepub fn lookup_arg_name<'a>(
&self,
context: &'a Context,
value: &Value
) -> Option<&'a String>
pub fn lookup_arg_name<'a>( &self, context: &'a Context, value: &Value ) -> Option<&'a String>
Find the name of an arg by value.
sourcepub fn args_iter<'a>(
&self,
context: &'a Context
) -> impl Iterator<Item = &'a (String, Value)>
pub fn args_iter<'a>( &self, context: &'a Context ) -> impl Iterator<Item = &'a (String, Value)>
Return an iterator for each of the function arguments.
sourcepub fn get_local_var(&self, context: &Context, name: &str) -> Option<LocalVar>
pub fn get_local_var(&self, context: &Context, name: &str) -> Option<LocalVar>
Get a pointer to a local value by name, if found.
sourcepub fn lookup_local_name<'a>(
&self,
context: &'a Context,
var: &LocalVar
) -> Option<&'a String>
pub fn lookup_local_name<'a>( &self, context: &'a Context, var: &LocalVar ) -> Option<&'a String>
Find the name of a local value by pointer.
sourcepub fn new_local_var(
&self,
context: &mut Context,
name: String,
local_type: Type,
initializer: Option<Constant>,
mutable: bool
) -> Result<LocalVar, IrError>
pub fn new_local_var( &self, context: &mut Context, name: String, local_type: Type, initializer: Option<Constant>, mutable: bool ) -> Result<LocalVar, IrError>
Add a value to the function local storage.
The name must be unique to this function else an error is returned.
sourcepub fn new_unique_local_var(
&self,
context: &mut Context,
name: String,
local_type: Type,
initializer: Option<Constant>,
mutable: bool
) -> LocalVar
pub fn new_unique_local_var( &self, context: &mut Context, name: String, local_type: Type, initializer: Option<Constant>, mutable: bool ) -> LocalVar
Add a value to the function local storage, by forcing the name to be unique if needed.
Will use the provided name as a hint and rename to guarantee insertion.
sourcepub fn locals_iter<'a>(
&self,
context: &'a Context
) -> impl Iterator<Item = (&'a String, &'a LocalVar)>
pub fn locals_iter<'a>( &self, context: &'a Context ) -> impl Iterator<Item = (&'a String, &'a LocalVar)>
Return an iterator to all of the values in this function’s local storage.
sourcepub fn remove_locals(&self, context: &mut Context, removals: &Vec<String>)
pub fn remove_locals(&self, context: &mut Context, removals: &Vec<String>)
Remove given list of locals
sourcepub fn merge_locals_from(
&self,
context: &mut Context,
other: Function
) -> HashMap<LocalVar, LocalVar>
pub fn merge_locals_from( &self, context: &mut Context, other: Function ) -> HashMap<LocalVar, LocalVar>
Merge values from another Function
into this one.
The names of the merged values are guaranteed to be unique via the use of
Function::new_unique_local_var
.
Returns a map from the original pointers to the newly merged pointers.
sourcepub fn block_iter(&self, context: &Context) -> BlockIterator ⓘ
pub fn block_iter(&self, context: &Context) -> BlockIterator ⓘ
Return an iterator to each block in this function.
sourcepub fn instruction_iter<'a>(
&self,
context: &'a Context
) -> impl Iterator<Item = (Block, Value)> + 'a
pub fn instruction_iter<'a>( &self, context: &'a Context ) -> impl Iterator<Item = (Block, Value)> + 'a
Return an iterator to each instruction in each block in this function.
This is a convenience method for when all instructions in a function need to be inspected. The instruction value is returned from the iterator along with the block it belongs to.
sourcepub fn replace_values(
&self,
context: &mut Context,
replace_map: &FxHashMap<Value, Value>,
starting_block: Option<Block>
)
pub fn replace_values( &self, context: &mut Context, replace_map: &FxHashMap<Value, Value>, starting_block: Option<Block> )
Replace a value with another within this function.
This is a convenience method which iterates over this function’s blocks and calls
Block::replace_values
in turn.
starting_block
is an optimisation for when the first possible reference to old_val
is
known.
pub fn replace_value( &self, context: &mut Context, old_val: Value, new_val: Value, starting_block: Option<Block> )
Trait Implementations§
source§impl PartialEq<Function> for Function
impl PartialEq<Function> for Function
impl Copy for Function
impl Eq for Function
impl StructuralEq for Function
impl StructuralPartialEq for Function
Auto Trait Implementations§
impl RefUnwindSafe for Function
impl Send for Function
impl Sync for Function
impl Unpin for Function
impl UnwindSafe for Function
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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere T: Any,
source§fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.