1//! Lifetime-branded references to things manipulated by the LLVM bindings.
23use std::marker::PhantomData;
4use std::ptr;
56/// Corresponds to `LLVMContextRef`.
7#[derive(#[automatically_derived]#[doc(hidden)]unsafe impl<'ll>
::core::clone::TrivialClone for Context<'ll> {
}
#[automatically_derived]impl<'ll> ::core::clone::Clone for Context<'ll> {
#[inline]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<ptr::NonNull<ContextRaw>>;
let _:
::core::clone::AssertParamIsClone<PhantomData<fn(&'ll ())
-> &'ll ()>>;
*self
}
}Clone, #[automatically_derived]impl<'ll> ::core::marker::Copy for Context<'ll> { }Copy)]
8#[repr(transparent)]
9pub(crate) struct Context<'ll> {
10 llcx_raw: ptr::NonNull<ContextRaw>,
11 _invariant_ll: PhantomData<fn(&'ll ()) -> &'ll ()>,
12}
1314/// Corresponds to `LLVMModuleRef`.
15#[derive(#[automatically_derived]#[doc(hidden)]unsafe impl<'ll>
::core::clone::TrivialClone for Module<'ll> {
}
#[automatically_derived]impl<'ll> ::core::clone::Clone for Module<'ll> {
#[inline]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<ptr::NonNull<ModuleRaw>>;
let _:
::core::clone::AssertParamIsClone<PhantomData<fn(&'ll ())
-> &'ll ()>>;
*self
}
}Clone, #[automatically_derived]impl<'ll> ::core::marker::Copy for Module<'ll> { }Copy)]
16#[repr(transparent)]
17pub(crate) struct Module<'ll> {
18 llmod_raw: ptr::NonNull<ModuleRaw>,
19 _invariant_ll: PhantomData<fn(&'ll ()) -> &'ll ()>,
20}
2122impl<'ll> Module<'ll> {
23pub(crate) fn llmod_raw(&self) -> ptr::NonNull<ModuleRaw> {
24self.llmod_raw
25 }
26}
2728unsafe extern "C" {
29/// Pointee of the raw pointer that is wrapped by a lifetime-branded [`Context`].
30pub(crate) type ContextRaw;
31/// Pointee of the raw pointer that is wrapped by a lifetime-branded [`Module`].
32pub(crate) type ModuleRaw;
33}
3435/// Converts an unbranded pointer-to-context to a lifetime-branded [`Context`].
36///
37/// # Safety
38/// - The pointer must be a valid LLVM context.
39/// - If the context is passed to safe code, its caller-requested lifetime must be distinct
40/// from that of any other context, and must not outlive the underlying context.
41pub(crate) unsafe fn wrap_llcx<'ll>(llcx_raw: ptr::NonNull<ContextRaw>) -> Context<'ll> {
42Context { llcx_raw, _invariant_ll: PhantomData }
43}
4445/// Converts an unbranded pointer-to-module to a lifetime-branded [`Module`].
46///
47/// # Safety
48/// - The pointer must be a valid LLVM module within the specified context.
49/// - The module must not be disposed during the lifetime of its context.
50pub(crate) unsafe fn wrap_llmod<'ll>(
51 _llcx: Context<'ll>, // The context constrains `'ll` but isn't actually used.
52llmod_raw: ptr::NonNull<ModuleRaw>,
53) -> Module<'ll> {
54Module { llmod_raw, _invariant_ll: PhantomData }
55}