Struct llvm_plugin_inkwell::values::CallableValue
source · [−]pub struct CallableValue<'ctx>(_);Expand description
A value that can be called with the build_call instruction.
In practice, the F : Into<CallableValue<'ctx>> bound of build_call means it is
possible to pass a FunctionValue to build_call directly. It will be implicitly converted
into a CallableValue.
use inkwell::context::Context;
// A simple function which calls itself:
let context = Context::create();
let module = context.create_module("ret");
let builder = context.create_builder();
let i32_type = context.i32_type();
let fn_type = i32_type.fn_type(&[i32_type.into()], false);
let fn_value = module.add_function("ret", fn_type, None);
let entry = context.append_basic_block(fn_value, "entry");
let i32_arg = fn_value.get_first_param().unwrap();
builder.position_at_end(entry);
let ret_val = builder.build_call(fn_value, &[i32_arg.into()], "call")
.try_as_basic_value()
.left()
.unwrap();
builder.build_return(Some(&ret_val));A PointerValue cannot be implicitly converted to a CallableValue because the pointer may
point to a non-function value. Instead we can use TryFrom to handle this failure case explicitly.
use std::convert::TryFrom;
use inkwell::context::Context;
use inkwell::values::CallableValue;
// A simple function which calls itself:
let context = Context::create();
let module = context.create_module("ret");
let builder = context.create_builder();
let i32_type = context.i32_type();
let fn_type = i32_type.fn_type(&[i32_type.into()], false);
let fn_value = module.add_function("ret", fn_type, None);
let entry = context.append_basic_block(fn_value, "entry");
let i32_arg = fn_value.get_first_param().unwrap();
builder.position_at_end(entry);
// take a pointer to the function value
let fn_pointer_value = fn_value.as_global_value().as_pointer_value();
// convert that pointer value into a callable value
// explicitly handling the failure case (here with `unwrap`)
let callable_value = CallableValue::try_from(fn_pointer_value).unwrap();
let ret_val = builder.build_call(callable_value, &[i32_arg.into()], "call")
.try_as_basic_value()
.left()
.unwrap();
builder.build_return(Some(&ret_val));Trait Implementations
sourceimpl<'ctx> AnyValue<'ctx> for CallableValue<'ctx>
impl<'ctx> AnyValue<'ctx> for CallableValue<'ctx>
sourcefn as_any_value_enum(&self) -> AnyValueEnum<'ctx>
fn as_any_value_enum(&self) -> AnyValueEnum<'ctx>
Returns an enum containing a typed version of AnyValue.
sourcefn print_to_string(&self) -> LLVMString
fn print_to_string(&self) -> LLVMString
Prints a value to a LLVMString
sourceimpl<'ctx> AsValueRef for CallableValue<'ctx>
impl<'ctx> AsValueRef for CallableValue<'ctx>
fn as_value_ref(&self) -> LLVMValueRef
sourceimpl<'ctx> Debug for CallableValue<'ctx>
impl<'ctx> Debug for CallableValue<'ctx>
sourceimpl Display for CallableValue<'_>
impl Display for CallableValue<'_>
sourceimpl<'ctx> From<FunctionValue<'ctx>> for CallableValue<'ctx>
impl<'ctx> From<FunctionValue<'ctx>> for CallableValue<'ctx>
sourcefn from(value: FunctionValue<'ctx>) -> Self
fn from(value: FunctionValue<'ctx>) -> Self
Converts to this type from the input type.
sourceimpl<'ctx> TryFrom<PointerValue<'ctx>> for CallableValue<'ctx>
impl<'ctx> TryFrom<PointerValue<'ctx>> for CallableValue<'ctx>
Auto Trait Implementations
impl<'ctx> RefUnwindSafe for CallableValue<'ctx>
impl<'ctx> !Send for CallableValue<'ctx>
impl<'ctx> !Sync for CallableValue<'ctx>
impl<'ctx> Unpin for CallableValue<'ctx>
impl<'ctx> UnwindSafe for CallableValue<'ctx>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
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