inkwell::values

Struct FunctionValue

source
pub struct FunctionValue<'ctx> { /* private fields */ }

Implementations§

source§

impl<'ctx> FunctionValue<'ctx>

source

pub unsafe fn new(value: LLVMValueRef) -> Option<Self>

Get a value from an LLVMValueRef.

§Safety

The ref must be valid and of type function.

source

pub fn get_linkage(self) -> Linkage

source

pub fn set_linkage(self, linkage: Linkage)

source

pub fn is_null(self) -> bool

source

pub fn is_undef(self) -> bool

source

pub fn print_to_stderr(self)

source

pub fn verify(self, print: bool) -> bool

source

pub fn get_next_function(self) -> Option<Self>

source

pub fn get_previous_function(self) -> Option<Self>

source

pub fn get_first_param(self) -> Option<BasicValueEnum<'ctx>>

source

pub fn get_last_param(self) -> Option<BasicValueEnum<'ctx>>

source

pub fn get_first_basic_block(self) -> Option<BasicBlock<'ctx>>

source

pub fn get_nth_param(self, nth: u32) -> Option<BasicValueEnum<'ctx>>

source

pub fn count_params(self) -> u32

source

pub fn count_basic_blocks(self) -> u32

source

pub fn get_basic_block_iter(self) -> BasicBlockIter<'ctx>

source

pub fn get_basic_blocks(self) -> Vec<BasicBlock<'ctx>>

source

pub fn get_param_iter(self) -> ParamValueIter<'ctx>

source

pub fn get_params(self) -> Vec<BasicValueEnum<'ctx>>

source

pub fn get_last_basic_block(self) -> Option<BasicBlock<'ctx>>

source

pub fn get_name(&self) -> &CStr

Gets the name of a FunctionValue.

source

pub fn view_function_cfg(self)

View the control flow graph and produce a .dot file

source

pub fn view_function_cfg_only(self)

Only view the control flow graph

source

pub unsafe fn delete(self)

source

pub fn get_type(self) -> FunctionType<'ctx>

Available on crate features llvm8-0 or llvm9-0 or llvm10-0 or llvm11-0 or llvm12-0 or llvm13-0 or llvm14-0 or llvm15-0 or llvm16-0 or llvm17-0 or llvm18-0 only.
source

pub fn has_personality_function(self) -> bool

source

pub fn get_personality_function(self) -> Option<FunctionValue<'ctx>>

source

