pub struct Function {
    pub name: UserFuncName,
    pub stencil: FunctionStencil,
    pub params: FunctionParameters,
}
Expand description

Functions can be cloned, but it is not a very fast operation. The clone will have all the same entity numbers as the original.

Fields§

§name: UserFuncName

Name of this function.

Mostly used by .clif files, only there for debugging / naming purposes.

§stencil: FunctionStencil

All the fields required for compiling a function, independently of details irrelevant to compilation and that are stored in the FunctionParameters params field instead.

§params: FunctionParameters

All the parameters that can be applied onto the function stencil, that is, that don’t matter when caching compilation artifacts.

Implementations§

source§

impl Function

source

pub fn with_name_signature(name: UserFuncName, sig: Signature) -> Self

Create a function with the given name and signature.

source

pub fn clear(&mut self)

Clear all data structures in this function.

source

pub fn new() -> Self

Create a new empty, anonymous function with a Fast calling convention.

source

pub fn display(&self) -> DisplayFunction<'_>

Return an object that can display this function with correct ISA-specific annotations.

source

pub fn display_with<'a>( &'a self, annotations: DisplayFunctionAnnotations<'a> ) -> DisplayFunction<'a>

Return an object that can display this function with correct ISA-specific annotations.

source

pub fn set_srcloc(&mut self, inst: Inst, srcloc: SourceLoc)

Sets an absolute source location for the given instruction.

If no base source location has been set yet, records it at the same time.

source

pub fn srcloc(&self, inst: Inst) -> SourceLoc

Returns an absolute source location for the given instruction.

source

pub fn declare_imported_user_function( &mut self, name: UserExternalName ) -> UserExternalNameRef

Declare a user-defined external function import, to be referenced in ExtFuncData::User later.

source

pub fn import_function(&mut self, data: ExtFuncData) -> FuncRef

Declare an external function import.

Methods from Deref<Target = FunctionStencil>§

source

pub fn create_jump_table(&mut self, data: JumpTableData) -> JumpTable

Creates a jump table in the function, to be used by br_table instructions.

source

pub fn create_sized_stack_slot(&mut self, data: StackSlotData) -> StackSlot

Creates a sized stack slot in the function, to be used by stack_load, stack_store and stack_addr instructions.

source

pub fn create_dynamic_stack_slot( &mut self, data: DynamicStackSlotData ) -> DynamicStackSlot

Creates a dynamic stack slot in the function, to be used by dynamic_stack_load, dynamic_stack_store and dynamic_stack_addr instructions.

source

pub fn import_signature(&mut self, signature: Signature) -> SigRef

Adds a signature which can later be used to declare an external function import.

source

pub fn create_global_value(&mut self, data: GlobalValueData) -> GlobalValue

Declares a global value accessible to the function.

source

pub fn get_dyn_scale(&self, ty: DynamicType) -> GlobalValue

Find the global dyn_scale value associated with given DynamicType

source

pub fn get_dynamic_slot_scale(&self, dss: DynamicStackSlot) -> GlobalValue

Find the global dyn_scale for the given stack slot.

source

pub fn get_concrete_dynamic_ty(&self, ty: DynamicType) -> Option<Type>

Get a concrete Type from a user defined DynamicType.

source

pub fn create_heap(&mut self, data: HeapData) -> Heap

Declares a heap accessible to the function.

source

pub fn create_table(&mut self, data: TableData) -> Table

Declares a table accessible to the function.

source

pub fn special_param(&self, purpose: ArgumentPurpose) -> Option<Value>

Find a presumed unique special-purpose function parameter value.

Returns the value of the last purpose parameter, or None if no such parameter exists.

source

pub fn collect_debug_info(&mut self)

Starts collection of debug information.

source

pub fn change_branch_destination(&mut self, inst: Inst, new_dest: Block)

Changes the destination of a jump or branch instruction. Does nothing if called with a non-jump or non-branch instruction.

Note that this method ignores multi-destination branches like br_table.

source

pub fn rewrite_branch_destination( &mut self, inst: Inst, old_dest: Block, new_dest: Block )

Rewrite the branch destination to new_dest if the destination matches old_dest. Does nothing if called with a non-jump or non-branch instruction.

Unlike change_branch_destination, this method rewrite the destinations of multi-destination branches like br_table.

source

pub fn is_block_basic(&self, block: Block) -> Result<(), (Inst, &'static str)>

Checks that the specified block can be encoded as a basic block.

On error, returns the first invalid instruction and an error message.

source

pub fn is_leaf(&self) -> bool

Returns true if the function is function that doesn’t call any other functions. This is not to be confused with a “leaf function” in Windows terminology.

source

pub fn transplant_inst(&mut self, dst: Inst, src: Inst)

Replace the dst instruction’s data with the src instruction’s data and then remove src.

src and its result values should not be used at all, as any uses would be left dangling after calling this method.

src and dst must have the same number of resulting values, and src’s i^th value must have the same type as dst’s i^th value.

source

pub fn fixed_stack_size(&self) -> u32

Size occupied by all stack slots associated with this function.

Does not include any padding necessary due to offsets

Trait Implementations§

source§

impl Clone for Function

source§

fn clone(&self) -> Function

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Function

source§

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Deref for Function

§

type Target = FunctionStencil

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl DerefMut for Function

source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
source§

impl Display for Function

source§

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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, U> Into<U> for Twhere 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> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere 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 Twhere 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.