1use llvm_sys::comdat::{LLVMComdatSelectionKind, LLVMGetComdatSelectionKind, LLVMSetComdatSelectionKind};
6use llvm_sys::prelude::LLVMComdatRef;
7
8#[llvm_enum(LLVMComdatSelectionKind)]
9#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
10pub enum ComdatSelectionKind {
12 #[llvm_variant(LLVMAnyComdatSelectionKind)]
14 Any,
15 #[llvm_variant(LLVMExactMatchComdatSelectionKind)]
17 ExactMatch,
18 #[llvm_variant(LLVMLargestComdatSelectionKind)]
20 Largest,
21 #[llvm_variant(LLVMNoDuplicatesComdatSelectionKind)]
23 NoDuplicates,
24 #[llvm_variant(LLVMSameSizeComdatSelectionKind)]
26 SameSize,
27}
28
29#[derive(Debug, PartialEq, Eq, Copy, Clone)]
31pub struct Comdat(pub(crate) LLVMComdatRef);
32
33impl Comdat {
34 pub unsafe fn new(comdat: LLVMComdatRef) -> Self {
36 debug_assert!(!comdat.is_null());
37
38 Comdat(comdat)
39 }
40
41 pub fn as_mut_ptr(&self) -> LLVMComdatRef {
43 self.0
44 }
45
46 pub fn get_selection_kind(self) -> ComdatSelectionKind {
48 let kind_ptr = unsafe { LLVMGetComdatSelectionKind(self.0) };
49
50 ComdatSelectionKind::new(kind_ptr)
51 }
52
53 pub fn set_selection_kind(self, kind: ComdatSelectionKind) {
55 unsafe { LLVMSetComdatSelectionKind(self.0, kind.into()) }
56 }
57}