llvm_lib::core::values::constants

Struct ConstValueRef

source
pub struct ConstValueRef(/* private fields */);

Implementations§

source§

impl ConstValueRef

source

pub fn const_null(ty: &TypeRef) -> Self

Obtain a constant value referring to the null instance of a type.

§Details

Creates a constant ‘null’ value of the specified type.

This function wraps the LLVMConstNull function from the LLVM core library. It generates a constant ‘null’ value for the specified type (ty). This is typically used for pointer types, where the null value represents a pointer to no valid memory location, but it can also be used for other types where a zero-initialized constant is required.

§Parameters
  • ty: A reference to the type (TypeRef) for which the null value should be created. This type determines the kind of null value that is generated (e.g., null pointer, zero-initialized struct).
§Returns

Returns an instance of ValueRef, which encapsulates the constant null value for the specified type.

source

pub fn const_all_ones(ty: &TypeRef) -> Self

Obtain a constant value referring to the instance of a type consisting of all ones.

This is only valid for integer types.

§Details

Creates a constant value with all bits set to one for the specified type.

This function wraps the LLVMConstAllOnes function from the LLVM core library. It generates a constant value for the specified type (ty) where all the bits are set to one. This is often used to represent a value where all bits are enabled, such as -1 for signed integers or the maximum possible value for unsigned integers.

§Parameters
  • ty: A reference to the type (TypeRef) for which the all-ones value should be created. This type determines the size and nature of the value (e.g., integer, vector).
§Returns

Returns an instance of ValueRef, which encapsulates the constant all-ones value for the specified type.

source

pub fn get_undef(ty: &TypeRef) -> Self

Obtain a constant value referring to an undefined value of a type.

§Details

Creates an ‘undefined’ value of the specified type.

This function wraps the LLVMGetUndef function from the LLVM core library. It generates a constant ‘undefined’ value for the specified type (ty). An undefined value is a placeholder that can take any value of the specified type during program execution, typically used in optimization phases or when a value does not need to be initialized.

§Parameters
  • ty: A reference to the type (TypeRef) for which the undefined value should be created. This type determines the nature of the undefined value (e.g., integer, floating-point, vector).
§Returns

Returns an instance of ValueRef, which encapsulates the constant undefined value for the specified type.

source

pub fn get_poison(ty: &TypeRef) -> Self

Obtain a constant value referring to a poison value of a type.

§Details

Creates a ‘poison’ value of the specified type.

This function wraps the LLVMGetPoison function from the LLVM core library. It generates a constant ‘poison’ value for the specified type (ty). A poison value is similar to an undefined value but more strict; it is used to represent a value that results from an operation with undefined behavior. Using a poison value in further operations can propagate the poison, potentially leading to further undefined behavior.

§Parameters
  • ty: A reference to the type (TypeRef) for which the poison value should be created. This type determines the nature of the poison value (e.g., integer, floating-point, vector).
§Returns

Returns an instance of ValueRef, which encapsulates the constant poison value for the specified type.

source

pub fn is_null(&self) -> bool

Determine whether a value instance is null.

§Details

Checks if the value is a constant ‘null’ value.

This function wraps the LLVMIsNull function from the LLVM core library. It determines whether the value represented by self is a constant ‘null’ value. This is typically used to check if a pointer or other nullable type is explicitly set to null within the LLVM IR.

§Returns

Returns true if the value is a constant null value, otherwise returns false.

source

pub fn const_pointer_null(ty: &TypeRef) -> Self

Obtain a constant that is a constant pointer pointing to NULL for a specified type.

§Details

Creates a constant null pointer value of the specified pointer type.

This function wraps the LLVMConstPointerNull function from the LLVM core library. It generates a constant null pointer for the specified pointer type (ty). This is typically used to represent a pointer that does not point to any valid memory location within LLVM IR.

§Parameters
  • ty: A reference to the pointer type (TypeRef) for which the null pointer value should be created. This type must be a pointer type.
§Returns

Returns an instance of ValueRef, which encapsulates the constant null pointer value for the specified type.

Trait Implementations§

source§

impl Clone for ConstValueRef

source§

fn clone(&self) -> ConstValueRef

Returns a copy of the value. Read more
1.6.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for ConstValueRef

source§

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

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

impl From<*mut LLVMValue> for ConstValueRef

source§

fn from(value: LLVMValueRef) -> Self

Converts to this type from the input type.
source§

impl From<ConstValueRef> for ValueRef

source§

fn from(value: ConstValueRef) -> Self

Converts to this type from the input type.
source§

impl From<ValueRef> for ConstValueRef

source§

fn from(value: ValueRef) -> Self

Converts to this type from the input type.
source§

impl GetRef for ConstValueRef

source§

type RawRef = *mut LLVMValue

Raw LLVM reference type
source§

fn get_ref(&self) -> Self::RawRef

Get LLVM raw reference

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> ToOwned for T
where T: Clone,

source§

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, U> TryFrom<U> for T
where U: Into<T>,

source§

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

source§

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.