Struct inkwell::values::CallSiteValue
source · 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>
impl<'ctx> CallSiteValue<'ctx>
sourcepub unsafe fn new(value: LLVMValueRef) -> Self
pub unsafe fn new(value: LLVMValueRef) -> Self
sourcepub fn set_tail_call(self, tail_call: bool)
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);
sourcepub fn is_tail_call(self) -> bool
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());
sourcepub fn get_tail_call_kind(self) -> LLVMTailCallKind
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);
sourcepub fn set_tail_call_kind(self, kind: LLVMTailCallKind)
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);
sourcepub fn try_as_basic_value(
self
) -> Either<BasicValueEnum<'ctx>, InstructionValue<'ctx>>
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());
sourcepub fn add_attribute(self, loc: AttributeLoc, attribute: Attribute)
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);
sourcepub fn get_called_fn_value(self) -> FunctionValue<'ctx>
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);
sourcepub fn count_attributes(self, loc: AttributeLoc) -> u32
pub fn count_attributes(self, loc: AttributeLoc) -> u32
Counts the number of Attribute
s 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);
sourcepub fn attributes(self, loc: AttributeLoc) -> Vec<Attribute>
pub fn attributes(self, loc: AttributeLoc) -> Vec<Attribute>
Get all Attribute
s 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 ]);
sourcepub fn get_enum_attribute(
self,
loc: AttributeLoc,
kind_id: u32
) -> Option<Attribute>
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);
sourcepub fn get_string_attribute(
self,
loc: AttributeLoc,
key: &str
) -> Option<Attribute>
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);
sourcepub fn remove_enum_attribute(self, loc: AttributeLoc, kind_id: u32)
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);
sourcepub fn remove_string_attribute(self, loc: AttributeLoc, key: &str)
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);
sourcepub fn count_arguments(self) -> u32
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);
sourcepub fn get_call_convention(self) -> u32
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);
sourcepub fn set_call_convention(self, conv: u32)
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);
sourcepub fn set_alignment_attribute(self, loc: AttributeLoc, alignment: u32)
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>
impl<'ctx> AnyValue<'ctx> for CallSiteValue<'ctx>
source§fn as_any_value_enum(&self) -> AnyValueEnum<'ctx>
fn as_any_value_enum(&self) -> AnyValueEnum<'ctx>
AnyValue
.source§fn print_to_string(&self) -> LLVMString
fn print_to_string(&self) -> LLVMString
LLVMString
source§impl AsValueRef for CallSiteValue<'_>
impl AsValueRef for CallSiteValue<'_>
fn as_value_ref(&self) -> LLVMValueRef
source§impl<'ctx> Clone for CallSiteValue<'ctx>
impl<'ctx> Clone for CallSiteValue<'ctx>
source§fn clone(&self) -> CallSiteValue<'ctx>
fn clone(&self) -> CallSiteValue<'ctx>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<'ctx> Debug for CallSiteValue<'ctx>
impl<'ctx> Debug for CallSiteValue<'ctx>
source§impl Display for CallSiteValue<'_>
impl Display for CallSiteValue<'_>
source§impl<'ctx> Hash for CallSiteValue<'ctx>
impl<'ctx> Hash for CallSiteValue<'ctx>
source§impl<'ctx> PartialEq for CallSiteValue<'ctx>
impl<'ctx> PartialEq for CallSiteValue<'ctx>
source§fn eq(&self, other: &CallSiteValue<'ctx>) -> bool
fn eq(&self, other: &CallSiteValue<'ctx>) -> bool
self
and other
values to be equal, and is used
by ==
.