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 scalable_vec_type(self, size: u32) -> ScalableVectorType<'ctx>
pub fn scalable_vec_type(self, size: u32) -> ScalableVectorType<'ctx>
Creates a ScalableVectorType with this IntType for its element type.
§Example
use inkwell::context::Context;
let context = Context::create();
let i8_type = context.i8_type();
let i8_scalable_vector_type = i8_type.scalable_vec_type(3);
assert_eq!(i8_scalable_vector_type.get_size(), 3);
assert_eq!(i8_scalable_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 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 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(feature = "typed-pointers")]
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 ExecutionEngines.
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 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.