Skip to main content

llir/types/
pointer.rs

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