1use std::ptr::NonNull;
6
7use llvm_sys::LLVMComdat;
8use llvm_sys::comdat::{LLVMComdatSelectionKind, LLVMGetComdatSelectionKind, LLVMSetComdatSelectionKind};
9use llvm_sys::prelude::LLVMComdatRef;
10
11use crate::support::assert_niche;
12
13#[llvm_enum(LLVMComdatSelectionKind)]
14#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
15pub enum ComdatSelectionKind {
17 #[llvm_variant(LLVMAnyComdatSelectionKind)]
19 Any,
20 #[llvm_variant(LLVMExactMatchComdatSelectionKind)]
22 ExactMatch,
23 #[llvm_variant(LLVMLargestComdatSelectionKind)]
25 Largest,
26 #[llvm_variant(LLVMNoDuplicatesComdatSelectionKind)]
28 NoDuplicates,
29 #[llvm_variant(LLVMSameSizeComdatSelectionKind)]
31 SameSize,
32}
33
34#[repr(transparent)]
36#[derive(Debug, PartialEq, Eq, Copy, Clone)]
37pub struct Comdat(pub(crate) NonNull<LLVMComdat>);
38const _: () = assert_niche::<Comdat>();
39
40impl Comdat {
41 pub unsafe fn new(comdat: LLVMComdatRef) -> Self {
47 debug_assert!(!comdat.is_null());
48
49 Comdat(unsafe { NonNull::new_unchecked(comdat) })
50 }
51
52 pub fn as_mut_ptr(&self) -> LLVMComdatRef {
54 self.0.as_ptr()
55 }
56
57 pub fn get_selection_kind(self) -> ComdatSelectionKind {
59 let kind_ptr = unsafe { LLVMGetComdatSelectionKind(self.as_mut_ptr()) };
60
61 ComdatSelectionKind::new(kind_ptr)
62 }
63
64 pub fn set_selection_kind(self, kind: ComdatSelectionKind) {
66 unsafe { LLVMSetComdatSelectionKind(self.as_mut_ptr(), kind.into()) }
67 }
68}