Do similar change to allocator
This commit is contained in:
		
							parent
							
								
									56b8506f50
								
							
						
					
					
						commit
						4a7f27205c
					
				| @ -6,8 +6,8 @@ use reid_lib::{ | ||||
| }; | ||||
| 
 | ||||
| use crate::mir::{ | ||||
|     self, CustomTypeKey, FunctionCall, FunctionDefinition, IfExpression, SourceModuleId, | ||||
|     TypeDefinition, TypeKind, WhileStatement, | ||||
|     self, CustomTypeKey, FunctionCall, FunctionDefinition, FunctionDefinitionKind, IfExpression, | ||||
|     SourceModuleId, TypeDefinition, TypeKind, WhileStatement, | ||||
| }; | ||||
| 
 | ||||
| #[derive(Debug)] | ||||
| @ -28,8 +28,12 @@ impl Allocator { | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     pub fn from(func: &FunctionDefinition, scope: &mut AllocatorScope) -> Allocator { | ||||
|         func.allocate(scope) | ||||
|     pub fn from( | ||||
|         func: &FunctionDefinitionKind, | ||||
|         params: &Vec<(String, TypeKind)>, | ||||
|         scope: &mut AllocatorScope, | ||||
|     ) -> Allocator { | ||||
|         func.allocate(scope, params) | ||||
|     } | ||||
| 
 | ||||
|     pub fn allocate(&mut self, name: &String, ty: &TypeKind) -> Option<InstructionValue> { | ||||
| @ -45,12 +49,16 @@ impl Allocator { | ||||
| #[derive(Clone, Debug)] | ||||
| pub struct Allocation(String, TypeKind, InstructionValue); | ||||
| 
 | ||||
| impl mir::FunctionDefinition { | ||||
|     fn allocate<'ctx, 'a>(&self, scope: &mut AllocatorScope<'ctx, 'a>) -> Allocator { | ||||
| impl mir::FunctionDefinitionKind { | ||||
|     fn allocate<'ctx, 'a>( | ||||
|         &self, | ||||
|         scope: &mut AllocatorScope<'ctx, 'a>, | ||||
|         parameters: &Vec<(String, TypeKind)>, | ||||
|     ) -> Allocator { | ||||
|         let mut allocated = Vec::new(); | ||||
|         match &self.kind { | ||||
|         match &self { | ||||
|             mir::FunctionDefinitionKind::Local(block, _) => { | ||||
|                 for param in &self.parameters { | ||||
|                 for param in parameters { | ||||
|                     let allocation = scope | ||||
|                         .block | ||||
|                         .build_named( | ||||
|  | ||||
| @ -355,18 +355,15 @@ impl mir::Module { | ||||
|             let function = functions.get(&mir_function.name).unwrap(); | ||||
|             let mut entry = function.ir.block("entry"); | ||||
| 
 | ||||
|             let allocator = match &mir_function.kind { | ||||
|                 FunctionDefinitionKind::Local(..) => Allocator::from( | ||||
|                     mir_function, | ||||
|                     &mut AllocatorScope { | ||||
|                         block: &mut entry, | ||||
|                         module_id: self.module_id, | ||||
|                         type_values: &type_values, | ||||
|                     }, | ||||
|                 ), | ||||
|                 FunctionDefinitionKind::Extern(_) => Allocator::empty(), | ||||
|                 FunctionDefinitionKind::Intrinsic(_) => Allocator::empty(), | ||||
|             }; | ||||
|             let allocator = Allocator::from( | ||||
|                 &mir_function.kind, | ||||
|                 &mir_function.parameters, | ||||
|                 &mut AllocatorScope { | ||||
|                     block: &mut entry, | ||||
|                     module_id: self.module_id, | ||||
|                     type_values: &type_values, | ||||
|                 }, | ||||
|             ); | ||||
| 
 | ||||
|             let mut scope = Scope { | ||||
|                 context, | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user