@@ -199,17 +199,33 @@ def _allocate_for_binop(builder, var_name, local_sym_tab):
199199 logger .info (f"Pre-allocated { var_name } for binop result" )
200200
201201
202+ def _get_type_name (ir_type ):
203+ """Get a string representation of an IR type."""
204+ if isinstance (ir_type , ir .IntType ):
205+ return f"i{ ir_type .width } "
206+ elif isinstance (ir_type , ir .PointerType ):
207+ return "ptr"
208+ elif isinstance (ir_type , ir .ArrayType ):
209+ return f"[{ ir_type .count } x{ _get_type_name (ir_type .element )} ]"
210+ else :
211+ return str (ir_type ).replace (" " , "" )
212+
213+
202214def allocate_temp_pool (builder , max_temps , local_sym_tab ):
203215 """Allocate the temporary scratch space pool for helper arguments."""
204- if max_temps == 0 :
216+ if not max_temps :
217+ logger .info ("No temp pool allocation needed" )
205218 return
206219
207- logger .info (f"Allocating temp pool of { max_temps } variables" )
208- for i in range (max_temps ):
209- temp_name = f"__helper_temp_{ i } "
210- temp_var = builder .alloca (ir .IntType (64 ), name = temp_name )
211- temp_var .align = 8
212- local_sym_tab [temp_name ] = LocalSymbol (temp_var , ir .IntType (64 ))
220+ for tmp_type , cnt in max_temps .items ():
221+ type_name = _get_type_name (tmp_type )
222+ logger .info (f"Allocating temp pool of { cnt } variables of type { type_name } " )
223+ for i in range (cnt ):
224+ temp_name = f"__helper_temp_{ type_name } _{ i } "
225+ temp_var = builder .alloca (tmp_type , name = temp_name )
226+ temp_var .align = _get_alignment (tmp_type )
227+ local_sym_tab [temp_name ] = LocalSymbol (temp_var , tmp_type )
228+ logger .debug (f"Allocated temp variable: { temp_name } " )
213229
214230
215231def _allocate_for_name (builder , var_name , rval , local_sym_tab ):
0 commit comments