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