/rust/registry/src/index.crates.io-1949cf8c6b5b557f/inkwell-0.8.0/src/values/enums.rs
Line | Count | Source |
1 | | use llvm_sys::core::{LLVMGetTypeKind, LLVMGetValueKind, LLVMIsAInstruction, LLVMTypeOf}; |
2 | | use llvm_sys::prelude::LLVMValueRef; |
3 | | use llvm_sys::{LLVMTypeKind, LLVMValueKind}; |
4 | | |
5 | | use crate::types::{AnyTypeEnum, BasicTypeEnum}; |
6 | | use crate::values::traits::AsValueRef; |
7 | | use crate::values::{ |
8 | | ArrayValue, FloatValue, FunctionValue, InstructionValue, IntValue, MetadataValue, PhiValue, PointerValue, |
9 | | ScalableVectorValue, StructValue, VectorValue, |
10 | | }; |
11 | | |
12 | | use std::convert::TryFrom; |
13 | | use std::ffi::CStr; |
14 | | use std::fmt::{self, Display}; |
15 | | |
16 | | use super::AnyValue; |
17 | | |
18 | | macro_rules! enum_value_set { |
19 | | ($enum_name:ident: $($args:ident),*) => ( |
20 | | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
21 | | pub enum $enum_name<'ctx> { |
22 | | $( |
23 | | $args($args<'ctx>), |
24 | | )* |
25 | | } |
26 | | |
27 | | unsafe impl AsValueRef for $enum_name<'_> { |
28 | 13.8M | fn as_value_ref(&self) -> LLVMValueRef { |
29 | 13.8M | match *self { |
30 | | $( |
31 | 0 | $enum_name::$args(ref t) => t.as_value_ref(), |
32 | | )* |
33 | | } |
34 | 13.8M | } <inkwell::values::enums::BasicValueEnum as inkwell::values::traits::AsValueRef>::as_value_ref Line | Count | Source | 28 | 10.7M | fn as_value_ref(&self) -> LLVMValueRef { | 29 | 10.7M | match *self { | 30 | | $( | 31 | 0 | $enum_name::$args(ref t) => t.as_value_ref(), | 32 | | )* | 33 | | } | 34 | 10.7M | } |
Unexecuted instantiation: <inkwell::values::enums::AggregateValueEnum as inkwell::values::traits::AsValueRef>::as_value_ref <inkwell::values::enums::BasicMetadataValueEnum as inkwell::values::traits::AsValueRef>::as_value_ref Line | Count | Source | 28 | 3.18M | fn as_value_ref(&self) -> LLVMValueRef { | 29 | 3.18M | match *self { | 30 | | $( | 31 | 0 | $enum_name::$args(ref t) => t.as_value_ref(), | 32 | | )* | 33 | | } | 34 | 3.18M | } |
Unexecuted instantiation: <inkwell::values::enums::AnyValueEnum as inkwell::values::traits::AsValueRef>::as_value_ref |
35 | | } |
36 | | |
37 | | $( |
38 | | impl<'ctx> From<$args<'ctx>> for $enum_name<'ctx> { |
39 | 2.21M | fn from(value: $args) -> $enum_name { |
40 | 2.21M | $enum_name::$args(value) |
41 | 2.21M | } <inkwell::values::enums::BasicMetadataValueEnum as core::convert::From<inkwell::values::int_value::IntValue>>::from Line | Count | Source | 39 | 558k | fn from(value: $args) -> $enum_name { | 40 | 558k | $enum_name::$args(value) | 41 | 558k | } |
<inkwell::values::enums::BasicValueEnum as core::convert::From<inkwell::values::int_value::IntValue>>::from Line | Count | Source | 39 | 3.06k | fn from(value: $args) -> $enum_name { | 40 | 3.06k | $enum_name::$args(value) | 41 | 3.06k | } |
<inkwell::values::enums::BasicValueEnum as core::convert::From<inkwell::values::float_value::FloatValue>>::from Line | Count | Source | 39 | 962 | fn from(value: $args) -> $enum_name { | 40 | 962 | $enum_name::$args(value) | 41 | 962 | } |
<inkwell::values::enums::BasicValueEnum as core::convert::From<inkwell::values::ptr_value::PointerValue>>::from Line | Count | Source | 39 | 41.2k | fn from(value: $args) -> $enum_name { | 40 | 41.2k | $enum_name::$args(value) | 41 | 41.2k | } |
<inkwell::values::enums::BasicMetadataValueEnum as core::convert::From<inkwell::values::float_value::FloatValue>>::from Line | Count | Source | 39 | 14.1k | fn from(value: $args) -> $enum_name { | 40 | 14.1k | $enum_name::$args(value) | 41 | 14.1k | } |
<inkwell::values::enums::BasicMetadataValueEnum as core::convert::From<inkwell::values::ptr_value::PointerValue>>::from Line | Count | Source | 39 | 139k | fn from(value: $args) -> $enum_name { | 40 | 139k | $enum_name::$args(value) | 41 | 139k | } |
<inkwell::values::enums::BasicMetadataValueEnum as core::convert::From<inkwell::values::vec_value::VectorValue>>::from Line | Count | Source | 39 | 16.1k | fn from(value: $args) -> $enum_name { | 40 | 16.1k | $enum_name::$args(value) | 41 | 16.1k | } |
<inkwell::values::enums::BasicMetadataValueEnum as core::convert::From<inkwell::values::metadata_value::MetadataValue>>::from Line | Count | Source | 39 | 1.44M | fn from(value: $args) -> $enum_name { | 40 | 1.44M | $enum_name::$args(value) | 41 | 1.44M | } |
Unexecuted instantiation: <inkwell::values::enums::AnyValueEnum as core::convert::From<inkwell::values::instruction_value::InstructionValue>>::from Unexecuted instantiation: <inkwell::values::enums::AnyValueEnum as core::convert::From<inkwell::values::metadata_value::MetadataValue>>::from Unexecuted instantiation: <inkwell::values::enums::BasicValueEnum as core::convert::From<inkwell::values::struct_value::StructValue>>::from Unexecuted instantiation: <inkwell::values::enums::BasicValueEnum as core::convert::From<inkwell::values::vec_value::VectorValue>>::from Unexecuted instantiation: <inkwell::values::enums::BasicValueEnum as core::convert::From<inkwell::values::scalable_vec_value::ScalableVectorValue>>::from Unexecuted instantiation: <inkwell::values::enums::BasicMetadataValueEnum as core::convert::From<inkwell::values::array_value::ArrayValue>>::from Unexecuted instantiation: <inkwell::values::enums::BasicValueEnum as core::convert::From<inkwell::values::array_value::ArrayValue>>::from Unexecuted instantiation: <inkwell::values::enums::BasicMetadataValueEnum as core::convert::From<inkwell::values::struct_value::StructValue>>::from Unexecuted instantiation: <inkwell::values::enums::BasicMetadataValueEnum as core::convert::From<inkwell::values::scalable_vec_value::ScalableVectorValue>>::from Unexecuted instantiation: <inkwell::values::enums::AnyValueEnum as core::convert::From<inkwell::values::float_value::FloatValue>>::from Unexecuted instantiation: <inkwell::values::enums::AnyValueEnum as core::convert::From<inkwell::values::phi_value::PhiValue>>::from Unexecuted instantiation: <inkwell::values::enums::AnyValueEnum as core::convert::From<inkwell::values::fn_value::FunctionValue>>::from Unexecuted instantiation: <inkwell::values::enums::AnyValueEnum as core::convert::From<inkwell::values::ptr_value::PointerValue>>::from Unexecuted instantiation: <inkwell::values::enums::AnyValueEnum as core::convert::From<inkwell::values::struct_value::StructValue>>::from Unexecuted instantiation: <inkwell::values::enums::AnyValueEnum as core::convert::From<inkwell::values::vec_value::VectorValue>>::from Unexecuted instantiation: <inkwell::values::enums::AnyValueEnum as core::convert::From<inkwell::values::scalable_vec_value::ScalableVectorValue>>::from Unexecuted instantiation: <inkwell::values::enums::AggregateValueEnum as core::convert::From<inkwell::values::array_value::ArrayValue>>::from Unexecuted instantiation: <inkwell::values::enums::AggregateValueEnum as core::convert::From<inkwell::values::struct_value::StructValue>>::from Unexecuted instantiation: <inkwell::values::enums::AnyValueEnum as core::convert::From<inkwell::values::array_value::ArrayValue>>::from Unexecuted instantiation: <inkwell::values::enums::AnyValueEnum as core::convert::From<inkwell::values::int_value::IntValue>>::from |
42 | | } |
43 | | |
44 | | impl<'ctx> PartialEq<$args<'ctx>> for $enum_name<'ctx> { |
45 | 0 | fn eq(&self, other: &$args<'ctx>) -> bool { |
46 | 0 | self.as_value_ref() == other.as_value_ref() |
47 | 0 | } Unexecuted instantiation: <inkwell::values::enums::AnyValueEnum as core::cmp::PartialEq<inkwell::values::scalable_vec_value::ScalableVectorValue>>::eq Unexecuted instantiation: <inkwell::values::enums::AnyValueEnum as core::cmp::PartialEq<inkwell::values::instruction_value::InstructionValue>>::eq Unexecuted instantiation: <inkwell::values::enums::AnyValueEnum as core::cmp::PartialEq<inkwell::values::metadata_value::MetadataValue>>::eq Unexecuted instantiation: <inkwell::values::enums::BasicValueEnum as core::cmp::PartialEq<inkwell::values::struct_value::StructValue>>::eq Unexecuted instantiation: <inkwell::values::enums::BasicValueEnum as core::cmp::PartialEq<inkwell::values::vec_value::VectorValue>>::eq Unexecuted instantiation: <inkwell::values::enums::BasicValueEnum as core::cmp::PartialEq<inkwell::values::scalable_vec_value::ScalableVectorValue>>::eq Unexecuted instantiation: <inkwell::values::enums::BasicMetadataValueEnum as core::cmp::PartialEq<inkwell::values::array_value::ArrayValue>>::eq Unexecuted instantiation: <inkwell::values::enums::BasicValueEnum as core::cmp::PartialEq<inkwell::values::array_value::ArrayValue>>::eq Unexecuted instantiation: <inkwell::values::enums::BasicValueEnum as core::cmp::PartialEq<inkwell::values::int_value::IntValue>>::eq Unexecuted instantiation: <inkwell::values::enums::BasicValueEnum as core::cmp::PartialEq<inkwell::values::float_value::FloatValue>>::eq Unexecuted instantiation: <inkwell::values::enums::BasicValueEnum as core::cmp::PartialEq<inkwell::values::ptr_value::PointerValue>>::eq Unexecuted instantiation: <inkwell::values::enums::BasicMetadataValueEnum as core::cmp::PartialEq<inkwell::values::int_value::IntValue>>::eq Unexecuted instantiation: <inkwell::values::enums::BasicMetadataValueEnum as core::cmp::PartialEq<inkwell::values::float_value::FloatValue>>::eq Unexecuted instantiation: <inkwell::values::enums::BasicMetadataValueEnum as core::cmp::PartialEq<inkwell::values::ptr_value::PointerValue>>::eq Unexecuted instantiation: <inkwell::values::enums::BasicMetadataValueEnum as core::cmp::PartialEq<inkwell::values::struct_value::StructValue>>::eq Unexecuted instantiation: <inkwell::values::enums::BasicMetadataValueEnum as core::cmp::PartialEq<inkwell::values::vec_value::VectorValue>>::eq Unexecuted instantiation: <inkwell::values::enums::BasicMetadataValueEnum as core::cmp::PartialEq<inkwell::values::scalable_vec_value::ScalableVectorValue>>::eq Unexecuted instantiation: <inkwell::values::enums::BasicMetadataValueEnum as core::cmp::PartialEq<inkwell::values::metadata_value::MetadataValue>>::eq Unexecuted instantiation: <inkwell::values::enums::AnyValueEnum as core::cmp::PartialEq<inkwell::values::float_value::FloatValue>>::eq Unexecuted instantiation: <inkwell::values::enums::AnyValueEnum as core::cmp::PartialEq<inkwell::values::phi_value::PhiValue>>::eq Unexecuted instantiation: <inkwell::values::enums::AnyValueEnum as core::cmp::PartialEq<inkwell::values::fn_value::FunctionValue>>::eq Unexecuted instantiation: <inkwell::values::enums::AnyValueEnum as core::cmp::PartialEq<inkwell::values::ptr_value::PointerValue>>::eq Unexecuted instantiation: <inkwell::values::enums::AnyValueEnum as core::cmp::PartialEq<inkwell::values::struct_value::StructValue>>::eq Unexecuted instantiation: <inkwell::values::enums::AnyValueEnum as core::cmp::PartialEq<inkwell::values::vec_value::VectorValue>>::eq Unexecuted instantiation: <inkwell::values::enums::AggregateValueEnum as core::cmp::PartialEq<inkwell::values::array_value::ArrayValue>>::eq Unexecuted instantiation: <inkwell::values::enums::AggregateValueEnum as core::cmp::PartialEq<inkwell::values::struct_value::StructValue>>::eq Unexecuted instantiation: <inkwell::values::enums::AnyValueEnum as core::cmp::PartialEq<inkwell::values::array_value::ArrayValue>>::eq Unexecuted instantiation: <inkwell::values::enums::AnyValueEnum as core::cmp::PartialEq<inkwell::values::int_value::IntValue>>::eq |
48 | | } |
49 | | |
50 | | impl<'ctx> PartialEq<$enum_name<'ctx>> for $args<'ctx> { |
51 | 0 | fn eq(&self, other: &$enum_name<'ctx>) -> bool { |
52 | 0 | self.as_value_ref() == other.as_value_ref() |
53 | 0 | } Unexecuted instantiation: <inkwell::values::scalable_vec_value::ScalableVectorValue as core::cmp::PartialEq<inkwell::values::enums::AnyValueEnum>>::eq Unexecuted instantiation: <inkwell::values::instruction_value::InstructionValue as core::cmp::PartialEq<inkwell::values::enums::AnyValueEnum>>::eq Unexecuted instantiation: <inkwell::values::metadata_value::MetadataValue as core::cmp::PartialEq<inkwell::values::enums::AnyValueEnum>>::eq Unexecuted instantiation: <inkwell::values::struct_value::StructValue as core::cmp::PartialEq<inkwell::values::enums::BasicValueEnum>>::eq Unexecuted instantiation: <inkwell::values::vec_value::VectorValue as core::cmp::PartialEq<inkwell::values::enums::BasicValueEnum>>::eq Unexecuted instantiation: <inkwell::values::scalable_vec_value::ScalableVectorValue as core::cmp::PartialEq<inkwell::values::enums::BasicValueEnum>>::eq Unexecuted instantiation: <inkwell::values::array_value::ArrayValue as core::cmp::PartialEq<inkwell::values::enums::BasicMetadataValueEnum>>::eq Unexecuted instantiation: <inkwell::values::array_value::ArrayValue as core::cmp::PartialEq<inkwell::values::enums::BasicValueEnum>>::eq Unexecuted instantiation: <inkwell::values::int_value::IntValue as core::cmp::PartialEq<inkwell::values::enums::BasicValueEnum>>::eq Unexecuted instantiation: <inkwell::values::float_value::FloatValue as core::cmp::PartialEq<inkwell::values::enums::BasicValueEnum>>::eq Unexecuted instantiation: <inkwell::values::ptr_value::PointerValue as core::cmp::PartialEq<inkwell::values::enums::BasicValueEnum>>::eq Unexecuted instantiation: <inkwell::values::int_value::IntValue as core::cmp::PartialEq<inkwell::values::enums::BasicMetadataValueEnum>>::eq Unexecuted instantiation: <inkwell::values::float_value::FloatValue as core::cmp::PartialEq<inkwell::values::enums::BasicMetadataValueEnum>>::eq Unexecuted instantiation: <inkwell::values::ptr_value::PointerValue as core::cmp::PartialEq<inkwell::values::enums::BasicMetadataValueEnum>>::eq Unexecuted instantiation: <inkwell::values::struct_value::StructValue as core::cmp::PartialEq<inkwell::values::enums::BasicMetadataValueEnum>>::eq Unexecuted instantiation: <inkwell::values::vec_value::VectorValue as core::cmp::PartialEq<inkwell::values::enums::BasicMetadataValueEnum>>::eq Unexecuted instantiation: <inkwell::values::scalable_vec_value::ScalableVectorValue as core::cmp::PartialEq<inkwell::values::enums::BasicMetadataValueEnum>>::eq Unexecuted instantiation: <inkwell::values::metadata_value::MetadataValue as core::cmp::PartialEq<inkwell::values::enums::BasicMetadataValueEnum>>::eq Unexecuted instantiation: <inkwell::values::float_value::FloatValue as core::cmp::PartialEq<inkwell::values::enums::AnyValueEnum>>::eq Unexecuted instantiation: <inkwell::values::phi_value::PhiValue as core::cmp::PartialEq<inkwell::values::enums::AnyValueEnum>>::eq Unexecuted instantiation: <inkwell::values::fn_value::FunctionValue as core::cmp::PartialEq<inkwell::values::enums::AnyValueEnum>>::eq Unexecuted instantiation: <inkwell::values::ptr_value::PointerValue as core::cmp::PartialEq<inkwell::values::enums::AnyValueEnum>>::eq Unexecuted instantiation: <inkwell::values::struct_value::StructValue as core::cmp::PartialEq<inkwell::values::enums::AnyValueEnum>>::eq Unexecuted instantiation: <inkwell::values::vec_value::VectorValue as core::cmp::PartialEq<inkwell::values::enums::AnyValueEnum>>::eq Unexecuted instantiation: <inkwell::values::array_value::ArrayValue as core::cmp::PartialEq<inkwell::values::enums::AggregateValueEnum>>::eq Unexecuted instantiation: <inkwell::values::struct_value::StructValue as core::cmp::PartialEq<inkwell::values::enums::AggregateValueEnum>>::eq Unexecuted instantiation: <inkwell::values::array_value::ArrayValue as core::cmp::PartialEq<inkwell::values::enums::AnyValueEnum>>::eq Unexecuted instantiation: <inkwell::values::int_value::IntValue as core::cmp::PartialEq<inkwell::values::enums::AnyValueEnum>>::eq |
54 | | } |
55 | | |
56 | | impl<'ctx> TryFrom<$enum_name<'ctx>> for $args<'ctx> { |
57 | | type Error = (); |
58 | | |
59 | 0 | fn try_from(value: $enum_name<'ctx>) -> Result<Self, Self::Error> { |
60 | 0 | match value { |
61 | 0 | $enum_name::$args(ty) => Ok(ty), |
62 | 0 | _ => Err(()), |
63 | | } |
64 | 0 | } Unexecuted instantiation: <inkwell::values::scalable_vec_value::ScalableVectorValue as core::convert::TryFrom<inkwell::values::enums::AnyValueEnum>>::try_from Unexecuted instantiation: <inkwell::values::instruction_value::InstructionValue as core::convert::TryFrom<inkwell::values::enums::AnyValueEnum>>::try_from Unexecuted instantiation: <inkwell::values::struct_value::StructValue as core::convert::TryFrom<inkwell::values::enums::BasicValueEnum>>::try_from Unexecuted instantiation: <inkwell::values::vec_value::VectorValue as core::convert::TryFrom<inkwell::values::enums::BasicValueEnum>>::try_from Unexecuted instantiation: <inkwell::values::scalable_vec_value::ScalableVectorValue as core::convert::TryFrom<inkwell::values::enums::BasicValueEnum>>::try_from Unexecuted instantiation: <inkwell::values::array_value::ArrayValue as core::convert::TryFrom<inkwell::values::enums::BasicMetadataValueEnum>>::try_from Unexecuted instantiation: <inkwell::values::metadata_value::MetadataValue as core::convert::TryFrom<inkwell::values::enums::AnyValueEnum>>::try_from Unexecuted instantiation: <inkwell::values::array_value::ArrayValue as core::convert::TryFrom<inkwell::values::enums::BasicValueEnum>>::try_from Unexecuted instantiation: <inkwell::values::int_value::IntValue as core::convert::TryFrom<inkwell::values::enums::BasicValueEnum>>::try_from Unexecuted instantiation: <inkwell::values::float_value::FloatValue as core::convert::TryFrom<inkwell::values::enums::BasicValueEnum>>::try_from Unexecuted instantiation: <inkwell::values::ptr_value::PointerValue as core::convert::TryFrom<inkwell::values::enums::BasicValueEnum>>::try_from Unexecuted instantiation: <inkwell::values::int_value::IntValue as core::convert::TryFrom<inkwell::values::enums::BasicMetadataValueEnum>>::try_from Unexecuted instantiation: <inkwell::values::float_value::FloatValue as core::convert::TryFrom<inkwell::values::enums::BasicMetadataValueEnum>>::try_from Unexecuted instantiation: <inkwell::values::ptr_value::PointerValue as core::convert::TryFrom<inkwell::values::enums::BasicMetadataValueEnum>>::try_from Unexecuted instantiation: <inkwell::values::struct_value::StructValue as core::convert::TryFrom<inkwell::values::enums::BasicMetadataValueEnum>>::try_from Unexecuted instantiation: <inkwell::values::vec_value::VectorValue as core::convert::TryFrom<inkwell::values::enums::BasicMetadataValueEnum>>::try_from Unexecuted instantiation: <inkwell::values::scalable_vec_value::ScalableVectorValue as core::convert::TryFrom<inkwell::values::enums::BasicMetadataValueEnum>>::try_from Unexecuted instantiation: <inkwell::values::metadata_value::MetadataValue as core::convert::TryFrom<inkwell::values::enums::BasicMetadataValueEnum>>::try_from Unexecuted instantiation: <inkwell::values::int_value::IntValue as core::convert::TryFrom<inkwell::values::enums::AnyValueEnum>>::try_from Unexecuted instantiation: <inkwell::values::float_value::FloatValue as core::convert::TryFrom<inkwell::values::enums::AnyValueEnum>>::try_from Unexecuted instantiation: <inkwell::values::phi_value::PhiValue as core::convert::TryFrom<inkwell::values::enums::AnyValueEnum>>::try_from Unexecuted instantiation: <inkwell::values::fn_value::FunctionValue as core::convert::TryFrom<inkwell::values::enums::AnyValueEnum>>::try_from Unexecuted instantiation: <inkwell::values::ptr_value::PointerValue as core::convert::TryFrom<inkwell::values::enums::AnyValueEnum>>::try_from Unexecuted instantiation: <inkwell::values::struct_value::StructValue as core::convert::TryFrom<inkwell::values::enums::AnyValueEnum>>::try_from Unexecuted instantiation: <inkwell::values::vec_value::VectorValue as core::convert::TryFrom<inkwell::values::enums::AnyValueEnum>>::try_from Unexecuted instantiation: <inkwell::values::array_value::ArrayValue as core::convert::TryFrom<inkwell::values::enums::AggregateValueEnum>>::try_from Unexecuted instantiation: <inkwell::values::struct_value::StructValue as core::convert::TryFrom<inkwell::values::enums::AggregateValueEnum>>::try_from Unexecuted instantiation: <inkwell::values::array_value::ArrayValue as core::convert::TryFrom<inkwell::values::enums::AnyValueEnum>>::try_from |
65 | | } |
66 | | )* |
67 | | ); |
68 | | } |
69 | | |
70 | | enum_value_set! {AggregateValueEnum: ArrayValue, StructValue} |
71 | | enum_value_set! {AnyValueEnum: ArrayValue, IntValue, FloatValue, PhiValue, FunctionValue, PointerValue, StructValue, VectorValue, ScalableVectorValue, InstructionValue, MetadataValue} |
72 | | enum_value_set! {BasicValueEnum: ArrayValue, IntValue, FloatValue, PointerValue, StructValue, VectorValue, ScalableVectorValue} |
73 | | enum_value_set! {BasicMetadataValueEnum: ArrayValue, IntValue, FloatValue, PointerValue, StructValue, VectorValue, ScalableVectorValue, MetadataValue} |
74 | | |
75 | | impl<'ctx> AnyValueEnum<'ctx> { |
76 | | /// Get a value from an [LLVMValueRef]. |
77 | | /// |
78 | | /// # Safety |
79 | | /// |
80 | | /// The ref must be valid and of supported enum type options ([LLVMTypeKind]). |
81 | 0 | pub unsafe fn new(value: LLVMValueRef) -> Self { |
82 | 0 | match LLVMGetTypeKind(LLVMTypeOf(value)) { |
83 | | LLVMTypeKind::LLVMFloatTypeKind |
84 | | | LLVMTypeKind::LLVMFP128TypeKind |
85 | | | LLVMTypeKind::LLVMDoubleTypeKind |
86 | | | LLVMTypeKind::LLVMHalfTypeKind |
87 | | | LLVMTypeKind::LLVMX86_FP80TypeKind |
88 | 0 | | LLVMTypeKind::LLVMPPC_FP128TypeKind => AnyValueEnum::FloatValue(FloatValue::new(value)), |
89 | | #[cfg(any( |
90 | | feature = "llvm11-0", |
91 | | feature = "llvm12-0", |
92 | | feature = "llvm13-0", |
93 | | feature = "llvm14-0", |
94 | | feature = "llvm15-0", |
95 | | feature = "llvm16-0", |
96 | | feature = "llvm17-0", |
97 | | feature = "llvm18-1", |
98 | | feature = "llvm19-1", |
99 | | feature = "llvm20-1", |
100 | | feature = "llvm21-1", |
101 | | ))] |
102 | 0 | LLVMTypeKind::LLVMBFloatTypeKind => AnyValueEnum::FloatValue(FloatValue::new(value)), |
103 | 0 | LLVMTypeKind::LLVMIntegerTypeKind => AnyValueEnum::IntValue(IntValue::new(value)), |
104 | 0 | LLVMTypeKind::LLVMStructTypeKind => AnyValueEnum::StructValue(StructValue::new(value)), |
105 | 0 | LLVMTypeKind::LLVMPointerTypeKind => match LLVMGetValueKind(value) { |
106 | 0 | LLVMValueKind::LLVMFunctionValueKind => AnyValueEnum::FunctionValue(FunctionValue::new(value).unwrap()), |
107 | 0 | _ => AnyValueEnum::PointerValue(PointerValue::new(value)), |
108 | | }, |
109 | 0 | LLVMTypeKind::LLVMArrayTypeKind => AnyValueEnum::ArrayValue(ArrayValue::new(value)), |
110 | 0 | LLVMTypeKind::LLVMVectorTypeKind => AnyValueEnum::VectorValue(VectorValue::new(value)), |
111 | | #[cfg(any( |
112 | | feature = "llvm11-0", |
113 | | feature = "llvm12-0", |
114 | | feature = "llvm13-0", |
115 | | feature = "llvm14-0", |
116 | | feature = "llvm15-0", |
117 | | feature = "llvm16-0", |
118 | | feature = "llvm17-0", |
119 | | feature = "llvm18-1", |
120 | | feature = "llvm19-1", |
121 | | feature = "llvm20-1", |
122 | | feature = "llvm21-1", |
123 | | ))] |
124 | | LLVMTypeKind::LLVMScalableVectorTypeKind => { |
125 | 0 | AnyValueEnum::ScalableVectorValue(ScalableVectorValue::new(value)) |
126 | | }, |
127 | 0 | LLVMTypeKind::LLVMFunctionTypeKind => AnyValueEnum::FunctionValue(FunctionValue::new(value).unwrap()), |
128 | | LLVMTypeKind::LLVMVoidTypeKind => { |
129 | 0 | if LLVMIsAInstruction(value).is_null() { |
130 | 0 | panic!("Void value isn't an instruction."); |
131 | 0 | } |
132 | 0 | AnyValueEnum::InstructionValue(InstructionValue::new(value)) |
133 | | }, |
134 | 0 | LLVMTypeKind::LLVMMetadataTypeKind => panic!("Metadata values are not supported as AnyValue's."), |
135 | 0 | _ => panic!("The given type is not supported."), |
136 | | } |
137 | 0 | } |
138 | | |
139 | 0 | pub fn get_type(&self) -> AnyTypeEnum<'ctx> { |
140 | 0 | unsafe { AnyTypeEnum::new(LLVMTypeOf(self.as_value_ref())) } |
141 | 0 | } |
142 | | |
143 | 0 | pub fn is_array_value(self) -> bool { |
144 | 0 | matches!(self, AnyValueEnum::ArrayValue(_)) |
145 | 0 | } |
146 | | |
147 | 0 | pub fn is_int_value(self) -> bool { |
148 | 0 | matches!(self, AnyValueEnum::IntValue(_)) |
149 | 0 | } |
150 | | |
151 | 0 | pub fn is_float_value(self) -> bool { |
152 | 0 | matches!(self, AnyValueEnum::FloatValue(_)) |
153 | 0 | } |
154 | | |
155 | 0 | pub fn is_phi_value(self) -> bool { |
156 | 0 | matches!(self, AnyValueEnum::PhiValue(_)) |
157 | 0 | } |
158 | | |
159 | 0 | pub fn is_function_value(self) -> bool { |
160 | 0 | matches!(self, AnyValueEnum::FunctionValue(_)) |
161 | 0 | } |
162 | | |
163 | 0 | pub fn is_pointer_value(self) -> bool { |
164 | 0 | matches!(self, AnyValueEnum::PointerValue(_)) |
165 | 0 | } |
166 | | |
167 | 0 | pub fn is_struct_value(self) -> bool { |
168 | 0 | matches!(self, AnyValueEnum::StructValue(_)) |
169 | 0 | } |
170 | | |
171 | 0 | pub fn is_vector_value(self) -> bool { |
172 | 0 | matches!(self, AnyValueEnum::VectorValue(_)) |
173 | 0 | } |
174 | | |
175 | 0 | pub fn is_scalable_vector_value(self) -> bool { |
176 | 0 | matches!(self, AnyValueEnum::ScalableVectorValue(_)) |
177 | 0 | } |
178 | | |
179 | 0 | pub fn is_instruction_value(self) -> bool { |
180 | 0 | matches!(self, AnyValueEnum::InstructionValue(_)) |
181 | 0 | } |
182 | | |
183 | | #[track_caller] |
184 | 0 | pub fn into_array_value(self) -> ArrayValue<'ctx> { |
185 | 0 | if let AnyValueEnum::ArrayValue(v) = self { |
186 | 0 | v |
187 | | } else { |
188 | 0 | panic!("Found {self:?} but expected the ArrayValue variant") |
189 | | } |
190 | 0 | } |
191 | | |
192 | | #[track_caller] |
193 | 0 | pub fn into_int_value(self) -> IntValue<'ctx> { |
194 | 0 | if let AnyValueEnum::IntValue(v) = self { |
195 | 0 | v |
196 | | } else { |
197 | 0 | panic!("Found {self:?} but expected the IntValue variant") |
198 | | } |
199 | 0 | } |
200 | | |
201 | | #[track_caller] |
202 | 0 | pub fn into_float_value(self) -> FloatValue<'ctx> { |
203 | 0 | if let AnyValueEnum::FloatValue(v) = self { |
204 | 0 | v |
205 | | } else { |
206 | 0 | panic!("Found {self:?} but expected the FloatValue variant") |
207 | | } |
208 | 0 | } |
209 | | |
210 | | #[track_caller] |
211 | 0 | pub fn into_phi_value(self) -> PhiValue<'ctx> { |
212 | 0 | if let AnyValueEnum::PhiValue(v) = self { |
213 | 0 | v |
214 | | } else { |
215 | 0 | panic!("Found {self:?} but expected the PhiValue variant") |
216 | | } |
217 | 0 | } |
218 | | |
219 | | #[track_caller] |
220 | 0 | pub fn into_function_value(self) -> FunctionValue<'ctx> { |
221 | 0 | if let AnyValueEnum::FunctionValue(v) = self { |
222 | 0 | v |
223 | | } else { |
224 | 0 | panic!("Found {self:?} but expected the FunctionValue variant") |
225 | | } |
226 | 0 | } |
227 | | |
228 | | #[track_caller] |
229 | 0 | pub fn into_pointer_value(self) -> PointerValue<'ctx> { |
230 | 0 | if let AnyValueEnum::PointerValue(v) = self { |
231 | 0 | v |
232 | | } else { |
233 | 0 | panic!("Found {self:?} but expected the PointerValue variant") |
234 | | } |
235 | 0 | } |
236 | | |
237 | | #[track_caller] |
238 | 0 | pub fn into_struct_value(self) -> StructValue<'ctx> { |
239 | 0 | if let AnyValueEnum::StructValue(v) = self { |
240 | 0 | v |
241 | | } else { |
242 | 0 | panic!("Found {self:?} but expected the StructValue variant") |
243 | | } |
244 | 0 | } |
245 | | |
246 | | #[track_caller] |
247 | 0 | pub fn into_vector_value(self) -> VectorValue<'ctx> { |
248 | 0 | if let AnyValueEnum::VectorValue(v) = self { |
249 | 0 | v |
250 | | } else { |
251 | 0 | panic!("Found {self:?} but expected the VectorValue variant") |
252 | | } |
253 | 0 | } |
254 | | |
255 | | #[track_caller] |
256 | 0 | pub fn into_scalable_vector_value(self) -> ScalableVectorValue<'ctx> { |
257 | 0 | if let AnyValueEnum::ScalableVectorValue(v) = self { |
258 | 0 | v |
259 | | } else { |
260 | 0 | panic!("Found {self:?} but expected the ScalableVectorValue variant") |
261 | | } |
262 | 0 | } |
263 | | |
264 | | #[track_caller] |
265 | 0 | pub fn into_instruction_value(self) -> InstructionValue<'ctx> { |
266 | 0 | if let AnyValueEnum::InstructionValue(v) = self { |
267 | 0 | v |
268 | | } else { |
269 | 0 | panic!("Found {self:?} but expected the InstructionValue variant") |
270 | | } |
271 | 0 | } |
272 | | } |
273 | | |
274 | | impl<'ctx> BasicValueEnum<'ctx> { |
275 | | /// Get a value from an [LLVMValueRef]. |
276 | | /// |
277 | | /// # Safety |
278 | | /// |
279 | | /// The ref must be valid and of supported enum type options ([LLVMTypeKind]). |
280 | 20.1M | pub unsafe fn new(value: LLVMValueRef) -> Self { |
281 | 20.1M | match LLVMGetTypeKind(LLVMTypeOf(value)) { |
282 | | LLVMTypeKind::LLVMFloatTypeKind |
283 | | | LLVMTypeKind::LLVMFP128TypeKind |
284 | | | LLVMTypeKind::LLVMDoubleTypeKind |
285 | | | LLVMTypeKind::LLVMHalfTypeKind |
286 | | | LLVMTypeKind::LLVMX86_FP80TypeKind |
287 | 4.09M | | LLVMTypeKind::LLVMPPC_FP128TypeKind => BasicValueEnum::FloatValue(FloatValue::new(value)), |
288 | | #[cfg(any( |
289 | | feature = "llvm11-0", |
290 | | feature = "llvm12-0", |
291 | | feature = "llvm13-0", |
292 | | feature = "llvm14-0", |
293 | | feature = "llvm15-0", |
294 | | feature = "llvm16-0", |
295 | | feature = "llvm17-0", |
296 | | feature = "llvm18-1", |
297 | | feature = "llvm19-1", |
298 | | feature = "llvm20-1", |
299 | | feature = "llvm21-1", |
300 | | ))] |
301 | 0 | LLVMTypeKind::LLVMBFloatTypeKind => BasicValueEnum::FloatValue(FloatValue::new(value)), |
302 | 7.69M | LLVMTypeKind::LLVMIntegerTypeKind => BasicValueEnum::IntValue(IntValue::new(value)), |
303 | 147k | LLVMTypeKind::LLVMStructTypeKind => BasicValueEnum::StructValue(StructValue::new(value)), |
304 | 8.12M | LLVMTypeKind::LLVMPointerTypeKind => BasicValueEnum::PointerValue(PointerValue::new(value)), |
305 | 0 | LLVMTypeKind::LLVMArrayTypeKind => BasicValueEnum::ArrayValue(ArrayValue::new(value)), |
306 | 95.5k | LLVMTypeKind::LLVMVectorTypeKind => BasicValueEnum::VectorValue(VectorValue::new(value)), |
307 | | #[cfg(any( |
308 | | feature = "llvm11-0", |
309 | | feature = "llvm12-0", |
310 | | feature = "llvm13-0", |
311 | | feature = "llvm14-0", |
312 | | feature = "llvm15-0", |
313 | | feature = "llvm16-0", |
314 | | feature = "llvm17-0", |
315 | | feature = "llvm18-1", |
316 | | feature = "llvm19-1", |
317 | | feature = "llvm20-1", |
318 | | feature = "llvm21-1", |
319 | | ))] |
320 | | LLVMTypeKind::LLVMScalableVectorTypeKind => { |
321 | 0 | BasicValueEnum::ScalableVectorValue(ScalableVectorValue::new(value)) |
322 | | }, |
323 | 0 | _ => unreachable!("The given type is not a basic type."), |
324 | | } |
325 | 20.1M | } |
326 | | |
327 | | /// Get the name of the `BasicValueEnum`. |
328 | 0 | pub fn get_name(&self) -> &CStr { |
329 | 0 | match self { |
330 | 0 | BasicValueEnum::ArrayValue(v) => v.get_name(), |
331 | 0 | BasicValueEnum::IntValue(v) => v.get_name(), |
332 | 0 | BasicValueEnum::FloatValue(v) => v.get_name(), |
333 | 0 | BasicValueEnum::PointerValue(v) => v.get_name(), |
334 | 0 | BasicValueEnum::StructValue(v) => v.get_name(), |
335 | 0 | BasicValueEnum::VectorValue(v) => v.get_name(), |
336 | 0 | BasicValueEnum::ScalableVectorValue(v) => v.get_name(), |
337 | | } |
338 | 0 | } |
339 | | |
340 | | /// Set name of the `BasicValueEnum`. |
341 | 78.1k | pub fn set_name(&self, name: &str) { |
342 | 78.1k | match self { |
343 | 0 | BasicValueEnum::ArrayValue(v) => v.set_name(name), |
344 | 0 | BasicValueEnum::IntValue(v) => v.set_name(name), |
345 | 0 | BasicValueEnum::FloatValue(v) => v.set_name(name), |
346 | 78.1k | BasicValueEnum::PointerValue(v) => v.set_name(name), |
347 | 0 | BasicValueEnum::StructValue(v) => v.set_name(name), |
348 | 0 | BasicValueEnum::VectorValue(v) => v.set_name(name), |
349 | 0 | BasicValueEnum::ScalableVectorValue(v) => v.set_name(name), |
350 | | } |
351 | 78.1k | } |
352 | | |
353 | 223k | pub fn get_type(&self) -> BasicTypeEnum<'ctx> { |
354 | 223k | unsafe { BasicTypeEnum::new(LLVMTypeOf(self.as_value_ref())) } |
355 | 223k | } |
356 | | |
357 | 0 | pub fn is_array_value(self) -> bool { |
358 | 0 | matches!(self, BasicValueEnum::ArrayValue(_)) |
359 | 0 | } |
360 | | |
361 | 6.41k | pub fn is_int_value(self) -> bool { |
362 | 6.41k | matches!(self, BasicValueEnum::IntValue(_)) |
363 | 6.41k | } |
364 | | |
365 | 8.03k | pub fn is_float_value(self) -> bool { |
366 | 8.03k | matches!(self, BasicValueEnum::FloatValue(_)) |
367 | 8.03k | } |
368 | | |
369 | 153 | pub fn is_pointer_value(self) -> bool { |
370 | 153 | matches!(self, BasicValueEnum::PointerValue(_)) |
371 | 153 | } |
372 | | |
373 | 0 | pub fn is_struct_value(self) -> bool { |
374 | 0 | matches!(self, BasicValueEnum::StructValue(_)) |
375 | 0 | } |
376 | | |
377 | 0 | pub fn is_vector_value(self) -> bool { |
378 | 0 | matches!(self, BasicValueEnum::VectorValue(_)) |
379 | 0 | } |
380 | | |
381 | 0 | pub fn is_scalable_vector_value(self) -> bool { |
382 | 0 | matches!(self, BasicValueEnum::ScalableVectorValue(_)) |
383 | 0 | } |
384 | | |
385 | | #[track_caller] |
386 | 0 | pub fn into_array_value(self) -> ArrayValue<'ctx> { |
387 | 0 | if let BasicValueEnum::ArrayValue(v) = self { |
388 | 0 | v |
389 | | } else { |
390 | 0 | panic!("Found {self:?} but expected the ArrayValue variant") |
391 | | } |
392 | 0 | } |
393 | | |
394 | | #[track_caller] |
395 | 1.68M | pub fn into_int_value(self) -> IntValue<'ctx> { |
396 | 1.68M | if let BasicValueEnum::IntValue(v) = self { |
397 | 1.68M | v |
398 | | } else { |
399 | 0 | panic!("Found {self:?} but expected the IntValue variant") |
400 | | } |
401 | 1.68M | } |
402 | | |
403 | | #[track_caller] |
404 | 261k | pub fn into_float_value(self) -> FloatValue<'ctx> { |
405 | 261k | if let BasicValueEnum::FloatValue(v) = self { |
406 | 261k | v |
407 | | } else { |
408 | 0 | panic!("Found {self:?} but expected the FloatValue variant") |
409 | | } |
410 | 261k | } |
411 | | |
412 | | #[track_caller] |
413 | 6.98M | pub fn into_pointer_value(self) -> PointerValue<'ctx> { |
414 | 6.98M | if let BasicValueEnum::PointerValue(v) = self { |
415 | 6.98M | v |
416 | | } else { |
417 | 0 | panic!("Found {self:?} but expected PointerValue variant") |
418 | | } |
419 | 6.98M | } |
420 | | |
421 | | #[track_caller] |
422 | 144k | pub fn into_struct_value(self) -> StructValue<'ctx> { |
423 | 144k | if let BasicValueEnum::StructValue(v) = self { |
424 | 144k | v |
425 | | } else { |
426 | 0 | panic!("Found {self:?} but expected the StructValue variant") |
427 | | } |
428 | 144k | } |
429 | | |
430 | | #[track_caller] |
431 | 76.7k | pub fn into_vector_value(self) -> VectorValue<'ctx> { |
432 | 76.7k | if let BasicValueEnum::VectorValue(v) = self { |
433 | 76.7k | v |
434 | | } else { |
435 | 0 | panic!("Found {self:?} but expected the VectorValue variant") |
436 | | } |
437 | 76.7k | } |
438 | | |
439 | | #[track_caller] |
440 | 0 | pub fn into_scalable_vector_value(self) -> ScalableVectorValue<'ctx> { |
441 | 0 | if let BasicValueEnum::ScalableVectorValue(v) = self { |
442 | 0 | v |
443 | | } else { |
444 | 0 | panic!("Found {self:?} but expected the ScalableVectorValue variant") |
445 | | } |
446 | 0 | } |
447 | | } |
448 | | |
449 | | impl<'ctx> AggregateValueEnum<'ctx> { |
450 | | /// Get a value from an [LLVMValueRef]. |
451 | | /// |
452 | | /// # Safety |
453 | | /// |
454 | | /// The ref must be valid and of supported aggregate type enum options ([LLVMTypeKind]). |
455 | 2.21M | pub unsafe fn new(value: LLVMValueRef) -> Self { |
456 | 2.21M | match LLVMGetTypeKind(LLVMTypeOf(value)) { |
457 | 0 | LLVMTypeKind::LLVMArrayTypeKind => AggregateValueEnum::ArrayValue(ArrayValue::new(value)), |
458 | 2.21M | LLVMTypeKind::LLVMStructTypeKind => AggregateValueEnum::StructValue(StructValue::new(value)), |
459 | 0 | _ => unreachable!("The given type is not an aggregate type."), |
460 | | } |
461 | 2.21M | } |
462 | | |
463 | 0 | pub fn is_array_value(self) -> bool { |
464 | 0 | matches!(self, AggregateValueEnum::ArrayValue(_)) |
465 | 0 | } |
466 | | |
467 | 0 | pub fn is_struct_value(self) -> bool { |
468 | 0 | matches!(self, AggregateValueEnum::StructValue(_)) |
469 | 0 | } |
470 | | |
471 | | #[track_caller] |
472 | 0 | pub fn into_array_value(self) -> ArrayValue<'ctx> { |
473 | 0 | if let AggregateValueEnum::ArrayValue(v) = self { |
474 | 0 | v |
475 | | } else { |
476 | 0 | panic!("Found {self:?} but expected the ArrayValue variant") |
477 | | } |
478 | 0 | } |
479 | | |
480 | | #[track_caller] |
481 | 670k | pub fn into_struct_value(self) -> StructValue<'ctx> { |
482 | 670k | if let AggregateValueEnum::StructValue(v) = self { |
483 | 670k | v |
484 | | } else { |
485 | 0 | panic!("Found {self:?} but expected the StructValue variant") |
486 | | } |
487 | 670k | } |
488 | | } |
489 | | |
490 | | impl<'ctx> BasicMetadataValueEnum<'ctx> { |
491 | 1.90M | pub(crate) unsafe fn new(value: LLVMValueRef) -> Self { |
492 | 1.90M | match LLVMGetTypeKind(LLVMTypeOf(value)) { |
493 | | LLVMTypeKind::LLVMFloatTypeKind |
494 | | | LLVMTypeKind::LLVMFP128TypeKind |
495 | | | LLVMTypeKind::LLVMDoubleTypeKind |
496 | | | LLVMTypeKind::LLVMHalfTypeKind |
497 | | | LLVMTypeKind::LLVMX86_FP80TypeKind |
498 | 516k | | LLVMTypeKind::LLVMPPC_FP128TypeKind => BasicMetadataValueEnum::FloatValue(FloatValue::new(value)), |
499 | | #[cfg(any( |
500 | | feature = "llvm11-0", |
501 | | feature = "llvm12-0", |
502 | | feature = "llvm13-0", |
503 | | feature = "llvm14-0", |
504 | | feature = "llvm15-0", |
505 | | feature = "llvm16-0", |
506 | | feature = "llvm17-0", |
507 | | feature = "llvm18-1", |
508 | | feature = "llvm19-1", |
509 | | feature = "llvm20-1", |
510 | | feature = "llvm21-1", |
511 | | ))] |
512 | 0 | LLVMTypeKind::LLVMBFloatTypeKind => BasicMetadataValueEnum::FloatValue(FloatValue::new(value)), |
513 | 670k | LLVMTypeKind::LLVMIntegerTypeKind => BasicMetadataValueEnum::IntValue(IntValue::new(value)), |
514 | 0 | LLVMTypeKind::LLVMStructTypeKind => BasicMetadataValueEnum::StructValue(StructValue::new(value)), |
515 | 715k | LLVMTypeKind::LLVMPointerTypeKind => BasicMetadataValueEnum::PointerValue(PointerValue::new(value)), |
516 | 0 | LLVMTypeKind::LLVMArrayTypeKind => BasicMetadataValueEnum::ArrayValue(ArrayValue::new(value)), |
517 | 322 | LLVMTypeKind::LLVMVectorTypeKind => BasicMetadataValueEnum::VectorValue(VectorValue::new(value)), |
518 | | #[cfg(any( |
519 | | feature = "llvm11-0", |
520 | | feature = "llvm12-0", |
521 | | feature = "llvm13-0", |
522 | | feature = "llvm14-0", |
523 | | feature = "llvm15-0", |
524 | | feature = "llvm16-0", |
525 | | feature = "llvm17-0", |
526 | | feature = "llvm18-1", |
527 | | feature = "llvm19-1", |
528 | | feature = "llvm20-1", |
529 | | feature = "llvm21-1", |
530 | | ))] |
531 | | LLVMTypeKind::LLVMScalableVectorTypeKind => { |
532 | 0 | BasicMetadataValueEnum::ScalableVectorValue(ScalableVectorValue::new(value)) |
533 | | }, |
534 | 0 | LLVMTypeKind::LLVMMetadataTypeKind => BasicMetadataValueEnum::MetadataValue(MetadataValue::new(value)), |
535 | 0 | _ => unreachable!("Unsupported type"), |
536 | | } |
537 | 1.90M | } |
538 | | |
539 | 0 | pub fn is_array_value(self) -> bool { |
540 | 0 | matches!(self, BasicMetadataValueEnum::ArrayValue(_)) |
541 | 0 | } |
542 | | |
543 | 0 | pub fn is_int_value(self) -> bool { |
544 | 0 | matches!(self, BasicMetadataValueEnum::IntValue(_)) |
545 | 0 | } |
546 | | |
547 | 0 | pub fn is_float_value(self) -> bool { |
548 | 0 | matches!(self, BasicMetadataValueEnum::FloatValue(_)) |
549 | 0 | } |
550 | | |
551 | 0 | pub fn is_pointer_value(self) -> bool { |
552 | 0 | matches!(self, BasicMetadataValueEnum::PointerValue(_)) |
553 | 0 | } |
554 | | |
555 | 0 | pub fn is_struct_value(self) -> bool { |
556 | 0 | matches!(self, BasicMetadataValueEnum::StructValue(_)) |
557 | 0 | } |
558 | | |
559 | 0 | pub fn is_vector_value(self) -> bool { |
560 | 0 | matches!(self, BasicMetadataValueEnum::VectorValue(_)) |
561 | 0 | } |
562 | | |
563 | 0 | pub fn is_scalable_vector_value(self) -> bool { |
564 | 0 | matches!(self, BasicMetadataValueEnum::ScalableVectorValue(_)) |
565 | 0 | } |
566 | | |
567 | 0 | pub fn is_metadata_value(self) -> bool { |
568 | 0 | matches!(self, BasicMetadataValueEnum::MetadataValue(_)) |
569 | 0 | } |
570 | | |
571 | | #[track_caller] |
572 | 0 | pub fn into_array_value(self) -> ArrayValue<'ctx> { |
573 | 0 | if let BasicMetadataValueEnum::ArrayValue(v) = self { |
574 | 0 | v |
575 | | } else { |
576 | 0 | panic!("Found {self:?} but expected the ArrayValue variant") |
577 | | } |
578 | 0 | } |
579 | | |
580 | | #[track_caller] |
581 | 0 | pub fn into_int_value(self) -> IntValue<'ctx> { |
582 | 0 | if let BasicMetadataValueEnum::IntValue(v) = self { |
583 | 0 | v |
584 | | } else { |
585 | 0 | panic!("Found {self:?} but expected the IntValue variant") |
586 | | } |
587 | 0 | } |
588 | | |
589 | | #[track_caller] |
590 | 0 | pub fn into_float_value(self) -> FloatValue<'ctx> { |
591 | 0 | if let BasicMetadataValueEnum::FloatValue(v) = self { |
592 | 0 | v |
593 | | } else { |
594 | 0 | panic!("Found {self:?} but expected FloatValue variant") |
595 | | } |
596 | 0 | } |
597 | | |
598 | | #[track_caller] |
599 | 0 | pub fn into_pointer_value(self) -> PointerValue<'ctx> { |
600 | 0 | if let BasicMetadataValueEnum::PointerValue(v) = self { |
601 | 0 | v |
602 | | } else { |
603 | 0 | panic!("Found {self:?} but expected the PointerValue variant") |
604 | | } |
605 | 0 | } |
606 | | |
607 | | #[track_caller] |
608 | 0 | pub fn into_struct_value(self) -> StructValue<'ctx> { |
609 | 0 | if let BasicMetadataValueEnum::StructValue(v) = self { |
610 | 0 | v |
611 | | } else { |
612 | 0 | panic!("Found {self:?} but expected the StructValue variant") |
613 | | } |
614 | 0 | } |
615 | | |
616 | | #[track_caller] |
617 | 0 | pub fn into_vector_value(self) -> VectorValue<'ctx> { |
618 | 0 | if let BasicMetadataValueEnum::VectorValue(v) = self { |
619 | 0 | v |
620 | | } else { |
621 | 0 | panic!("Found {self:?} but expected the VectorValue variant") |
622 | | } |
623 | 0 | } |
624 | | |
625 | | #[track_caller] |
626 | 0 | pub fn into_scalable_vector_value(self) -> ScalableVectorValue<'ctx> { |
627 | 0 | if let BasicMetadataValueEnum::ScalableVectorValue(v) = self { |
628 | 0 | v |
629 | | } else { |
630 | 0 | panic!("Found {self:?} but expected the ScalableVectorValue variant") |
631 | | } |
632 | 0 | } |
633 | | |
634 | | #[track_caller] |
635 | 0 | pub fn into_metadata_value(self) -> MetadataValue<'ctx> { |
636 | 0 | if let BasicMetadataValueEnum::MetadataValue(v) = self { |
637 | 0 | v |
638 | | } else { |
639 | 0 | panic!("Found {self:?} but expected MetaData variant") |
640 | | } |
641 | 0 | } |
642 | | } |
643 | | |
644 | | impl<'ctx> From<BasicValueEnum<'ctx>> for AnyValueEnum<'ctx> { |
645 | 0 | fn from(value: BasicValueEnum<'ctx>) -> Self { |
646 | 0 | unsafe { AnyValueEnum::new(value.as_value_ref()) } |
647 | 0 | } |
648 | | } |
649 | | |
650 | | impl<'ctx> From<BasicValueEnum<'ctx>> for BasicMetadataValueEnum<'ctx> { |
651 | 1.90M | fn from(value: BasicValueEnum<'ctx>) -> Self { |
652 | 1.90M | unsafe { BasicMetadataValueEnum::new(value.as_value_ref()) } |
653 | 1.90M | } |
654 | | } |
655 | | |
656 | | impl<'ctx> TryFrom<AnyValueEnum<'ctx>> for BasicValueEnum<'ctx> { |
657 | | type Error = (); |
658 | | |
659 | 0 | fn try_from(value: AnyValueEnum<'ctx>) -> Result<Self, Self::Error> { |
660 | | use AnyValueEnum::*; |
661 | 0 | Ok(match value { |
662 | 0 | ArrayValue(av) => av.into(), |
663 | 0 | IntValue(iv) => iv.into(), |
664 | 0 | FloatValue(fv) => fv.into(), |
665 | 0 | PointerValue(pv) => pv.into(), |
666 | 0 | StructValue(sv) => sv.into(), |
667 | 0 | VectorValue(vv) => vv.into(), |
668 | 0 | ScalableVectorValue(vv) => vv.into(), |
669 | 0 | MetadataValue(_) | PhiValue(_) | FunctionValue(_) | InstructionValue(_) => return Err(()), |
670 | | }) |
671 | 0 | } |
672 | | } |
673 | | |
674 | | impl<'ctx> TryFrom<AnyValueEnum<'ctx>> for BasicMetadataValueEnum<'ctx> { |
675 | | type Error = (); |
676 | | |
677 | 0 | fn try_from(value: AnyValueEnum<'ctx>) -> Result<Self, Self::Error> { |
678 | | use AnyValueEnum::*; |
679 | 0 | Ok(match value { |
680 | 0 | ArrayValue(av) => av.into(), |
681 | 0 | IntValue(iv) => iv.into(), |
682 | 0 | FloatValue(fv) => fv.into(), |
683 | 0 | PointerValue(pv) => pv.into(), |
684 | 0 | StructValue(sv) => sv.into(), |
685 | 0 | VectorValue(vv) => vv.into(), |
686 | 0 | ScalableVectorValue(vv) => vv.into(), |
687 | 0 | MetadataValue(mv) => mv.into(), |
688 | 0 | PhiValue(_) | FunctionValue(_) | InstructionValue(_) => return Err(()), |
689 | | }) |
690 | 0 | } |
691 | | } |
692 | | |
693 | | impl<'ctx> TryFrom<BasicMetadataValueEnum<'ctx>> for BasicValueEnum<'ctx> { |
694 | | type Error = (); |
695 | | |
696 | 0 | fn try_from(value: BasicMetadataValueEnum<'ctx>) -> Result<Self, Self::Error> { |
697 | | use BasicMetadataValueEnum::*; |
698 | 0 | Ok(match value { |
699 | 0 | ArrayValue(av) => av.into(), |
700 | 0 | IntValue(iv) => iv.into(), |
701 | 0 | FloatValue(fv) => fv.into(), |
702 | 0 | PointerValue(pv) => pv.into(), |
703 | 0 | StructValue(sv) => sv.into(), |
704 | 0 | VectorValue(vv) => vv.into(), |
705 | 0 | ScalableVectorValue(vv) => vv.into(), |
706 | 0 | MetadataValue(_) => return Err(()), |
707 | | }) |
708 | 0 | } |
709 | | } |
710 | | |
711 | | impl Display for AggregateValueEnum<'_> { |
712 | 0 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
713 | 0 | write!(f, "{}", self.print_to_string()) |
714 | 0 | } |
715 | | } |
716 | | |
717 | | impl Display for AnyValueEnum<'_> { |
718 | 0 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
719 | 0 | write!(f, "{}", self.print_to_string()) |
720 | 0 | } |
721 | | } |
722 | | |
723 | | impl Display for BasicValueEnum<'_> { |
724 | 0 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
725 | 0 | write!(f, "{}", self.print_to_string()) |
726 | 0 | } |
727 | | } |
728 | | |
729 | | impl Display for BasicMetadataValueEnum<'_> { |
730 | 0 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
731 | 0 | write!(f, "{}", self.print_to_string()) |
732 | 0 | } |
733 | | } |