Remove name from alloca
This commit is contained in:
		
							parent
							
								
									848f4118bf
								
							
						
					
					
						commit
						71a01dad69
					
				| @ -390,7 +390,7 @@ impl Builder { | |||||||
|                     } |                     } | ||||||
|                     Ok(()) |                     Ok(()) | ||||||
|                 } |                 } | ||||||
|                 Instr::Alloca(_, _) => Ok(()), |                 Instr::Alloca(_) => Ok(()), | ||||||
|                 Instr::Load(ptr, load_ty) => { |                 Instr::Load(ptr, load_ty) => { | ||||||
|                     let ptr_ty = ptr.get_type(&self)?; |                     let ptr_ty = ptr.get_type(&self)?; | ||||||
|                     if let Type::Ptr(ptr_ty_inner) = ptr_ty { |                     if let Type::Ptr(ptr_ty_inner) = ptr_ty { | ||||||
|  | |||||||
| @ -444,7 +444,7 @@ impl DebugMetadataHolder { | |||||||
|                     *debug.types.get(&var.ty).unwrap(), |                     *debug.types.get(&var.ty).unwrap(), | ||||||
|                     var.always_preserve as i32, |                     var.always_preserve as i32, | ||||||
|                     var.flags.as_llvm(), |                     var.flags.as_llvm(), | ||||||
|                     var.alignment, |                     0, | ||||||
|                 ), |                 ), | ||||||
|                 DebugMetadata::VarAssignment => todo!(), |                 DebugMetadata::VarAssignment => todo!(), | ||||||
|             } |             } | ||||||
| @ -824,10 +824,10 @@ impl InstructionHolder { | |||||||
|                     ); |                     ); | ||||||
|                     phi |                     phi | ||||||
|                 } |                 } | ||||||
|                 Alloca(name, ty) => LLVMBuildAlloca( |                 Alloca(ty) => LLVMBuildAlloca( | ||||||
|                     module.builder_ref, |                     module.builder_ref, | ||||||
|                     ty.as_llvm(module.context_ref, &module.types), |                     ty.as_llvm(module.context_ref, &module.types), | ||||||
|                     into_cstring(name).as_ptr(), |                     c"alloca".as_ptr(), | ||||||
|                 ), |                 ), | ||||||
|                 Load(ptr, ty) => LLVMBuildLoad2( |                 Load(ptr, ty) => LLVMBuildLoad2( | ||||||
|                     module.builder_ref, |                     module.builder_ref, | ||||||
|  | |||||||
| @ -132,7 +132,7 @@ impl Debug for Instr { | |||||||
|             Instr::Phi(val) => fmt_call(f, &"Phi", &val), |             Instr::Phi(val) => fmt_call(f, &"Phi", &val), | ||||||
|             Instr::ICmp(cmp, lhs, rhs) => fmt_binop(f, lhs, cmp, rhs), |             Instr::ICmp(cmp, lhs, rhs) => fmt_binop(f, lhs, cmp, rhs), | ||||||
|             Instr::FunctionCall(fun, params) => fmt_call(f, fun, params), |             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::Load(val, ty) => write!(f, "load<{:?}>({:?})", ty, val), | ||||||
|             Instr::Store(ptr, val) => write!(f, "store({:?} = {:?})", ptr, val), |             Instr::Store(ptr, val) => write!(f, "store({:?} = {:?})", ptr, val), | ||||||
|             Instr::ArrayAlloca(ty, instruction_value) => { |             Instr::ArrayAlloca(ty, instruction_value) => { | ||||||
|  | |||||||
| @ -235,7 +235,6 @@ pub struct DebugLocalVariable { | |||||||
|     pub location: DebugLocation, |     pub location: DebugLocation, | ||||||
|     pub ty: DebugTypeValue, |     pub ty: DebugTypeValue, | ||||||
|     pub always_preserve: bool, |     pub always_preserve: bool, | ||||||
|     pub alignment: u32, |  | ||||||
|     pub flags: DwarfFlags, |     pub flags: DwarfFlags, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -312,7 +312,7 @@ pub enum Instr { | |||||||
|     And(InstructionValue, InstructionValue), |     And(InstructionValue, InstructionValue), | ||||||
|     Phi(Vec<InstructionValue>), |     Phi(Vec<InstructionValue>), | ||||||
| 
 | 
 | ||||||
|     Alloca(String, Type), |     Alloca(Type), | ||||||
|     Load(InstructionValue, Type), |     Load(InstructionValue, Type), | ||||||
|     Store(InstructionValue, InstructionValue), |     Store(InstructionValue, InstructionValue), | ||||||
|     ArrayAlloca(Type, u32), |     ArrayAlloca(Type, u32), | ||||||
| @ -402,7 +402,7 @@ impl InstructionValue { | |||||||
|                 ICmp(_, _, _) => Ok(Type::Bool), |                 ICmp(_, _, _) => Ok(Type::Bool), | ||||||
|                 FunctionCall(function_value, _) => Ok(builder.function_data(function_value).ret), |                 FunctionCall(function_value, _) => Ok(builder.function_data(function_value).ret), | ||||||
|                 Phi(values) => values.first().ok_or(()).and_then(|v| v.get_type(&builder)), |                 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()), |                 Load(_, ty) => Ok(ty.clone()), | ||||||
|                 Store(_, value) => value.get_type(builder), |                 Store(_, value) => value.get_type(builder), | ||||||
|                 ArrayAlloca(ty, _) => Ok(Type::Ptr(Box::new(ty.clone()))), |                 ArrayAlloca(ty, _) => Ok(Type::Ptr(Box::new(ty.clone()))), | ||||||
|  | |||||||
| @ -345,10 +345,7 @@ impl mir::Module { | |||||||
|                 // Codegen actual parameters
 |                 // Codegen actual parameters
 | ||||||
|                 let param = entry.build(Instr::Param(i)).unwrap(); |                 let param = entry.build(Instr::Param(i)).unwrap(); | ||||||
|                 let alloca = entry |                 let alloca = entry | ||||||
|                     .build(Instr::Alloca( |                     .build(Instr::Alloca(p_ty.get_type(&type_values, &types))) | ||||||
|                         p_name.clone(), |  | ||||||
|                         p_ty.get_type(&type_values, &types), |  | ||||||
|                     )) |  | ||||||
|                     .unwrap(); |                     .unwrap(); | ||||||
|                 entry.build(Instr::Store(alloca, param)).unwrap(); |                 entry.build(Instr::Store(alloca, param)).unwrap(); | ||||||
|                 stack_values.insert( |                 stack_values.insert( | ||||||
| @ -475,10 +472,7 @@ impl mir::Statement { | |||||||
| 
 | 
 | ||||||
|                 let alloca = scope |                 let alloca = scope | ||||||
|                     .block |                     .block | ||||||
|                     .build(Instr::Alloca( |                     .build(Instr::Alloca(ty.get_type(scope.type_values, scope.types))) | ||||||
|                         name.clone(), |  | ||||||
|                         ty.get_type(scope.type_values, scope.types), |  | ||||||
|                     )) |  | ||||||
|                     .unwrap() |                     .unwrap() | ||||||
|                     .maybe_location(&mut scope.block, location); |                     .maybe_location(&mut scope.block, location); | ||||||
| 
 | 
 | ||||||
| @ -504,9 +498,8 @@ impl mir::Statement { | |||||||
|                         DebugMetadata::LocalVar(DebugLocalVariable { |                         DebugMetadata::LocalVar(DebugLocalVariable { | ||||||
|                             name: name.clone(), |                             name: name.clone(), | ||||||
|                             location, |                             location, | ||||||
|                             ty: ty.clone().get_debug_type(debug, scope), |                             ty: TypeKind::Ptr(Box::new(ty.clone())).get_debug_type(debug, scope), | ||||||
|                             always_preserve: true, |                             always_preserve: true, | ||||||
|                             alignment: 32, |  | ||||||
|                             flags: DwarfFlags, |                             flags: DwarfFlags, | ||||||
|                         }), |                         }), | ||||||
|                     ); |                     ); | ||||||
| @ -737,7 +730,7 @@ impl mir::Expression { | |||||||
| 
 | 
 | ||||||
|                 let array = scope |                 let array = scope | ||||||
|                     .block |                     .block | ||||||
|                     .build(Instr::Alloca("array".to_owned(), array_ty.clone())) |                     .build(Instr::Alloca(array_ty.clone())) | ||||||
|                     .unwrap() |                     .unwrap() | ||||||
|                     .maybe_location(&mut scope.block, location); |                     .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_ty = Type::CustomType(*scope.type_values.get(name)?); | ||||||
|                 let struct_ptr = scope |                 let struct_ptr = scope | ||||||
|                     .block |                     .block | ||||||
|                     .build(Instr::Alloca(name.clone(), struct_ty.clone())) |                     .build(Instr::Alloca(struct_ty.clone())) | ||||||
|                     .unwrap() |                     .unwrap() | ||||||
|                     .maybe_location(&mut scope.block, location); |                     .maybe_location(&mut scope.block, location); | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -5,17 +5,21 @@ struct Test { | |||||||
|   second: [u32; 4] |   second: [u32; 4] | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| fn test() -> [Test; 1] { | fn test() -> Test { | ||||||
|   let value = [Test { |   let value = Test { | ||||||
|     field: 5, |     field: 5, | ||||||
|     second: [6, 3, 4, 8], |     second: [6, 3, 4, 8], | ||||||
|   }]; |   }; | ||||||
|   return value; |   return value; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| fn main() -> u32 { | fn main() -> u32 { | ||||||
|   let mut value = test(); |   let mut value = test(); | ||||||
| 
 | 
 | ||||||
|  |   let mut a = value.second; | ||||||
| 
 | 
 | ||||||
|   return value[0].second[2]; |   a[2] = 15; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |   return value.second[2]; | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user