use llvm_sys::{
core::{LLVMConstReal, LLVMDumpType, LLVMGetTypeKind},
prelude::LLVMTypeRef,
LLVMTypeKind,
};
use std::marker::PhantomData;
use super::Value;
#[derive(Copy, Clone)]
#[repr(transparent)]
pub struct Type<'llvm>(LLVMTypeRef, PhantomData<&'llvm ()>);
impl<'llvm> Type<'llvm> {
pub(super) fn new(type_ref: LLVMTypeRef) -> Self {
assert!(!type_ref.is_null());
Type(type_ref, PhantomData)
}
#[inline]
pub(super) fn type_ref(&self) -> LLVMTypeRef {
self.0
}
pub(super) fn kind(&self) -> LLVMTypeKind {
unsafe { LLVMGetTypeKind(self.type_ref()) }
}
pub fn dump(&self) {
unsafe { LLVMDumpType(self.type_ref()) };
}
pub fn const_f64(self, n: f64) -> Value<'llvm> {
debug_assert_eq!(
self.kind(),
LLVMTypeKind::LLVMDoubleTypeKind,
"Expected a double type when creating const f64 value!"
);
let value_ref = unsafe { LLVMConstReal(self.type_ref(), n) };
Value::new(value_ref)
}
}