pub struct IntType<'ctx> { /* private fields */ }
Expand description
An IntType
is the type of an integer constant or variable.
Implementations§
source§impl<'ctx> IntType<'ctx>
impl<'ctx> IntType<'ctx>
sourcepub unsafe fn new(int_type: LLVMTypeRef) -> Self
pub unsafe fn new(int_type: LLVMTypeRef) -> Self
sourcepub fn const_int(self, value: u64, sign_extend: bool) -> IntValue<'ctx>
pub fn const_int(self, value: u64, sign_extend: bool) -> IntValue<'ctx>
Creates an IntValue
representing a constant value of this IntType
. It will be automatically assigned this IntType
’s Context
.
§Example
use inkwell::context::Context;
// Local Context
let context = Context::create();
let i32_type = context.i32_type();
let i32_value = i32_type.const_int(42, false);
sourcepub fn const_int_from_string(
self,
slice: &str,
radix: StringRadix,
) -> Option<IntValue<'ctx>>
pub fn const_int_from_string( self, slice: &str, radix: StringRadix, ) -> Option<IntValue<'ctx>>
Create an IntValue
from a string and radix. LLVM provides no error handling here,
so this may produce unexpected results and should not be relied upon for validation.
§Example
use std::convert::TryFrom;
use inkwell::context::Context;
use inkwell::types::StringRadix;
use inkwell::values::AnyValue;
let context = Context::create();
let i8_type = context.i8_type();
let i8_val = i8_type.const_int_from_string("0121", StringRadix::Decimal).unwrap();
assert_eq!(i8_val.print_to_string().to_string(), "i8 121");
let i8_val = i8_type.const_int_from_string("0121", StringRadix::try_from(10).unwrap()).unwrap();
assert_eq!(i8_val.print_to_string().to_string(), "i8 16");
let i8_val = i8_type.const_int_from_string("0121", StringRadix::Binary);
assert!(i8_val.is_none());
let i8_val = i8_type.const_int_from_string("ABCD", StringRadix::Binary);
assert!(i8_val.is_none());
sourcepub fn const_int_arbitrary_precision(self, words: &[u64]) -> IntValue<'ctx>
pub fn const_int_arbitrary_precision(self, words: &[u64]) -> IntValue<'ctx>
Create a constant IntValue
of arbitrary precision.
§Example
use inkwell::context::Context;
let context = Context::create();
let i64_type = context.i64_type();
let i64_val = i64_type.const_int_arbitrary_precision(&[1, 2]);
sourcepub fn const_all_ones(self) -> IntValue<'ctx>
pub fn const_all_ones(self) -> IntValue<'ctx>
Creates an IntValue
representing a constant value of all one bits of this IntType
. It will be automatically assigned this IntType
’s Context
.
§Example
use inkwell::context::Context;
// Local Context
let context = Context::create();
let i32_type = context.i32_type();
let i32_ptr_value = i32_type.const_all_ones();
sourcepub fn const_zero(self) -> IntValue<'ctx>
pub fn const_zero(self) -> IntValue<'ctx>
Creates a constant zero value of this IntType
.
§Example
use inkwell::context::Context;
use inkwell::values::AnyValue;
let context = Context::create();
let i8_type = context.i8_type();
let i8_zero = i8_type.const_zero();
assert_eq!(i8_zero.print_to_string().to_string(), "i8 0");
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 IntType
for its return type.
§Example
use inkwell::context::Context;
let context = Context::create();
let i8_type = context.i8_type();
let fn_type = i8_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 IntType
for its element type.
§Example
use inkwell::context::Context;
let context = Context::create();
let i8_type = context.i8_type();
let i8_array_type = i8_type.array_type(3);
assert_eq!(i8_array_type.len(), 3);
assert_eq!(i8_array_type.get_element_type().into_int_type(), i8_type);
sourcepub fn vec_type(self, size: u32) -> VectorType<'ctx>
pub fn vec_type(self, size: u32) -> VectorType<'ctx>
Creates a VectorType
with this IntType
for its element type.
§Example
use inkwell::context::Context;
let context = Context::create();
let i8_type = context.i8_type();
let i8_vector_type = i8_type.vec_type(3);
assert_eq!(i8_vector_type.get_size(), 3);
assert_eq!(i8_vector_type.get_element_type().into_int_type(), i8_type);
sourcepub fn get_context(self) -> ContextRef<'ctx>
pub fn get_context(self) -> ContextRef<'ctx>
Gets a reference to the Context
this IntType
was created in.
§Example
use inkwell::context::Context;
let context = Context::create();
let i8_type = context.i8_type();
assert_eq!(i8_type.get_context(), context);
sourcepub fn size_of(self) -> IntValue<'ctx>
pub fn size_of(self) -> IntValue<'ctx>
Gets the size of this IntType
. Value may vary depending on the target architecture.
§Example
use inkwell::context::Context;
let context = Context::create();
let i8_type = context.i8_type();
let i8_type_size = i8_type.size_of();
sourcepub fn get_alignment(self) -> IntValue<'ctx>
pub fn get_alignment(self) -> IntValue<'ctx>
Gets the alignment of this IntType
. Value may vary depending on the target architecture.
§Example
use inkwell::context::Context;
let context = Context::create();
let i8_type = context.i8_type();
let i8_type_alignment = i8_type.get_alignment();
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>
Creates a PointerType
with this IntType
for its element type.
§Example
use inkwell::context::Context;
use inkwell::AddressSpace;
let context = Context::create();
let i8_type = context.i8_type();
let i8_ptr_type = i8_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!(i8_ptr_type.get_element_type().into_int_type(), i8_type);
sourcepub fn get_bit_width(self) -> u32
pub fn get_bit_width(self) -> u32
Gets the bit width of an IntType
.
§Example
use inkwell::context::Context;
let context = Context::create();
let bool_type = context.bool_type();
assert_eq!(bool_type.get_bit_width(), 1);
sourcepub fn print_to_string(self) -> LLVMString
pub fn print_to_string(self) -> LLVMString
Print the definition of an IntType
to LLVMString
.
sourcepub fn get_undef(self) -> IntValue<'ctx>
pub fn get_undef(self) -> IntValue<'ctx>
Creates an undefined instance of an IntType
.
§Example
use inkwell::context::Context;
use inkwell::AddressSpace;
let context = Context::create();
let i8_type = context.i8_type();
let i8_undef = i8_type.get_undef();
assert!(i8_undef.is_undef());
sourcepub fn get_poison(self) -> IntValue<'ctx>
pub fn get_poison(self) -> IntValue<'ctx>
Creates a poison instance of an IntType
.
§Example
use inkwell::context::Context;
use inkwell::AddressSpace;
use inkwell::values::AnyValue;
let context = Context::create();
let i8_type = context.i8_type();
let i8_poison = i8_type.get_poison();
assert!(i8_poison.is_poison());
sourcepub fn create_generic_value(
self,
value: u64,
is_signed: bool,
) -> GenericValue<'ctx>
pub fn create_generic_value( self, value: u64, is_signed: bool, ) -> GenericValue<'ctx>
Creates a GenericValue
for use with ExecutionEngine
s.
sourcepub fn const_array(self, values: &[IntValue<'ctx>]) -> ArrayValue<'ctx>
pub fn const_array(self, values: &[IntValue<'ctx>]) -> ArrayValue<'ctx>
Creates a constant ArrayValue
.
§Example
use inkwell::context::Context;
let context = Context::create();
let i8_type = context.i8_type();
let i8_val = i8_type.const_int(0, false);
let i8_val2 = i8_type.const_int(2, false);
let i8_array = i8_type.const_array(&[i8_val, i8_val2]);
assert!(i8_array.is_const());
Trait Implementations§
source§impl<'ctx> AnyType<'ctx> for IntType<'ctx>
impl<'ctx> AnyType<'ctx> for IntType<'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 IntType<'_>
impl AsTypeRef for IntType<'_>
source§fn as_type_ref(&self) -> LLVMTypeRef
fn as_type_ref(&self) -> LLVMTypeRef
source§impl<'ctx> BasicType<'ctx> for IntType<'ctx>
impl<'ctx> BasicType<'ctx> for IntType<'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 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>
source§impl<'ctx> From<IntType<'ctx>> for AnyTypeEnum<'ctx>
impl<'ctx> From<IntType<'ctx>> for AnyTypeEnum<'ctx>
source§fn from(value: IntType<'_>) -> AnyTypeEnum<'_>
fn from(value: IntType<'_>) -> AnyTypeEnum<'_>
source§impl<'ctx> From<IntType<'ctx>> for BasicMetadataTypeEnum<'ctx>
impl<'ctx> From<IntType<'ctx>> for BasicMetadataTypeEnum<'ctx>
source§fn from(value: IntType<'_>) -> BasicMetadataTypeEnum<'_>
fn from(value: IntType<'_>) -> BasicMetadataTypeEnum<'_>
source§impl<'ctx> From<IntType<'ctx>> for BasicTypeEnum<'ctx>
impl<'ctx> From<IntType<'ctx>> for BasicTypeEnum<'ctx>
source§fn from(value: IntType<'_>) -> BasicTypeEnum<'_>
fn from(value: IntType<'_>) -> BasicTypeEnum<'_>
source§impl<'ctx> IntMathType<'ctx> for IntType<'ctx>
impl<'ctx> IntMathType<'ctx> for IntType<'ctx>
§type MathConvType = FloatType<'ctx>
type MathConvType = FloatType<'ctx>
§type PtrConvType = PointerType<'ctx>
type PtrConvType = PointerType<'ctx>
source§impl<'ctx> PartialEq for IntType<'ctx>
impl<'ctx> PartialEq for IntType<'ctx>
source§impl<'ctx> TryFrom<AnyTypeEnum<'ctx>> for IntType<'ctx>
impl<'ctx> TryFrom<AnyTypeEnum<'ctx>> for IntType<'ctx>
source§impl<'ctx> TryFrom<BasicMetadataTypeEnum<'ctx>> for IntType<'ctx>
impl<'ctx> TryFrom<BasicMetadataTypeEnum<'ctx>> for IntType<'ctx>
source§impl<'ctx> TryFrom<BasicTypeEnum<'ctx>> for IntType<'ctx>
impl<'ctx> TryFrom<BasicTypeEnum<'ctx>> for IntType<'ctx>
impl<'ctx> Copy for IntType<'ctx>
impl<'ctx> Eq for IntType<'ctx>
impl<'ctx> StructuralPartialEq for IntType<'ctx>
Auto Trait Implementations§
impl<'ctx> Freeze for IntType<'ctx>
impl<'ctx> RefUnwindSafe for IntType<'ctx>
impl<'ctx> !Send for IntType<'ctx>
impl<'ctx> !Sync for IntType<'ctx>
impl<'ctx> Unpin for IntType<'ctx>
impl<'ctx> UnwindSafe for IntType<'ctx>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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