llir/types/
int.rs

1use llvm_sys::core::LLVMGetIntTypeWidth;
2use llvm_sys::prelude::LLVMTypeRef;
3use std::marker::PhantomData;
4
5use crate::types::*;
6use crate::{FromLLVMType, TypeRef};
7
8/// [Integer type](https://llvm.org/docs/LangRef.html#integer-type)
9#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
10pub struct IntType<'ctx>(LLVMTypeRef, PhantomData<&'ctx ()>);
11
12impl_send_sync!(IntType);
13
14impl<'ctx> IntType<'ctx> {
15  /// Get the bit-width
16  pub fn width(&self) -> u32 {
17    unsafe { LLVMGetIntTypeWidth(self.0) }
18  }
19}
20
21impl<'ctx> AsType<'ctx> for IntType<'ctx> {
22  fn as_type(&self) -> Type<'ctx> {
23    Type::Int(self.clone())
24  }
25}
26
27impl_positional_type_ref!(IntType, 0);
28
29impl_positional_from_llvm_type!(IntType);