pub struct Function(pub Index);
Tuple Fields
0: Index
Implementations
sourceimpl 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
) -> 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
) -> 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 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 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 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 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 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_ptr(&self, context: &Context, name: &str) -> Option<Pointer>
pub fn get_local_ptr(&self, context: &Context, name: &str) -> Option<Pointer>
Get a pointer to a local value by name, if found.
sourcepub fn lookup_local_name<'a>(
&self,
context: &'a Context,
ptr: &Pointer
) -> Option<&'a String>
pub fn lookup_local_name<'a>(
&self,
context: &'a Context,
ptr: &Pointer
) -> Option<&'a String>
Find the name of a local value by pointer.
sourcepub fn new_local_ptr(
&self,
context: &mut Context,
name: String,
local_type: Type,
is_mutable: bool,
initializer: Option<Constant>
) -> Result<Pointer, IrError>
pub fn new_local_ptr(
&self,
context: &mut Context,
name: String,
local_type: Type,
is_mutable: bool,
initializer: Option<Constant>
) -> Result<Pointer, 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_ptr(
&self,
context: &mut Context,
name: String,
local_type: Type,
is_mutable: bool,
initializer: Option<Constant>
) -> Pointer
pub fn new_unique_local_ptr(
&self,
context: &mut Context,
name: String,
local_type: Type,
is_mutable: bool,
initializer: Option<Constant>
) -> Pointer
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 Pointer)>
pub fn locals_iter<'a>(
&self,
context: &'a Context
) -> impl Iterator<Item = (&'a String, &'a Pointer)>
Return an iterator to all of the values in this function’s local storage.
sourcepub fn merge_locals_from(
&self,
context: &mut Context,
other: Function
) -> Result<HashMap<Pointer, Pointer>, IrError>
pub fn merge_locals_from(
&self,
context: &mut Context,
other: Function
) -> Result<HashMap<Pointer, Pointer>, IrError>
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_ptr
.
Returns a map from the original pointers to the newly merged pointers.
XXX This function returns a Result but can’t actually fail?
sourcepub fn block_iter(&self, context: &Context) -> BlockIteratorⓘNotable traits for BlockIteratorimpl Iterator for BlockIterator type Item = Block;
pub fn block_iter(&self, context: &Context) -> BlockIteratorⓘNotable traits for BlockIteratorimpl Iterator for BlockIterator type Item = Block;
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_value(
&self,
context: &mut Context,
old_val: Value,
new_val: Value,
starting_block: Option<Block>
)
pub fn replace_value(
&self,
context: &mut Context,
old_val: Value,
new_val: 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_value
in turn.
starting_block
is an optimisation for when the first possible reference to old_val
is
known.
Trait Implementations
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more