From d8a62fba3d25e5caf55de255e9c3a8156a626dc4 Mon Sep 17 00:00:00 2001 From: Corban Villa Date: Thu, 28 Dec 2023 00:12:16 +0000 Subject: [PATCH 1/4] expose LLVMValueRef constructors --- src/values/array_value.rs | 2 +- src/values/basic_value_use.rs | 2 +- src/values/call_site_value.rs | 2 +- src/values/enums.rs | 8 ++++---- src/values/float_value.rs | 2 +- src/values/fn_value.rs | 2 +- src/values/generic_value.rs | 2 +- src/values/global_value.rs | 2 +- src/values/instruction_value.rs | 2 +- src/values/int_value.rs | 2 +- src/values/metadata_value.rs | 2 +- src/values/mod.rs | 2 +- src/values/phi_value.rs | 2 +- src/values/ptr_value.rs | 2 +- src/values/struct_value.rs | 2 +- src/values/vec_value.rs | 2 +- 16 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/values/array_value.rs b/src/values/array_value.rs index 8416051ffac..e9c74dfcd05 100644 --- a/src/values/array_value.rs +++ b/src/values/array_value.rs @@ -15,7 +15,7 @@ pub struct ArrayValue<'ctx> { } impl<'ctx> ArrayValue<'ctx> { - pub(crate) unsafe fn new(value: LLVMValueRef) -> Self { + pub unsafe fn new(value: LLVMValueRef) -> Self { assert!(!value.is_null()); ArrayValue { diff --git a/src/values/basic_value_use.rs b/src/values/basic_value_use.rs index afbbfcbe74f..9bd4ac0370c 100644 --- a/src/values/basic_value_use.rs +++ b/src/values/basic_value_use.rs @@ -15,7 +15,7 @@ use crate::values::{AnyValueEnum, BasicValueEnum}; pub struct BasicValueUse<'ctx>(LLVMUseRef, PhantomData<&'ctx ()>); impl<'ctx> BasicValueUse<'ctx> { - pub(crate) unsafe fn new(use_: LLVMUseRef) -> Self { + pub unsafe fn new(use_: LLVMUseRef) -> Self { debug_assert!(!use_.is_null()); BasicValueUse(use_, PhantomData) diff --git a/src/values/call_site_value.rs b/src/values/call_site_value.rs index 3d2d8c2b2c6..4bba2fef93e 100644 --- a/src/values/call_site_value.rs +++ b/src/values/call_site_value.rs @@ -20,7 +20,7 @@ use super::AnyValue; pub struct CallSiteValue<'ctx>(Value<'ctx>); impl<'ctx> CallSiteValue<'ctx> { - pub(crate) unsafe fn new(value: LLVMValueRef) -> Self { + pub unsafe fn new(value: LLVMValueRef) -> Self { CallSiteValue(Value::new(value)) } diff --git a/src/values/enums.rs b/src/values/enums.rs index 875a547347c..ad4223dc3b7 100644 --- a/src/values/enums.rs +++ b/src/values/enums.rs @@ -72,7 +72,7 @@ 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 { + pub unsafe fn new(value: LLVMValueRef) -> Self { match LLVMGetTypeKind(LLVMTypeOf(value)) { LLVMTypeKind::LLVMFloatTypeKind | LLVMTypeKind::LLVMFP128TypeKind @@ -214,7 +214,7 @@ impl<'ctx> AnyValueEnum<'ctx> { } impl<'ctx> BasicValueEnum<'ctx> { - pub(crate) unsafe fn new(value: LLVMValueRef) -> Self { + pub unsafe fn new(value: LLVMValueRef) -> Self { match LLVMGetTypeKind(LLVMTypeOf(value)) { LLVMTypeKind::LLVMFloatTypeKind | LLVMTypeKind::LLVMFP128TypeKind @@ -321,7 +321,7 @@ impl<'ctx> BasicValueEnum<'ctx> { } impl<'ctx> AggregateValueEnum<'ctx> { - pub(crate) unsafe fn new(value: LLVMValueRef) -> Self { + 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)), @@ -355,7 +355,7 @@ impl<'ctx> AggregateValueEnum<'ctx> { } impl<'ctx> BasicMetadataValueEnum<'ctx> { - pub(crate) unsafe fn new(value: LLVMValueRef) -> Self { + pub unsafe fn new(value: LLVMValueRef) -> Self { match LLVMGetTypeKind(LLVMTypeOf(value)) { LLVMTypeKind::LLVMFloatTypeKind | LLVMTypeKind::LLVMFP128TypeKind diff --git a/src/values/float_value.rs b/src/values/float_value.rs index 4d9d45f346e..5afaed48c2c 100644 --- a/src/values/float_value.rs +++ b/src/values/float_value.rs @@ -23,7 +23,7 @@ pub struct FloatValue<'ctx> { } impl<'ctx> FloatValue<'ctx> { - pub(crate) unsafe fn new(value: LLVMValueRef) -> Self { + pub unsafe fn new(value: LLVMValueRef) -> Self { assert!(!value.is_null()); FloatValue { diff --git a/src/values/fn_value.rs b/src/values/fn_value.rs index 131725dfe4a..a9eb49b5cfd 100644 --- a/src/values/fn_value.rs +++ b/src/values/fn_value.rs @@ -35,7 +35,7 @@ pub struct FunctionValue<'ctx> { } impl<'ctx> FunctionValue<'ctx> { - pub(crate) unsafe fn new(value: LLVMValueRef) -> Option { + pub unsafe fn new(value: LLVMValueRef) -> Option { if value.is_null() { return None; } diff --git a/src/values/generic_value.rs b/src/values/generic_value.rs index f203e2ca128..6e60c259493 100644 --- a/src/values/generic_value.rs +++ b/src/values/generic_value.rs @@ -16,7 +16,7 @@ pub struct GenericValue<'ctx> { } impl<'ctx> GenericValue<'ctx> { - pub(crate) unsafe fn new(generic_value: LLVMGenericValueRef) -> Self { + pub unsafe fn new(generic_value: LLVMGenericValueRef) -> Self { assert!(!generic_value.is_null()); GenericValue { diff --git a/src/values/global_value.rs b/src/values/global_value.rs index 250507828ea..042b28affb1 100644 --- a/src/values/global_value.rs +++ b/src/values/global_value.rs @@ -47,7 +47,7 @@ pub struct GlobalValue<'ctx> { } impl<'ctx> GlobalValue<'ctx> { - pub(crate) unsafe fn new(value: LLVMValueRef) -> Self { + pub unsafe fn new(value: LLVMValueRef) -> Self { assert!(!value.is_null()); GlobalValue { diff --git a/src/values/instruction_value.rs b/src/values/instruction_value.rs index 5785c8492e5..c810bcf38e6 100644 --- a/src/values/instruction_value.rs +++ b/src/values/instruction_value.rs @@ -130,7 +130,7 @@ impl<'ctx> InstructionValue<'ctx> { !unsafe { LLVMIsAAtomicCmpXchgInst(self.as_value_ref()) }.is_null() } - pub(crate) unsafe fn new(instruction_value: LLVMValueRef) -> Self { + pub unsafe fn new(instruction_value: LLVMValueRef) -> Self { debug_assert!(!instruction_value.is_null()); let value = Value::new(instruction_value); diff --git a/src/values/int_value.rs b/src/values/int_value.rs index 8ae04718136..9f8e3b703de 100644 --- a/src/values/int_value.rs +++ b/src/values/int_value.rs @@ -25,7 +25,7 @@ pub struct IntValue<'ctx> { } impl<'ctx> IntValue<'ctx> { - pub(crate) unsafe fn new(value: LLVMValueRef) -> Self { + pub unsafe fn new(value: LLVMValueRef) -> Self { assert!(!value.is_null()); IntValue { diff --git a/src/values/metadata_value.rs b/src/values/metadata_value.rs index 227a761470a..3ee88173fc3 100644 --- a/src/values/metadata_value.rs +++ b/src/values/metadata_value.rs @@ -45,7 +45,7 @@ pub struct MetadataValue<'ctx> { } impl<'ctx> MetadataValue<'ctx> { - pub(crate) unsafe fn new(value: LLVMValueRef) -> Self { + pub unsafe fn new(value: LLVMValueRef) -> Self { assert!(!value.is_null()); assert!(!LLVMIsAMDNode(value).is_null() || !LLVMIsAMDString(value).is_null()); diff --git a/src/values/mod.rs b/src/values/mod.rs index d133d31325d..352eebd31cc 100644 --- a/src/values/mod.rs +++ b/src/values/mod.rs @@ -67,7 +67,7 @@ struct Value<'ctx> { } impl<'ctx> Value<'ctx> { - pub(crate) unsafe fn new(value: LLVMValueRef) -> Self { + pub unsafe fn new(value: LLVMValueRef) -> Self { debug_assert!( !value.is_null(), "This should never happen since containing struct should check null ptrs" diff --git a/src/values/phi_value.rs b/src/values/phi_value.rs index dcc4cbf3978..95c01e74c72 100644 --- a/src/values/phi_value.rs +++ b/src/values/phi_value.rs @@ -20,7 +20,7 @@ pub struct PhiValue<'ctx> { } impl<'ctx> PhiValue<'ctx> { - pub(crate) unsafe fn new(value: LLVMValueRef) -> Self { + pub unsafe fn new(value: LLVMValueRef) -> Self { assert!(!value.is_null()); PhiValue { diff --git a/src/values/ptr_value.rs b/src/values/ptr_value.rs index 63ff751f355..1198a7b1ba4 100644 --- a/src/values/ptr_value.rs +++ b/src/values/ptr_value.rs @@ -21,7 +21,7 @@ pub struct PointerValue<'ctx> { } impl<'ctx> PointerValue<'ctx> { - pub(crate) unsafe fn new(value: LLVMValueRef) -> Self { + pub unsafe fn new(value: LLVMValueRef) -> Self { assert!(!value.is_null()); PointerValue { diff --git a/src/values/struct_value.rs b/src/values/struct_value.rs index 52483310c14..9f1db13967d 100644 --- a/src/values/struct_value.rs +++ b/src/values/struct_value.rs @@ -17,7 +17,7 @@ pub struct StructValue<'ctx> { } impl<'ctx> StructValue<'ctx> { - pub(crate) unsafe fn new(value: LLVMValueRef) -> Self { + pub unsafe fn new(value: LLVMValueRef) -> Self { assert!(!value.is_null()); StructValue { diff --git a/src/values/vec_value.rs b/src/values/vec_value.rs index 79667e00f25..b1ccfb1bf78 100644 --- a/src/values/vec_value.rs +++ b/src/values/vec_value.rs @@ -19,7 +19,7 @@ pub struct VectorValue<'ctx> { } impl<'ctx> VectorValue<'ctx> { - pub(crate) unsafe fn new(vector_value: LLVMValueRef) -> Self { + pub unsafe fn new(vector_value: LLVMValueRef) -> Self { assert!(!vector_value.is_null()); VectorValue { From d56a4bed6760766046708d92f5c530bf11e57c45 Mon Sep 17 00:00:00 2001 From: Corban Villa Date: Fri, 9 Feb 2024 14:14:01 +0000 Subject: [PATCH 2/4] hide Value constructor --- src/values/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/values/mod.rs b/src/values/mod.rs index 69b42c02161..2d0cd72e0e5 100644 --- a/src/values/mod.rs +++ b/src/values/mod.rs @@ -66,7 +66,7 @@ struct Value<'ctx> { } impl<'ctx> Value<'ctx> { - pub unsafe fn new(value: LLVMValueRef) -> Self { + pub(crate) unsafe fn new(value: LLVMValueRef) -> Self { debug_assert!( !value.is_null(), "This should never happen since containing struct should check null ptrs" From 94c10626eb991478b3cd54f1ba5ba0e3239bf7cd Mon Sep 17 00:00:00 2001 From: Corban Villa Date: Sat, 10 Feb 2024 10:37:06 +0000 Subject: [PATCH 3/4] updated docs --- src/values/enums.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/values/enums.rs b/src/values/enums.rs index 25d6884a093..3def22ca143 100644 --- a/src/values/enums.rs +++ b/src/values/enums.rs @@ -73,6 +73,11 @@ enum_value_set! {BasicValueEnum: ArrayValue, IntValue, FloatValue, PointerValue, enum_value_set! {BasicMetadataValueEnum: ArrayValue, IntValue, FloatValue, PointerValue, StructValue, VectorValue, MetadataValue} impl<'ctx> AnyValueEnum<'ctx> { + /// 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 @@ -215,6 +220,11 @@ impl<'ctx> AnyValueEnum<'ctx> { } impl<'ctx> BasicValueEnum<'ctx> { + /// 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 @@ -334,6 +344,11 @@ impl<'ctx> BasicValueEnum<'ctx> { } impl<'ctx> AggregateValueEnum<'ctx> { + /// 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)), @@ -368,7 +383,7 @@ impl<'ctx> AggregateValueEnum<'ctx> { } impl<'ctx> BasicMetadataValueEnum<'ctx> { - pub unsafe fn new(value: LLVMValueRef) -> Self { + pub(crate) unsafe fn new(value: LLVMValueRef) -> Self { match LLVMGetTypeKind(LLVMTypeOf(value)) { LLVMTypeKind::LLVMFloatTypeKind | LLVMTypeKind::LLVMFP128TypeKind From 3bac9dddfb02f8d865cec15921483826e59134c8 Mon Sep 17 00:00:00 2001 From: Corban Villa Date: Sat, 10 Feb 2024 10:38:49 +0000 Subject: [PATCH 4/4] remove pub for generic_value --- src/values/generic_value.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/values/generic_value.rs b/src/values/generic_value.rs index 6e60c259493..f203e2ca128 100644 --- a/src/values/generic_value.rs +++ b/src/values/generic_value.rs @@ -16,7 +16,7 @@ pub struct GenericValue<'ctx> { } impl<'ctx> GenericValue<'ctx> { - pub unsafe fn new(generic_value: LLVMGenericValueRef) -> Self { + pub(crate) unsafe fn new(generic_value: LLVMGenericValueRef) -> Self { assert!(!generic_value.is_null()); GenericValue {