@@ -58,6 +58,8 @@ def get_next_temp(self, local_sym_tab):
5858 f"Current counter: { self ._counter } "
5959 )
6060
61+ return local_sym_tab [temp_name ].var , temp_name
62+
6163
6264_temp_pool_manager = ScratchPoolManager () # Singleton instance
6365
@@ -67,25 +69,21 @@ def reset_scratch_pool():
6769 _temp_pool_manager .reset ()
6870
6971
70- def get_next_scratch_temp (local_sym_tab ):
71- """Get the next temporary variable name from the scratch pool"""
72- return _temp_pool_manager .get_next_temp (local_sym_tab )
73-
74-
7572def get_var_ptr_from_name (var_name , local_sym_tab ):
7673 """Get a pointer to a variable from the symbol table."""
7774 if local_sym_tab and var_name in local_sym_tab :
7875 return local_sym_tab [var_name ].var
7976 raise ValueError (f"Variable '{ var_name } ' not found in local symbol table" )
8077
8178
82- def create_int_constant_ptr (value , builder , int_width = 64 ):
79+ def create_int_constant_ptr (value , builder , local_sym_tab , int_width = 64 ):
8380 """Create a pointer to an integer constant."""
81+
8482 # Default to 64-bit integer
85- int_type = ir . IntType ( int_width )
86- ptr = builder . alloca ( int_type )
87- ptr . align = int_type . width // 8
88- builder .store (ir . Constant ( int_type , value ) , ptr )
83+ ptr , temp_name = _temp_pool_manager . get_next_temp ( local_sym_tab )
84+ logger . debug ( f"Using temp variable ' { temp_name } ' for int constant { value } " )
85+ const_val = ir . Constant ( ir . IntType ( int_width ), value )
86+ builder .store (const_val , ptr )
8987 return ptr
9088
9189
@@ -95,7 +93,7 @@ def get_or_create_ptr_from_arg(arg, builder, local_sym_tab):
9593 if isinstance (arg , ast .Name ):
9694 ptr = get_var_ptr_from_name (arg .id , local_sym_tab )
9795 elif isinstance (arg , ast .Constant ) and isinstance (arg .value , int ):
98- ptr = create_int_constant_ptr (arg .value , builder )
96+ ptr = create_int_constant_ptr (arg .value , builder , local_sym_tab )
9997 else :
10098 raise NotImplementedError (
10199 "Only simple variable names are supported as args in map helpers."
0 commit comments