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

An IntType is the type of an integer constant or variable.

Implementations

Creates an IntValue repesenting 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);

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

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

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

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

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

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

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

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

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

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

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::Generic);

assert_eq!(i8_ptr_type.get_element_type().into_int_type(), i8_type);

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

Print the definition of an IntType to LLVMString.

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

Creates a GenericValue for use with ExecutionEngines.

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

Returns an AnyTypeEnum that represents the current type.

Prints the definition of a Type to a LLVMString.

Returns a BasicTypeEnum that represents the current type.

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

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

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

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

Create a PointerType that points to this BasicType. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

The value instance of an int or int vector type.

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

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

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.