Last active
September 11, 2023 16:59
-
-
Save shqld/7c29d3f83402a107435e9fd5cfe0376c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Context { | |
_inner: *mut std::ffi::c_void, | |
} | |
impl Drop for Context { | |
fn drop(&mut self) { | |
println!("drop: Context") | |
} | |
} | |
impl Context { | |
fn new() -> Self { | |
Context { | |
_inner: std::ptr::null_mut(), | |
} | |
} | |
} | |
struct Module<'ctx> { | |
_inner: *mut std::ffi::c_void, | |
_context: &'ctx Context, | |
} | |
impl Drop for Module<'_> { | |
fn drop(&mut self) { | |
println!("drop: Module") | |
} | |
} | |
impl<'ctx> Module<'ctx> { | |
fn new(context: &'ctx Context) -> Self { | |
Module { | |
_inner: std::ptr::null_mut(), | |
_context: context, | |
} | |
} | |
fn add_global(&mut self, _ty: Type<'ctx>) { | |
unimplemented!() | |
// unsafe { LLVMAddGlobal(self._inner, ty._inner, to_cstring(name).as_ptr()) } | |
} | |
} | |
struct Type<'ctx> { | |
_inner: *mut std::ffi::c_void, | |
_context: &'ctx Context, | |
} | |
impl<'ctx> Type<'ctx> { | |
fn new(context: &'ctx Context) -> Self { | |
Type { | |
_inner: std::ptr::null_mut(), | |
_context: context, | |
} | |
} | |
} | |
fn main() { | |
let context = Context::new(); | |
let mut module = Module::new(&context); | |
let context2 = Context::new(); | |
module.add_global(Type::new(&context2)); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use llvm_sys::{LLVMContext, LLVMModule, LLVMType}; | |
use std::{cell::UnsafeCell, marker::PhantomData}; | |
struct Context { | |
_inner: *mut LLVMContext, | |
} | |
impl Drop for Context { | |
fn drop(&mut self) { | |
println!("drop: Context") | |
} | |
} | |
impl Context { | |
fn new() -> Self { | |
Context { | |
_inner: std::ptr::null_mut(), | |
} | |
} | |
} | |
struct Module<'ctx> { | |
_inner: *mut LLVMModule, | |
_context: PhantomData<UnsafeCell<&'ctx Context>>, | |
} | |
impl Drop for Module<'_> { | |
fn drop(&mut self) { | |
println!("drop: Module") | |
} | |
} | |
impl<'ctx> Module<'ctx> { | |
fn new(context: &'ctx Context) -> Self { | |
Module { | |
_inner: std::ptr::null_mut(), | |
_context: PhantomData, | |
} | |
} | |
fn add_global(&self, _ty: Type<'ctx>) { | |
unimplemented!() | |
// unsafe { LLVMAddGlobal(self._inner, ty._inner, to_cstring(name).as_ptr()) } | |
} | |
} | |
struct Type<'ctx> { | |
_inner: *mut LLVMType, | |
_context: &'ctx Context, | |
} | |
impl<'ctx> Type<'ctx> { | |
fn new(context: &'ctx Context) -> Self { | |
Type { | |
_inner: std::ptr::null_mut(), | |
_context: context, | |
} | |
} | |
} | |
fn main() { | |
let context = Context::new(); | |
let module = Module::new(&context); | |
let context2 = Context::new(); | |
module.add_global(Type::new(&context2)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment