Add builder methods to create custom types
This commit is contained in:
parent
31185d921e
commit
29996c4a30
@ -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,
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user