Remove name from alloca

This commit is contained in:
Sofia 2025-07-20 20:24:26 +03:00
parent 848f4118bf
commit 71a01dad69
7 changed files with 20 additions and 24 deletions

View File

@ -390,7 +390,7 @@ impl Builder {
}
Ok(())
}
Instr::Alloca(_, _) => Ok(()),
Instr::Alloca(_) => Ok(()),
Instr::Load(ptr, load_ty) => {
let ptr_ty = ptr.get_type(&self)?;
if let Type::Ptr(ptr_ty_inner) = ptr_ty {

View File

@ -444,7 +444,7 @@ impl DebugMetadataHolder {
*debug.types.get(&var.ty).unwrap(),
var.always_preserve as i32,
var.flags.as_llvm(),
var.alignment,
0,
),
DebugMetadata::VarAssignment => todo!(),
}
@ -824,10 +824,10 @@ impl InstructionHolder {
);
phi
}
Alloca(name, ty) => LLVMBuildAlloca(
Alloca(ty) => LLVMBuildAlloca(
module.builder_ref,
ty.as_llvm(module.context_ref, &module.types),
into_cstring(name).as_ptr(),
c"alloca".as_ptr(),
),
Load(ptr, ty) => LLVMBuildLoad2(
module.builder_ref,

View File

@ -132,7 +132,7 @@ impl Debug for Instr {
Instr::Phi(val) => fmt_call(f, &"Phi", &val),
Instr::ICmp(cmp, lhs, rhs) => fmt_binop(f, lhs, cmp, rhs),
Instr::FunctionCall(fun, params) => fmt_call(f, fun, params),
Instr::Alloca(name, ty) => write!(f, "alloca<{:?}>({})", ty, name),
Instr::Alloca(ty) => write!(f, "alloca<{:?}>", ty),
Instr::Load(val, ty) => write!(f, "load<{:?}>({:?})", ty, val),
Instr::Store(ptr, val) => write!(f, "store({:?} = {:?})", ptr, val),
Instr::ArrayAlloca(ty, instruction_value) => {

View File

@ -235,7 +235,6 @@ pub struct DebugLocalVariable {
pub location: DebugLocation,
pub ty: DebugTypeValue,
pub always_preserve: bool,
pub alignment: u32,
pub flags: DwarfFlags,
}

View File

@ -312,7 +312,7 @@ pub enum Instr {
And(InstructionValue, InstructionValue),
Phi(Vec<InstructionValue>),
Alloca(String, Type),
Alloca(Type),
Load(InstructionValue, Type),
Store(InstructionValue, InstructionValue),
ArrayAlloca(Type, u32),
@ -402,7 +402,7 @@ impl InstructionValue {
ICmp(_, _, _) => Ok(Type::Bool),
FunctionCall(function_value, _) => Ok(builder.function_data(function_value).ret),
Phi(values) => values.first().ok_or(()).and_then(|v| v.get_type(&builder)),
Alloca(_, ty) => Ok(Type::Ptr(Box::new(ty.clone()))),
Alloca(ty) => Ok(Type::Ptr(Box::new(ty.clone()))),
Load(_, ty) => Ok(ty.clone()),
Store(_, value) => value.get_type(builder),
ArrayAlloca(ty, _) => Ok(Type::Ptr(Box::new(ty.clone()))),

View File

@ -345,10 +345,7 @@ impl mir::Module {
// Codegen actual parameters
let param = entry.build(Instr::Param(i)).unwrap();
let alloca = entry
.build(Instr::Alloca(
p_name.clone(),
p_ty.get_type(&type_values, &types),
))
.build(Instr::Alloca(p_ty.get_type(&type_values, &types)))
.unwrap();
entry.build(Instr::Store(alloca, param)).unwrap();
stack_values.insert(
@ -475,10 +472,7 @@ impl mir::Statement {
let alloca = scope
.block
.build(Instr::Alloca(
name.clone(),
ty.get_type(scope.type_values, scope.types),
))
.build(Instr::Alloca(ty.get_type(scope.type_values, scope.types)))
.unwrap()
.maybe_location(&mut scope.block, location);
@ -504,9 +498,8 @@ impl mir::Statement {
DebugMetadata::LocalVar(DebugLocalVariable {
name: name.clone(),
location,
ty: ty.clone().get_debug_type(debug, scope),
ty: TypeKind::Ptr(Box::new(ty.clone())).get_debug_type(debug, scope),
always_preserve: true,
alignment: 32,
flags: DwarfFlags,
}),
);
@ -737,7 +730,7 @@ impl mir::Expression {
let array = scope
.block
.build(Instr::Alloca("array".to_owned(), array_ty.clone()))
.build(Instr::Alloca(array_ty.clone()))
.unwrap()
.maybe_location(&mut scope.block, location);
@ -817,7 +810,7 @@ impl mir::Expression {
let struct_ty = Type::CustomType(*scope.type_values.get(name)?);
let struct_ptr = scope
.block
.build(Instr::Alloca(name.clone(), struct_ty.clone()))
.build(Instr::Alloca(struct_ty.clone()))
.unwrap()
.maybe_location(&mut scope.block, location);

View File

@ -5,17 +5,21 @@ struct Test {
second: [u32; 4]
}
fn test() -> [Test; 1] {
let value = [Test {
fn test() -> Test {
let value = Test {
field: 5,
second: [6, 3, 4, 8],
}];
};
return value;
}
fn main() -> u32 {
let mut value = test();
let mut a = value.second;
return value[0].second[2];
a[2] = 15;
return value.second[2];
}