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>
impl<'ctx> FloatType<'ctx>
Sourcepub unsafe fn new(float_type: LLVMTypeRef) -> Self
pub unsafe fn new(float_type: LLVMTypeRef) -> Self
Sourcepub fn fn_type(
self,
param_types: &[BasicMetadataTypeEnum<'ctx>],
is_var_args: bool,
) -> FunctionType<'ctx>
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);Sourcepub fn array_type(self, size: u32) -> ArrayType<'ctx>
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);Sourcepub fn vec_type(self, size: u32) -> VectorType<'ctx>
pub fn vec_type(self, size: u32) -> VectorType<'ctx>
Creates a 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_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);Sourcepub fn scalable_vec_type(self, size: u32) -> ScalableVectorType<'ctx>
pub fn scalable_vec_type(self, size: u32) -> ScalableVectorType<'ctx>
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);Sourcepub fn const_float(self, value: f64) -> FloatValue<'ctx>
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.);Sourcepub unsafe fn const_float_from_string(self, slice: &str) -> FloatValue<'ctx>
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");Sourcepub fn const_zero(self) -> FloatValue<'ctx>
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");Sourcepub fn size_of(self) -> IntValue<'ctx>
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();Sourcepub fn get_context(self) -> ContextRef<'ctx>
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);Sourcepub 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.
pub fn ptr_type(self, address_space: AddressSpace) -> PointerType<'ctx>
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(feature = "typed-pointers")]
assert_eq!(f32_ptr_type.get_element_type().into_float_type(), f32_type);Sourcepub fn get_bit_width(self) -> u32
pub fn get_bit_width(self) -> u32
Gets the bit width of a FloatType.
§Example
use inkwell::context::Context;
let context = Context::create();
let f128_type = context.f128_type();
assert_eq!(f128_type.get_bit_width(), 128);Sourcepub fn print_to_string(self) -> LLVMString
pub fn print_to_string(self) -> LLVMString
Print the definition of a FloatType to LLVMString.
Sourcepub fn get_undef(&self) -> FloatValue<'ctx>
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());Sourcepub fn get_poison(&self) -> FloatValue<'ctx>
pub fn get_poison(&self) -> FloatValue<'ctx>
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());Sourcepub fn create_generic_value(self, value: f64) -> GenericValue<'ctx>
pub fn create_generic_value(self, value: f64) -> GenericValue<'ctx>
Creates a GenericValue for use with ExecutionEngines.
Sourcepub fn const_array(self, values: &[FloatValue<'ctx>]) -> ArrayValue<'ctx>
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>
impl<'ctx> AnyType<'ctx> for FloatType<'ctx>
Source§fn as_any_type_enum(&self) -> AnyTypeEnum<'ctx>
fn as_any_type_enum(&self) -> AnyTypeEnum<'ctx>
AnyTypeEnum that represents the current type.Source§fn print_to_string(&self) -> LLVMString
fn print_to_string(&self) -> LLVMString
LLVMString.Source§impl AsTypeRef for FloatType<'_>
impl AsTypeRef for FloatType<'_>
Source§fn as_type_ref(&self) -> LLVMTypeRef
fn as_type_ref(&self) -> LLVMTypeRef
Source§impl<'ctx> BasicType<'ctx> for FloatType<'ctx>
impl<'ctx> BasicType<'ctx> for FloatType<'ctx>
Source§fn as_basic_type_enum(&self) -> BasicTypeEnum<'ctx>
fn as_basic_type_enum(&self) -> BasicTypeEnum<'ctx>
BasicTypeEnum that represents the current type.Source§fn fn_type(
&self,
param_types: &[BasicMetadataTypeEnum<'ctx>],
is_var_args: bool,
) -> FunctionType<'ctx>
fn fn_type( &self, param_types: &[BasicMetadataTypeEnum<'ctx>], is_var_args: bool, ) -> FunctionType<'ctx>
Source§fn is_sized(&self) -> bool
fn is_sized(&self) -> bool
BasicType is sized or not.
For example, opaque structs are unsized. Read moreSource§fn size_of(&self) -> Option<IntValue<'ctx>>
fn size_of(&self) -> Option<IntValue<'ctx>>
BasicType. Value may vary depending on the target architecture. Read moreSource§fn get_alignment(&self) -> IntValue<'ctx>
fn get_alignment(&self) -> IntValue<'ctx>
BasicType. Value may vary depending on the target architecture. Read moreSource§fn array_type(&self, size: u32) -> ArrayType<'ctx>
fn array_type(&self, size: u32) -> ArrayType<'ctx>
Source§fn ptr_type(&self, address_space: AddressSpace) -> PointerType<'ctx>
fn ptr_type(&self, address_space: AddressSpace) -> PointerType<'ctx>
Starting from version 15.0, LLVM doesn’t differentiate between pointer types. Use Context::ptr_type instead.