inkwell::types

Struct FloatType

Source
pub struct FloatType<'ctx> { /* private fields */ }
Expand description

A FloatType is the type of a floating point constant or variable.

Implementations§

Source§

impl<'ctx> FloatType<'ctx>

Source

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

Create FloatType from LLVMTypeRef

§Safety

Undefined behavior, if referenced type isn’t float type

Source

pub fn fn_type( self, param_types: &[BasicMetadataTypeEnum<'ctx>], is_var_args: bool, ) -> FunctionType<'ctx>

Creates a FunctionType with this FloatType for its return type.

§Example
use inkwell::context::Context;

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

pub fn array_type(self, size: u32) -> ArrayType<'ctx>

Creates an ArrayType with this FloatType for its element type.

§Example
use inkwell::context::Context;

let context = Context::create();
let f32_type = context.f32_type();
let f32_array_type = f32_type.array_type(3);

assert_eq!(f32_array_type.len(), 3);
assert_eq!(f32_array_type.get_element_type().into_float_type(), f32_type);
Source

pub fn vec_type(self, size: u32) -> VectorType<'ctx>

Creates a ScalableVectorType with this FloatType for its element type.

§Example
use inkwell::context::Context;

let context = Context::create();
let f32_type = context.f32_type();
let f32_scalable_vector_type = f32_type.vec_type(3);

assert_eq!(f32_scalable_vector_type.get_size(), 3);
assert_eq!(f32_scalable_vector_type.get_element_type().into_float_type(), f32_type);
Source

pub fn scalable_vec_type(self, size: u32) -> ScalableVectorType<'ctx>

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.

Creates a scalable VectorType with this FloatType for its element type.

§Example
use inkwell::context::Context;

let context = Context::create();
let f32_type = context.f32_type();
let f32_vector_type = f32_type.scalable_vec_type(3);

assert_eq!(f32_vector_type.get_size(), 3);
assert_eq!(f32_vector_type.get_element_type().into_float_type(), f32_type);
Source

pub fn const_float(self, value: f64) -> FloatValue<'ctx>

Creates a FloatValue representing a constant value of this FloatType. It will be automatically assigned this FloatType’s Context.

§Example
use inkwell::context::Context;

// Local Context
let context = Context::create();
let f32_type = context.f32_type();
let f32_value = f32_type.const_float(42.);
Source

pub unsafe fn const_float_from_string(self, slice: &str) -> FloatValue<'ctx>

Create a FloatValue from a string. This function is marked unsafe because LLVM provides no error handling here, so this may produce undefined behavior if an invalid string is used.

§Example
use inkwell::context::Context;
use inkwell::values::AnyValue;

let context = Context::create();
let f64_type = context.f64_type();
let f64_val = unsafe { f64_type.const_float_from_string("3.6") };

assert_eq!(f64_val.print_to_string().to_string(), "double 3.600000e+00");

let f64_val = unsafe { f64_type.const_float_from_string("3.") };

assert_eq!(f64_val.print_to_string().to_string(), "double 3.000000e+00");

let f64_val = unsafe { f64_type.const_float_from_string("3") };

assert_eq!(f64_val.print_to_string().to_string(), "double 3.000000e+00");

let f64_val = unsafe { f64_type.const_float_from_string("3.asd") };

assert_eq!(f64_val.print_to_string().to_string(), "double 0x7FF0000000000000");
Source

pub fn const_zero(self) -> FloatValue<'ctx>

Creates a constant zero value of this FloatType.

§Example
use inkwell::context::Context;
use inkwell::values::AnyValue;

let context = Context::create();
let f32_type = context.f32_type();
let f32_zero = f32_type.const_zero();

assert_eq!(f32_zero.print_to_string().to_string(), "float 0.000000e+00");
Source

pub fn size_of(self) -> IntValue<'ctx>

Gets the size of this FloatType. Value may vary depending on the target architecture.

§Example
use inkwell::context::Context;

let context = Context::create();
let f32_type = context.f32_type();
let f32_type_size = f32_type.size_of();
Source

pub fn get_alignment(self) -> IntValue<'ctx>

Gets the alignment of this FloatType. Value may vary depending on the target architecture.

§Example
use inkwell::context::Context;

let context = Context::create();
let f32_type = context.f32_type();
let f32_type_alignment = f32_type.get_alignment();
Source

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

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

§Example
use inkwell::context::Context;

let context = Context::create();
let f32_type = context.f32_type();

assert_eq!(f32_type.get_context(), context);
Source

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

👎Deprecated: Starting from version 15.0, LLVM doesn’t differentiate between pointer types. Use Context::ptr_type instead.

Creates a PointerType with this FloatType for its element type.

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

let context = Context::create();
let f32_type = context.f32_type();
let f32_ptr_type = f32_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!(f32_ptr_type.get_element_type().into_float_type(), f32_type);
Source

pub fn print_to_string(self) -> LLVMString

Print the definition of a FloatType to LLVMString.

Source

pub fn get_undef(&self) -> FloatValue<'ctx>

Creates an undefined instance of a FloatType.

§Example
use inkwell::context::Context;

let context = Context::create();
let f32_type = context.f32_type();
let f32_undef = f32_type.get_undef();

assert!(f32_undef.is_undef());
Source

pub fn get_poison(&self) -> FloatValue<'ctx>

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.

Creates a poison instance of a FloatType.

§Example
use inkwell::context::Context;
use inkwell::values::AnyValue;

let context = Context::create();
let f32_type = context.f32_type();
let f32_poison = f32_type.get_poison();

assert!(f32_poison.is_poison());
Source

pub fn create_generic_value(self, value: f64) -> GenericValue<'ctx>

Creates a GenericValue for use with ExecutionEngines.

Source

pub fn const_array(self, values: &[FloatValue<'ctx>]) -> ArrayValue<'ctx>

Creates a constant ArrayValue.

§Example
use inkwell::context::Context;

let context = Context::create();
let f32_type = context.f32_type();
let f32_val = f32_type.const_float(0.);
let f32_val2 = f32_type.const_float(2.);
let f32_array = f32_type.const_array(&[f32_val, f32_val2]);

assert!(f32_array.is_const());

Trait Implementations§

Source§

impl<'ctx> AnyType<'ctx> for FloatType<'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 FloatType<'_>

Source§

fn as_type_ref(&self) -> LLVMTypeRef

Returns the internal LLVM reference behind the type
Source§

impl<'ctx> BasicType<'ctx> for FloatType<'ctx>

Source§

fn as_basic_type_enum(&self) -> BasicTypeEnum<'ctx>

Returns a BasicTypeEnum that represents the current type.
Source§

fn fn_type( &self, param_types: &[BasicMetadataTypeEnum<'ctx>], is_var_args: bool, ) -> FunctionType<'ctx>

Create a FunctionType with this BasicType as its return type. Read more
Source§

fn is_sized(&self) -> bool

Determines whether or not this BasicType is sized or not. For example, opaque structs are unsized. Read more
Source§

fn size_of(&self) -> Option<IntValue<'ctx>>

Gets the size of this BasicType. Value may vary depending on the target architecture. Read more
Source§

fn array_type(&self, size: u32) -> ArrayType<'ctx>

Create an ArrayType with this BasicType as its elements. Read more
Source§

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

👎Deprecated: Starting from version 15.0, LLVM doesn’t differentiate between pointer types. Use Context::ptr_type instead.
Create a PointerType that points to this BasicType. Read more
Source§

impl<'ctx> Clone for FloatType<'ctx>

Source§

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

Source§

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

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

impl Display for FloatType<'_>

Source§

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

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

impl<'ctx> FloatMathType<'ctx> for FloatType<'ctx>

Source§

type ValueType = FloatValue<'ctx>

The value instance of a float or float vector type.
Source§

type MathConvType = IntType<'ctx>

The type for float to int or float vector to int vector conversions.
Source§

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

Source§

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

Converts to this type from the input type.
Source§

impl<'ctx> From<FloatType<'ctx>> for BasicMetadataTypeEnum<'ctx>

Source§

fn from(value: FloatType<'_>) -> BasicMetadataTypeEnum<'_>

Converts to this type from the input type.
Source§

impl<'ctx> From<FloatType<'ctx>> for BasicTypeEnum<'ctx>

Source§

fn from(value: FloatType<'_>) -> BasicTypeEnum<'_>

Converts to this type from the input type.
Source§

impl<'ctx> PartialEq for FloatType<'ctx>

Source§

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

Source§

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> TryFrom<BasicMetadataTypeEnum<'ctx>> for FloatType<'ctx>

Source§

type Error = ()

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

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

Performs the conversion.
Source§

impl<'ctx> TryFrom<BasicTypeEnum<'ctx>> for FloatType<'ctx>

Source§

type Error = ()

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

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

Performs the conversion.
Source§

impl<'ctx> Copy for FloatType<'ctx>

Source§

impl<'ctx> Eq for FloatType<'ctx>

Source§

impl<'ctx> StructuralPartialEq for FloatType<'ctx>

Auto Trait Implementations§

§

impl<'ctx> Freeze for FloatType<'ctx>

§

impl<'ctx> RefUnwindSafe for FloatType<'ctx>

§

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

§

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

§

impl<'ctx> Unpin for FloatType<'ctx>

§

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