From 3437e601373253c3090252066b8e73c7fc38b9ec Mon Sep 17 00:00:00 2001 From: Alex Saveau Date: Sat, 20 Jan 2024 17:23:05 -0800 Subject: [PATCH] Expose some ref constructors Signed-off-by: Alex Saveau --- src/module.rs | 7 ++++++- src/values/array_value.rs | 7 ++++++- src/values/basic_value_use.rs | 7 ++++++- src/values/call_site_value.rs | 7 ++++++- src/values/float_value.rs | 7 ++++++- src/values/fn_value.rs | 7 ++++++- src/values/global_value.rs | 7 ++++++- src/values/instruction_value.rs | 7 ++++++- src/values/int_value.rs | 7 ++++++- src/values/metadata_value.rs | 7 ++++++- src/values/phi_value.rs | 7 ++++++- src/values/ptr_value.rs | 7 ++++++- src/values/struct_value.rs | 7 ++++++- src/values/vec_value.rs | 7 ++++++- 14 files changed, 84 insertions(+), 14 deletions(-) diff --git a/src/module.rs b/src/module.rs index 770f01b43c3..26e2fbbb4f5 100644 --- a/src/module.rs +++ b/src/module.rs @@ -173,7 +173,12 @@ pub struct Module<'ctx> { } impl<'ctx> Module<'ctx> { - pub(crate) unsafe fn new(module: LLVMModuleRef) -> Self { + /// Get a module from an [LLVMModuleRef]. + /// + /// # Safety + /// + /// The ref must be valid. + pub unsafe fn new(module: LLVMModuleRef) -> Self { debug_assert!(!module.is_null()); Module { diff --git a/src/values/array_value.rs b/src/values/array_value.rs index 8416051ffac..863cad728a8 100644 --- a/src/values/array_value.rs +++ b/src/values/array_value.rs @@ -15,7 +15,12 @@ pub struct ArrayValue<'ctx> { } impl<'ctx> ArrayValue<'ctx> { - pub(crate) unsafe fn new(value: LLVMValueRef) -> Self { + /// Get a value from an [LLVMValueRef]. + /// + /// # Safety + /// + /// The ref must be valid and of type array. + 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..fa971c03b1a 100644 --- a/src/values/basic_value_use.rs +++ b/src/values/basic_value_use.rs @@ -15,7 +15,12 @@ use crate::values::{AnyValueEnum, BasicValueEnum}; pub struct BasicValueUse<'ctx>(LLVMUseRef, PhantomData<&'ctx ()>); impl<'ctx> BasicValueUse<'ctx> { - pub(crate) unsafe fn new(use_: LLVMUseRef) -> Self { + /// Get a value from an [LLVMUseRef]. + /// + /// # Safety + /// + /// The ref must be valid and of type basic value. + 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..65ef8ebce12 100644 --- a/src/values/call_site_value.rs +++ b/src/values/call_site_value.rs @@ -20,7 +20,12 @@ use super::AnyValue; pub struct CallSiteValue<'ctx>(Value<'ctx>); impl<'ctx> CallSiteValue<'ctx> { - pub(crate) unsafe fn new(value: LLVMValueRef) -> Self { + /// Get a value from an [LLVMValueRef]. + /// + /// # Safety + /// + /// The ref must be valid and of type call site. + pub unsafe fn new(value: LLVMValueRef) -> Self { CallSiteValue(Value::new(value)) } diff --git a/src/values/float_value.rs b/src/values/float_value.rs index 4d9d45f346e..13bb4264b20 100644 --- a/src/values/float_value.rs +++ b/src/values/float_value.rs @@ -23,7 +23,12 @@ pub struct FloatValue<'ctx> { } impl<'ctx> FloatValue<'ctx> { - pub(crate) unsafe fn new(value: LLVMValueRef) -> Self { + /// Get a value from an [LLVMValueRef]. + /// + /// # Safety + /// + /// The ref must be valid and of type float. + 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 6818b513666..7c529f98ee8 100644 --- a/src/values/fn_value.rs +++ b/src/values/fn_value.rs @@ -35,7 +35,12 @@ pub struct FunctionValue<'ctx> { } impl<'ctx> FunctionValue<'ctx> { - pub(crate) unsafe fn new(value: LLVMValueRef) -> Option { + /// Get a value from an [LLVMValueRef]. + /// + /// # Safety + /// + /// The ref must be valid and of type function. + pub unsafe fn new(value: LLVMValueRef) -> Option { if value.is_null() { return None; } diff --git a/src/values/global_value.rs b/src/values/global_value.rs index 250507828ea..80c098e704d 100644 --- a/src/values/global_value.rs +++ b/src/values/global_value.rs @@ -47,7 +47,12 @@ pub struct GlobalValue<'ctx> { } impl<'ctx> GlobalValue<'ctx> { - pub(crate) unsafe fn new(value: LLVMValueRef) -> Self { + /// Get a value from an [LLVMValueRef]. + /// + /// # Safety + /// + /// The ref must be valid and of type global. + 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..646a43dae68 100644 --- a/src/values/instruction_value.rs +++ b/src/values/instruction_value.rs @@ -130,7 +130,12 @@ impl<'ctx> InstructionValue<'ctx> { !unsafe { LLVMIsAAtomicCmpXchgInst(self.as_value_ref()) }.is_null() } - pub(crate) unsafe fn new(instruction_value: LLVMValueRef) -> Self { + /// Get a value from an [LLVMValueRef]. + /// + /// # Safety + /// + /// The ref must be valid and of type instruction. + 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 0e68594efbb..9c7b7ab01d8 100644 --- a/src/values/int_value.rs +++ b/src/values/int_value.rs @@ -29,7 +29,12 @@ pub struct IntValue<'ctx> { } impl<'ctx> IntValue<'ctx> { - pub(crate) unsafe fn new(value: LLVMValueRef) -> Self { + /// Get a value from an [LLVMValueRef]. + /// + /// # Safety + /// + /// The ref must be valid and of type int. + 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 ba7a3563992..a7656ac7f05 100644 --- a/src/values/metadata_value.rs +++ b/src/values/metadata_value.rs @@ -45,7 +45,12 @@ pub struct MetadataValue<'ctx> { } impl<'ctx> MetadataValue<'ctx> { - pub(crate) unsafe fn new(value: LLVMValueRef) -> Self { + /// Get a value from an [LLVMValueRef]. + /// + /// # Safety + /// + /// The ref must be valid and of type metadata. + 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/phi_value.rs b/src/values/phi_value.rs index dcc4cbf3978..4be15e40fbf 100644 --- a/src/values/phi_value.rs +++ b/src/values/phi_value.rs @@ -20,7 +20,12 @@ pub struct PhiValue<'ctx> { } impl<'ctx> PhiValue<'ctx> { - pub(crate) unsafe fn new(value: LLVMValueRef) -> Self { + /// Get a value from an [LLVMValueRef]. + /// + /// # Safety + /// + /// The ref must be valid and of type phi. + 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..1e7aa063937 100644 --- a/src/values/ptr_value.rs +++ b/src/values/ptr_value.rs @@ -21,7 +21,12 @@ pub struct PointerValue<'ctx> { } impl<'ctx> PointerValue<'ctx> { - pub(crate) unsafe fn new(value: LLVMValueRef) -> Self { + /// Get a value from an [LLVMValueRef]. + /// + /// # Safety + /// + /// The ref must be valid and of type pointer. + 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..3933c410c07 100644 --- a/src/values/struct_value.rs +++ b/src/values/struct_value.rs @@ -17,7 +17,12 @@ pub struct StructValue<'ctx> { } impl<'ctx> StructValue<'ctx> { - pub(crate) unsafe fn new(value: LLVMValueRef) -> Self { + /// Get a value from an [LLVMValueRef]. + /// + /// # Safety + /// + /// The ref must be valid and of type struct. + 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 8ee8912c1c1..9cc0ab1f67b 100644 --- a/src/values/vec_value.rs +++ b/src/values/vec_value.rs @@ -21,7 +21,12 @@ pub struct VectorValue<'ctx> { } impl<'ctx> VectorValue<'ctx> { - pub(crate) unsafe fn new(vector_value: LLVMValueRef) -> Self { + /// Get a value from an [LLVMValueRef]. + /// + /// # Safety + /// + /// The ref must be valid and of type vector. + pub unsafe fn new(vector_value: LLVMValueRef) -> Self { assert!(!vector_value.is_null()); VectorValue {