pub fn set_personality_function(self, personality_fn: FunctionValue<'ctx>)

source

pub fn get_intrinsic_id(self) -> u32

source

pub fn get_call_conventions(self) -> u32

source

pub fn set_call_conventions(self, call_conventions: u32)

source

pub fn get_gc(&self) -> &CStr

source

pub fn set_gc(self, gc: &str)

source

pub fn replace_all_uses_with(self, other: FunctionValue<'ctx>)

source

pub fn add_attribute(self, loc: AttributeLoc, attribute: Attribute)

Adds an Attribute to a particular location in this FunctionValue.

§Example
use inkwell::attributes::AttributeLoc;
use inkwell::context::Context;

let context = Context::create();
let module = context.create_module("my_mod");
let void_type = context.void_type();
let fn_type = void_type.fn_type(&[], false);
let fn_value = module.add_function("my_fn", fn_type, None);
let string_attribute = context.create_string_attribute("my_key", "my_val");
let enum_attribute = context.create_enum_attribute(1, 1);

fn_value.add_attribute(AttributeLoc::Return, string_attribute);
fn_value.add_attribute(AttributeLoc::Return, enum_attribute);
source

pub fn count_attributes(self, loc: AttributeLoc) -> u32

Counts the number of Attributes belonging to the specified location in this FunctionValue.

§Example
use inkwell::attributes::AttributeLoc;
use inkwell::context::Context;

let context = Context::create();
let module = context.create_module("my_mod");
let void_type = context.void_type();
let fn_type = void_type.fn_type(&[], false);
let fn_value = module.add_function("my_fn", fn_type, None);
let string_attribute = context.create_string_attribute("my_key", "my_val");
let enum_attribute = context.create_enum_attribute(1, 1);

fn_value.add_attribute(AttributeLoc::Return, string_attribute);
fn_value.add_attribute(AttributeLoc::Return, enum_attribute);

assert_eq!(fn_value.count_attributes(AttributeLoc::Return), 2);
source

pub fn attributes(self, loc: AttributeLoc) -> Vec<Attribute>

Get all Attributes belonging to the specified location in this FunctionValue.

§Example
use inkwell::attributes::AttributeLoc;
use inkwell::context::Context;

let context = Context::create();
let module = context.create_module("my_mod");
let void_type = context.void_type();
let fn_type = void_type.fn_type(&[], false);
let fn_value = module.add_function("my_fn", fn_type, None);
let string_attribute = context.create_string_attribute("my_key", "my_val");
let enum_attribute = context.create_enum_attribute(1, 1);

fn_value.add_attribute(AttributeLoc::Return, string_attribute);
fn_value.add_attribute(AttributeLoc::Return, enum_attribute);

assert_eq!(fn_value.attributes(AttributeLoc::Return), vec![string_attribute, enum_attribute]);
source

pub fn remove_string_attribute(self, loc: AttributeLoc, key: &str)

Removes a string Attribute belonging to the specified location in this FunctionValue.

§Example
use inkwell::attributes::AttributeLoc;
use inkwell::context::Context;

let context = Context::create();
let module = context.create_module("my_mod");
let void_type = context.void_type();
let fn_type = void_type.fn_type(&[], false);
let fn_value = module.add_function("my_fn", fn_type, None);
let string_attribute = context.create_string_attribute("my_key", "my_val");

fn_value.add_attribute(AttributeLoc::Return, string_attribute);
fn_value.remove_string_attribute(AttributeLoc::Return, "my_key");
source

pub fn remove_enum_attribute(self, loc: AttributeLoc, kind_id: u32)

Removes an enum Attribute belonging to the specified location in this FunctionValue.

§Example
use inkwell::attributes::AttributeLoc;
use inkwell::context::Context;

let context = Context::create();
let module = context.create_module("my_mod");
let void_type = context.void_type();
let fn_type = void_type.fn_type(&[], false);
let fn_value = module.add_function("my_fn", fn_type, None);
let enum_attribute = context.create_enum_attribute(1, 1);

fn_value.add_attribute(AttributeLoc::Return, enum_attribute);
fn_value.remove_enum_attribute(AttributeLoc::Return, 1);
source

pub fn get_enum_attribute( self, loc: AttributeLoc, kind_id: u32, ) -> Option<Attribute>

Gets an enum Attribute belonging to the specified location in this FunctionValue.

§Example
use inkwell::attributes::AttributeLoc;
use inkwell::context::Context;

let context = Context::create();
let module = context.create_module("my_mod");
let void_type = context.void_type();
let fn_type = void_type.fn_type(&[], false);
let fn_value = module.add_function("my_fn", fn_type, None);
let enum_attribute = context.create_enum_attribute(1, 1);

fn_value.add_attribute(AttributeLoc::Return, enum_attribute);

assert_eq!(fn_value.get_enum_attribute(AttributeLoc::Return, 1), Some(enum_attribute));
source

pub fn get_string_attribute( self, loc: AttributeLoc, key: &str, ) -> Option<Attribute>

Gets a string Attribute belonging to the specified location in this FunctionValue.

§Example
use inkwell::attributes::AttributeLoc;
use inkwell::context::Context;

let context = Context::create();
let module = context.create_module("my_mod");
let void_type = context.void_type();
let fn_type = void_type.fn_type(&[], false);
let fn_value = module.add_function("my_fn", fn_type, None);
let string_attribute = context.create_string_attribute("my_key", "my_val");

fn_value.add_attribute(AttributeLoc::Return, string_attribute);

assert_eq!(fn_value.get_string_attribute(AttributeLoc::Return, "my_key"), Some(string_attribute));
source

pub fn set_param_alignment(self, param_index: u32, alignment: u32)

source

pub fn as_global_value(self) -> GlobalValue<'ctx>

Gets the GlobalValue version of this FunctionValue. This allows you to further inspect its global properties or even convert it to a PointerValue.

source

pub fn set_subprogram(self, subprogram: DISubprogram<'ctx>)

Available on crate features llvm7-0 or llvm8-0 or llvm9-0 or llvm10-0 or llvm11-0 or llvm12-0 or llvm13-0 or llvm14-0 or llvm15-0 or llvm16-0 or llvm17-0 or llvm18-0 only.

Set the debug info descriptor

source

pub fn get_subprogram(self) -> Option<DISubprogram<'ctx>>

Available on crate features llvm7-0 or llvm8-0 or llvm9-0 or llvm10-0 or llvm11-0 or llvm12-0 or llvm13-0 or llvm14-0 or llvm15-0 or llvm16-0 or llvm17-0 or llvm18-0 only.

Get the debug info descriptor

source

pub fn get_section(&self) -> Option<&CStr>

Get the section to which this function belongs

source

pub fn set_section(self, section: Option<&str>)

Set the section to which this function should belong

Trait Implementations§

source§

impl<'ctx> AnyValue<'ctx> for FunctionValue<'ctx>

source§

fn as_any_value_enum(&self) -> AnyValueEnum<'ctx>

Returns an enum containing a typed version of AnyValue.
source§

fn print_to_string(&self) -> LLVMString

Prints a value to a LLVMString
source§

fn is_poison(&self) -> bool

Available on crate features llvm12-0 or llvm13-0 or llvm14-0 or llvm15-0 or llvm16-0 or llvm17-0 or llvm18-0 only.
Returns whether the value is poison
source§

impl AsValueRef for FunctionValue<'_>

source§

impl<'ctx> Clone for FunctionValue<'ctx>

source§

fn clone(&self) -> FunctionValue<'ctx>

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 FunctionValue<'_>

source§

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

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

impl Display for FunctionValue<'_>

source§

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

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

impl<'ctx> From<FunctionValue<'ctx>> for AnyValueEnum<'ctx>

source§

fn from(value: FunctionValue<'_>) -> AnyValueEnum<'_>

Converts to this type from the input type.
source§

impl<'ctx> Hash for FunctionValue<'ctx>

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<'ctx> PartialEq<AnyValueEnum<'ctx>> for FunctionValue<'ctx>

source§

fn eq(&self, other: &AnyValueEnum<'ctx>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'ctx> PartialEq<FunctionValue<'ctx>> for AnyValueEnum<'ctx>

source§

fn eq(&self, other: &FunctionValue<'ctx>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'ctx> PartialEq for FunctionValue<'ctx>

source§

fn eq(&self, other: &FunctionValue<'ctx>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'ctx> PassManagerSubType for FunctionValue<'ctx>

source§

type Input = Module<'ctx>

source§

unsafe fn create<I: Borrow<Self::Input>>(input: I) -> LLVMPassManagerRef

source§

unsafe fn run_in_pass_manager(&self, pass_manager: &PassManager<Self>) -> bool

source§

impl<'ctx> TryFrom<AnyValueEnum<'ctx>> for FunctionValue<'ctx>

source§

type Error = ()

The type returned in the event of a conversion error.
source§

fn try_from(value: AnyValueEnum<'ctx>) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl<'ctx> Copy for FunctionValue<'ctx>

source§

impl<'ctx> Eq for FunctionValue<'ctx>

source§

impl<'ctx> StructuralPartialEq for FunctionValue<'ctx>

Auto Trait Implementations§

§

impl<'ctx> Freeze for FunctionValue<'ctx>

§

impl<'ctx> RefUnwindSafe for FunctionValue<'ctx>

§

impl<'ctx> !Send for FunctionValue<'ctx>

§

impl<'ctx> !Sync for FunctionValue<'ctx>

§

impl<'ctx> Unpin for FunctionValue<'ctx>

§

impl<'ctx> UnwindSafe for FunctionValue<'ctx>

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> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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 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> ToOwned for T
where T: Clone,

source§

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 T
where 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 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.