Function const_int

Source
pub fn const_int(ty: &TypeRef, n: u64, sign_extend: bool) -> ValueRef
Expand description

Obtain a constant value for an integer type. The returned value corresponds to a llvm ConstantInt.

§Details

Creates a constant integer value of a specified type.

This function wraps the LLVMConstInt function from the LLVM core library. It generates a constant integer value of the type specified by ty, using the provided n as the value. The sign_extend parameter determines whether the value should be sign-extended to the specified type if the type is larger than the original value.

§Parameters

  • ty: A reference to the integer type (TypeRef) for the constant value. This specifies the bit width and signedness of the integer.
  • n: The integer value to be used for the constant. It will be interpreted according to the bit width and signedness of the target type.
  • sign_extend: A boolean value indicating whether the constant should be sign-extended to the target type. If true, the value will be sign-extended; if false, it will be zero-extended.

§Returns

Returns an instance of ValueRef, which encapsulates the constant integer value determined at compile time.