Struct inkwell::types::FunctionType

source ·
pub struct FunctionType<'ctx> { /* private fields */ }
Expand description

A FunctionType is the type of a function variable.

Implementations§

source§

impl<'ctx> FunctionType<'ctx>

source

pub unsafe fn new(fn_type: LLVMTypeRef) -> Self

Create FunctionType from LLVMTypeRef

§Safety

Undefined behavior, if referenced type isn’t function type

source

pub fn ptr_type(self, address_space: AddressSpace) -> PointerType<'ctx>

Creates a PointerType with this FunctionType for its element type.

§Example
use inkwell::context::Context;
use inkwell::AddressSpace;

let context = Context::create();
let f32_type = context.f32_type();
let fn_type = f32_type.fn_type(&[], false);
let fn_ptr_type = fn_type.ptr_type(AddressSpace::default());

#[cfg(any(
    feature = "llvm4-0",
    feature = "llvm5-0",
    feature = "llvm6-0",
    feature = "llvm7-0",
    feature = "llvm8-0",
    feature = "llvm9-0",
    feature = "llvm10-0",
    feature = "llvm11-0",
    feature = "llvm12-0",
    feature = "llvm13-0",
    feature = "llvm14-0"
))]
assert_eq!(fn_ptr_type.get_element_type().into_function_type(), fn_type);
source

pub fn is_var_arg(self) -> bool

Determines whether or not a FunctionType is a variadic function.

§Example
use inkwell::context::Context;

let context = Context::create();
let f32_type = context.f32_type();
let fn_type = f32_type.fn_type(&[], true);

assert!(fn_type.is_var_arg());
source

pub fn get_param_types(self) -> Vec<BasicTypeEnum<'ctx>>

Gets param types this FunctionType has.

§Example
use inkwell::context::Context;

let context = Context::create();
let f32_type = context.f32_type();
let fn_type = f32_type.fn_type(&[f32_type.into()], true);
let param_types = fn_type.get_param_types();

assert_eq!(param_types.len(), 1);
assert_eq!(param_types[0].into_float_type(), f32_type);
source

pub fn count_param_types(self) -> u32

Counts the number of param types this FunctionType has.

§Example
use inkwell::context::Context;

let context = Context::create();
let f32_type = context.f32_type();
let fn_type = f32_type.fn_type(&[f32_type.into()], true);

assert_eq!(fn_type.count_param_types(), 1);
source

pub fn is_sized(self) -> bool

Gets whether or not this FunctionType is sized or not. This is likely always false and may be removed in the future.

§Example
use inkwell::context::Context;

let context = Context::create();
let f32_type = context.f32_type();
let fn_type = f32_type.fn_type(&[], true);

assert!(!fn_type.is_sized());
source

pub fn get_context(self) -> ContextRef<'ctx>

Gets a reference to the Context this FunctionType was created in.

§Example
use inkwell::context::Context;

let context = Context::create();
let f32_type = context.f32_type();
let fn_type = f32_type.fn_type(&[], true);

assert_eq!(fn_type.get_context(), context);
source

pub fn print_to_string(self) -> LLVMString

Print the definition of a FunctionType to LLVMString.

source

pub fn get_return_type(self) -> Option<BasicTypeEnum<'ctx>>

Gets the return type of this FunctionType.

§Example
use inkwell::context::Context;

let context = Context::create();
let f32_type = context.f32_type();
let fn_type = f32_type.fn_type(&[], true);

assert_eq!(fn_type.get_return_type().unwrap().into_float_type(), f32_type);

Trait Implementations§

source§

impl<'ctx> AnyType<'ctx> for FunctionType<'ctx>

source§

fn as_any_type_enum(&self) -> AnyTypeEnum<'ctx>

Returns an AnyTypeEnum that represents the current type.
source§

fn print_to_string(&self) -> LLVMString

Prints the definition of a Type to a LLVMString.
source§

impl AsTypeRef for FunctionType<'_>

source§

fn as_type_ref(&self) -> LLVMTypeRef

Returns the internal LLVM reference behind the type
source§

impl<'ctx> Clone for FunctionType<'ctx>

source§

fn clone(&self) -> FunctionType<'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 FunctionType<'_>

source§

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

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

impl Display for FunctionType<'_>

source§

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

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

impl<'ctx> From<FunctionType<'ctx>> for AnyTypeEnum<'ctx>

source§

fn from(value: FunctionType<'_>) -> AnyTypeEnum<'_>

Converts to this type from the input type.
source§

impl<'ctx> PartialEq for FunctionType<'ctx>

source§

fn eq(&self, other: &FunctionType<'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> TryFrom<AnyTypeEnum<'ctx>> for FunctionType<'ctx>

§

type Error = ()

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

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

Performs the conversion.
source§

impl<'ctx> Copy for FunctionType<'ctx>

source§

impl<'ctx> Eq for FunctionType<'ctx>

source§

impl<'ctx> StructuralPartialEq for FunctionType<'ctx>

Auto Trait Implementations§

§

impl<'ctx> RefUnwindSafe for FunctionType<'ctx>

§

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

§

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

§

impl<'ctx> Unpin for FunctionType<'ctx>

§

impl<'ctx> UnwindSafe for FunctionType<'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.