Struct inkwell::types::IntType

source ·
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>

source

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

Create IntType from LLVMTypeRef

§Safety

Undefined behavior, if referenced type isn’t int type

source

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);
source

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());
source

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]);
source

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();
source

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");
source

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);
source

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);
source

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);
source

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);
source

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();
source

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();
source

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);
source

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);
source

pub fn print_to_string(self) -> LLVMString

Print the definition of an IntType to LLVMString.

source

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());
source

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());
source

pub fn create_generic_value( self, value: u64, is_signed: bool ) -> GenericValue<'ctx>

Creates a GenericValue for use with ExecutionEngines.

source

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>

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 IntType<'_>

source§

fn as_type_ref(&self) -> LLVMTypeRef

Returns the internal LLVM reference behind the type
source§

impl<'ctx> BasicType<'ctx> for IntType<'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>

Create a PointerType that points to this BasicType. Read more
source§

impl<'ctx> Clone for IntType<'ctx>

source§

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

source§

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

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

impl Display for IntType<'_>

source§

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

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

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

source§

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

Converts to this type from the input type.
source§

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

source§

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

Converts to this type from the input type.
source§

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

source§

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

Converts to this type from the input type.
source§

impl<'ctx> IntMathType<'ctx> for IntType<'ctx>

§

type ValueType = IntValue<'ctx>

The value instance of an int or int vector type.
§

type MathConvType = FloatType<'ctx>

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

type PtrConvType = PointerType<'ctx>

The type for int to pointer or int vector to pointer vector conversions.
source§

impl<'ctx> PartialEq for IntType<'ctx>

source§

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

§

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 IntType<'ctx>

§

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 IntType<'ctx>

source§

impl<'ctx> Eq for IntType<'ctx>

source§

impl<'ctx> StructuralPartialEq for IntType<'ctx>

Auto Trait Implementations§

§

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> 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.