Skip to content

Commit

Permalink
Merge pull request #457 from corbanvilla/master
Browse files Browse the repository at this point in the history
Expose `pub(crate) fn new` constructors for value types
  • Loading branch information
TheDan64 committed Feb 12, 2024
2 parents f7a8091 + 3bac9dd commit c044e3c
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/values/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@ enum_value_set! {BasicValueEnum: ArrayValue, IntValue, FloatValue, PointerValue,
enum_value_set! {BasicMetadataValueEnum: ArrayValue, IntValue, FloatValue, PointerValue, StructValue, VectorValue, MetadataValue}

impl<'ctx> AnyValueEnum<'ctx> {
pub(crate) unsafe fn new(value: LLVMValueRef) -> Self {
/// Get a value from an [LLVMValueRef].
///
/// # Safety
///
/// The ref must be valid and of supported enum type options ([LLVMTypeKind]).
pub unsafe fn new(value: LLVMValueRef) -> Self {
match LLVMGetTypeKind(LLVMTypeOf(value)) {
LLVMTypeKind::LLVMFloatTypeKind
| LLVMTypeKind::LLVMFP128TypeKind
Expand Down Expand Up @@ -215,7 +220,12 @@ impl<'ctx> AnyValueEnum<'ctx> {
}

impl<'ctx> BasicValueEnum<'ctx> {
pub(crate) unsafe fn new(value: LLVMValueRef) -> Self {
/// Get a value from an [LLVMValueRef].
///
/// # Safety
///
/// The ref must be valid and of supported enum type options ([LLVMTypeKind]).
pub unsafe fn new(value: LLVMValueRef) -> Self {
match LLVMGetTypeKind(LLVMTypeOf(value)) {
LLVMTypeKind::LLVMFloatTypeKind
| LLVMTypeKind::LLVMFP128TypeKind
Expand Down Expand Up @@ -334,7 +344,12 @@ impl<'ctx> BasicValueEnum<'ctx> {
}

impl<'ctx> AggregateValueEnum<'ctx> {
pub(crate) unsafe fn new(value: LLVMValueRef) -> Self {
/// Get a value from an [LLVMValueRef].
///
/// # Safety
///
/// The ref must be valid and of supported aggregate type enum options ([LLVMTypeKind]).
pub unsafe fn new(value: LLVMValueRef) -> Self {
match LLVMGetTypeKind(LLVMTypeOf(value)) {
LLVMTypeKind::LLVMArrayTypeKind => AggregateValueEnum::ArrayValue(ArrayValue::new(value)),
LLVMTypeKind::LLVMStructTypeKind => AggregateValueEnum::StructValue(StructValue::new(value)),
Expand Down

0 comments on commit c044e3c

Please sign in to comment.