From 29996c4a307f3bebe96d4286e5cd4d67c74532f5 Mon Sep 17 00:00:00 2001 From: sofia Date: Wed, 16 Jul 2025 16:16:18 +0300 Subject: [PATCH] Add builder methods to create custom types --- reid-llvm-lib/src/builder.rs | 10 ++++++++++ reid-llvm-lib/src/lib.rs | 9 +++++++++ 2 files changed, 19 insertions(+) diff --git a/reid-llvm-lib/src/builder.rs b/reid-llvm-lib/src/builder.rs index d03e914..05e120b 100644 --- a/reid-llvm-lib/src/builder.rs +++ b/reid-llvm-lib/src/builder.rs @@ -80,6 +80,16 @@ impl Builder { value } + pub(crate) unsafe fn add_type(&self, mod_val: &ModuleValue, data: TypeData) -> TypeValue { + unsafe { + let mut modules = self.modules.borrow_mut(); + let module = modules.get_unchecked_mut(mod_val.0); + let value = TypeValue(module.value, module.types.len()); + module.types.push(TypeHolder { value, data }); + value + } + } + pub(crate) unsafe fn add_function( &self, mod_val: &ModuleValue, diff --git a/reid-llvm-lib/src/lib.rs b/reid-llvm-lib/src/lib.rs index 7d78550..fbc4754 100644 --- a/reid-llvm-lib/src/lib.rs +++ b/reid-llvm-lib/src/lib.rs @@ -76,6 +76,15 @@ impl<'ctx> Module<'ctx> { } } + pub fn custom_type(&mut self, ty: CustomTypeKind) -> TypeValue { + unsafe { + let (name, kind) = match &ty { + CustomTypeKind::NamedStruct(NamedStruct(name, _)) => (name.clone(), ty), + }; + self.builder.add_type(&self.value, TypeData { name, kind }) + } + } + pub fn value(&self) -> ModuleValue { self.value }