pub struct CallSiteValue<'ctx>(/* private fields */);
Expand description

A value resulting from a function call. It may have function attributes applied to it.

This struct may be removed in the future in favor of an InstructionValue<CallSite> type.

Implementations§

source§

impl<'ctx> CallSiteValue<'ctx>

source

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

Get a value from an LLVMValueRef.

§Safety

The ref must be valid and of type call site.

source

pub fn set_tail_call(self, tail_call: bool)

Sets whether or not this call is a tail call.

§Example
use inkwell::context::Context;

let context = Context::create();
let builder = context.create_builder();
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 entry_bb = context.append_basic_block(fn_value, "entry");

builder.position_at_end(entry_bb);

let call_site_value = builder.build_call(fn_value, &[], "my_fn").unwrap();

call_site_value.set_tail_call(true);
source

pub fn is_tail_call(self) -> bool

Determines whether or not this call is a tail call.

§Example
use inkwell::context::Context;

let context = Context::create();
let builder = context.create_builder();
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 entry_bb = context.append_basic_block(fn_value, "entry");

builder.position_at_end(entry_bb);

let call_site_value = builder.build_call(fn_value, &[], "my_fn").unwrap();

call_site_value.set_tail_call(true);

assert!(call_site_value.is_tail_call());
source

pub fn get_tail_call_kind(self) -> LLVMTailCallKind

Returns tail, musttail, and notail attributes.

§Example
use inkwell::values::LLVMTailCallKind::*;

let context = inkwell::context::Context::create();
let builder = context.create_builder();
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 entry_bb = context.append_basic_block(fn_value, "entry");

builder.position_at_end(entry_bb);

let call_site = builder.build_call(fn_value, &[], "my_fn").unwrap();

assert_eq!(call_site.get_tail_call_kind(), LLVMTailCallKindNone);
source

pub fn set_tail_call_kind(self, kind: LLVMTailCallKind)

Sets tail, musttail, and notail attributes.

§Example
use inkwell::values::LLVMTailCallKind::*;

let context = inkwell::context::Context::create();
let builder = context.create_builder();
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 entry_bb = context.append_basic_block(fn_value, "entry");

builder.position_at_end(entry_bb);

let call_site = builder.build_call(fn_value, &[], "my_fn").unwrap();

call_site.set_tail_call_kind(LLVMTailCallKindTail);
assert_eq!(call_site.get_tail_call_kind(), LLVMTailCallKindTail);
source

pub fn try_as_basic_value( self ) -> Either<BasicValueEnum<'ctx>, InstructionValue<'ctx>>

Try to convert this CallSiteValue to a BasicValueEnum if not a void return type.

§Example
use inkwell::context::Context;

let context = Context::create();
let builder = context.create_builder();
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 entry_bb = context.append_basic_block(fn_value, "entry");

builder.position_at_end(entry_bb);

let call_site_value = builder.build_call(fn_value, &[], "my_fn").unwrap();

assert!(call_site_value.try_as_basic_value().is_right());
source

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

Adds an Attribute to this CallSiteValue.

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

let context = Context::create();
let builder = context.create_builder();
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);
let entry_bb = context.append_basic_block(fn_value, "entry");

builder.position_at_end(entry_bb);

let call_site_value = builder.build_call(fn_value, &[], "my_fn").unwrap();

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

pub fn get_called_fn_value(self) -> FunctionValue<'ctx>

Gets the FunctionValue this CallSiteValue is based on.

§Example
use inkwell::context::Context;

let context = Context::create();
let builder = context.create_builder();
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);
let entry_bb = context.append_basic_block(fn_value, "entry");

builder.position_at_end(entry_bb);

let call_site_value = builder.build_call(fn_value, &[], "my_fn").unwrap();

assert_eq!(call_site_value.get_called_fn_value(), fn_value);
source

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

Counts the number of Attributes on this CallSiteValue at an index.

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

let context = Context::create();
let builder = context.create_builder();
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);
let entry_bb = context.append_basic_block(fn_value, "entry");

builder.position_at_end(entry_bb);

let call_site_value = builder.build_call(fn_value, &[], "my_fn").unwrap();

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

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

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

Get all Attributes on this CallSiteValue at an index.

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

let context = Context::create();
let builder = context.create_builder();
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);
let entry_bb = context.append_basic_block(fn_value, "entry");

builder.position_at_end(entry_bb);

let call_site_value = builder.build_call(fn_value, &[], "my_fn").unwrap();

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

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

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

Gets an enum Attribute on this CallSiteValue at an index and kind id.

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

let context = Context::create();
let builder = context.create_builder();
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);
let entry_bb = context.append_basic_block(fn_value, "entry");

builder.position_at_end(entry_bb);

let call_site_value = builder.build_call(fn_value, &[], "my_fn").unwrap();

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

assert_eq!(call_site_value.get_enum_attribute(AttributeLoc::Return, 1).unwrap(), enum_attribute);
source

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

Gets a string Attribute on this CallSiteValue at an index and key.

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

let context = Context::create();
let builder = context.create_builder();
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);
let entry_bb = context.append_basic_block(fn_value, "entry");

builder.position_at_end(entry_bb);

let call_site_value = builder.build_call(fn_value, &[], "my_fn").unwrap();

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

assert_eq!(call_site_value.get_string_attribute(AttributeLoc::Return, "my_key").unwrap(), string_attribute);
source

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

Removes an enum Attribute on this CallSiteValue at an index and kind id.

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

let context = Context::create();
let builder = context.create_builder();
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);
let entry_bb = context.append_basic_block(fn_value, "entry");

builder.position_at_end(entry_bb);

let call_site_value = builder.build_call(fn_value, &[], "my_fn").unwrap();

call_site_value.add_attribute(AttributeLoc::Return, string_attribute);
call_site_value.add_attribute(AttributeLoc::Return, enum_attribute);
call_site_value.remove_enum_attribute(AttributeLoc::Return, 1);

assert_eq!(call_site_value.get_enum_attribute(AttributeLoc::Return, 1), None);
source

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

Removes a string Attribute on this CallSiteValue at an index and key.

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

let context = Context::create();
let builder = context.create_builder();
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);
let entry_bb = context.append_basic_block(fn_value, "entry");

builder.position_at_end(entry_bb);

let call_site_value = builder.build_call(fn_value, &[], "my_fn").unwrap();

call_site_value.add_attribute(AttributeLoc::Return, string_attribute);
call_site_value.add_attribute(AttributeLoc::Return, enum_attribute);
call_site_value.remove_string_attribute(AttributeLoc::Return, "my_key");

assert_eq!(call_site_value.get_string_attribute(AttributeLoc::Return, "my_key"), None);
source

pub fn count_arguments(self) -> u32

Counts the number of arguments this CallSiteValue was called with.

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

let context = Context::create();
let builder = context.create_builder();
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);
let entry_bb = context.append_basic_block(fn_value, "entry");

builder.position_at_end(entry_bb);

let call_site_value = builder.build_call(fn_value, &[], "my_fn").unwrap();

assert_eq!(call_site_value.count_arguments(), 0);
source

pub fn get_call_convention(self) -> u32

Gets the calling convention for this CallSiteValue.

§Example
use inkwell::context::Context;

let context = Context::create();
let builder = context.create_builder();
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 entry_bb = context.append_basic_block(fn_value, "entry");

builder.position_at_end(entry_bb);

let call_site_value = builder.build_call(fn_value, &[], "my_fn").unwrap();

assert_eq!(call_site_value.get_call_convention(), 0);
source

pub fn set_call_convention(self, conv: u32)

Sets the calling convention for this CallSiteValue.

§Example
use inkwell::context::Context;

let context = Context::create();
let builder = context.create_builder();
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 entry_bb = context.append_basic_block(fn_value, "entry");

builder.position_at_end(entry_bb);

let call_site_value = builder.build_call(fn_value, &[], "my_fn").unwrap();

call_site_value.set_call_convention(2);

assert_eq!(call_site_value.get_call_convention(), 2);
source

pub fn set_alignment_attribute(self, loc: AttributeLoc, alignment: u32)

Shortcut for setting the alignment Attribute for this CallSiteValue.

§Panics

When the alignment is not a power of 2.

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

let context = Context::create();
let builder = context.create_builder();
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 entry_bb = context.append_basic_block(fn_value, "entry");

builder.position_at_end(entry_bb);

let call_site_value = builder.build_call(fn_value, &[], "my_fn").unwrap();

call_site_value.set_alignment_attribute(AttributeLoc::Param(0), 2);

Trait Implementations§

source§

impl<'ctx> AnyValue<'ctx> for CallSiteValue<'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

Returns whether the value is poison
source§

impl AsValueRef for CallSiteValue<'_>

source§

impl<'ctx> Clone for CallSiteValue<'ctx>

source§

fn clone(&self) -> CallSiteValue<'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<'ctx> Debug for CallSiteValue<'ctx>

source§

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

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

impl Display for CallSiteValue<'_>

source§

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

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

impl<'ctx> Hash for CallSiteValue<'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 for CallSiteValue<'ctx>

source§

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

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

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

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

impl<'ctx> Copy for CallSiteValue<'ctx>

source§

impl<'ctx> Eq for CallSiteValue<'ctx>

source§

impl<'ctx> StructuralPartialEq for CallSiteValue<'ctx>

Auto Trait Implementations§

§

impl<'ctx> Freeze for CallSiteValue<'ctx>

§

impl<'ctx> RefUnwindSafe for CallSiteValue<'ctx>

§

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

§

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

§

impl<'ctx> Unpin for CallSiteValue<'ctx>

§

impl<'ctx> UnwindSafe for CallSiteValue<'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> 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,

§

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>,

§

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>,

§

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.