@@ -298,15 +298,6 @@ def allocate_temp_pool(builder, max_temps, local_sym_tab):
298298 logger .debug (f"Allocated temp variable: { temp_name } " )
299299
300300
301- def _get_alignment (tmp_type ):
302- """Return alignment for a given type."""
303- if isinstance (tmp_type , ir .PointerType ):
304- return 8
305- elif isinstance (tmp_type , ir .IntType ):
306- return tmp_type .width // 8
307- return 8
308-
309-
310301def _allocate_for_name (builder , var_name , rval , local_sym_tab ):
311302 """Allocate memory for variable-to-variable assignment (b = a)."""
312303 source_var = rval .id
@@ -329,16 +320,6 @@ def _allocate_for_name(builder, var_name, rval, local_sym_tab):
329320 )
330321
331322
332- def _allocate_with_type (builder , var_name , ir_type ):
333- """Allocate memory for a variable with a specific type."""
334- var = builder .alloca (ir_type , name = var_name )
335- if isinstance (ir_type , ir .IntType ):
336- var .align = ir_type .width // 8
337- elif isinstance (ir_type , ir .PointerType ):
338- var .align = 8
339- return var
340-
341-
342323def _allocate_for_attribute (
343324 builder , var_name , rval , local_sym_tab , compilation_context
344325):
@@ -477,3 +458,20 @@ def _allocate_for_attribute(
477458 logger .info (
478459 f"Pre-allocated { var_name } from { struct_var } .{ field_name } with type { alloc_type } "
479460 )
461+
462+
463+ def _allocate_with_type (builder , var_name , ir_type ):
464+ """Allocate variable with appropriate alignment for type."""
465+ var = builder .alloca (ir_type , name = var_name )
466+ var .align = _get_alignment (ir_type )
467+ return var
468+
469+
470+ def _get_alignment (ir_type ):
471+ """Get appropriate alignment for IR type."""
472+ if isinstance (ir_type , ir .IntType ):
473+ return ir_type .width // 8
474+ elif isinstance (ir_type , ir .ArrayType ) and isinstance (ir_type .element , ir .IntType ):
475+ return ir_type .element .width // 8
476+ else :
477+ return 8 # Default: pointer size
0 commit comments