use std::ptr::NonNull;
use llvm_sys::LLVMComdat;
use llvm_sys::comdat::{LLVMComdatSelectionKind, LLVMGetComdatSelectionKind, LLVMSetComdatSelectionKind};
use llvm_sys::prelude::LLVMComdatRef;
use crate::support::assert_niche;
#[llvm_enum(LLVMComdatSelectionKind)]
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub enum ComdatSelectionKind {
#[llvm_variant(LLVMAnyComdatSelectionKind)]
Any,
#[llvm_variant(LLVMExactMatchComdatSelectionKind)]
ExactMatch,
#[llvm_variant(LLVMLargestComdatSelectionKind)]
Largest,
#[llvm_variant(LLVMNoDuplicatesComdatSelectionKind)]
NoDuplicates,
#[llvm_variant(LLVMSameSizeComdatSelectionKind)]
SameSize,
}
#[repr(transparent)]
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
pub struct Comdat(pub(crate) NonNull<LLVMComdat>);
const _: () = assert_niche::<Comdat>();
impl Comdat {
pub unsafe fn new(comdat: LLVMComdatRef) -> Self {
debug_assert!(!comdat.is_null());
Comdat(unsafe { NonNull::new_unchecked(comdat) })
}
pub fn as_mut_ptr(&self) -> LLVMComdatRef {
self.0.as_ptr()
}
pub fn get_selection_kind(self) -> ComdatSelectionKind {
let kind_ptr = unsafe { LLVMGetComdatSelectionKind(self.as_mut_ptr()) };
ComdatSelectionKind::new(kind_ptr)
}
pub fn set_selection_kind(self, kind: ComdatSelectionKind) {
unsafe { LLVMSetComdatSelectionKind(self.as_mut_ptr(), kind.into()) }
}
}