Function const_trunc

Source
pub fn const_trunc(val: &ValueRef, to_type: &TypeRef) -> ValueRef
Expand description

Truncate a constant value to the specified type.

§Details

Truncates a constant integer value to a smaller integer type.

This function wraps the LLVMConstTrunc function from the LLVM core library. It generates a constant truncation instruction, which reduces the bit width of the integer value represented by ValueRef to the bit width of the target type specified by to_type. This is typically used when you need to narrow a constant integer value to a smaller type at compile time.

§Parameters

  • to_type: A reference to the target type (TypeRef) to which the integer value should be truncated. This type must have a smaller bit width than the original integer type.

§Returns

Returns an instance of ValueRef, which encapsulates the result of the truncation. The result is a constant value determined at compile time, representing the truncated integer value.