@@ -81,6 +81,19 @@ def handle_assign(func, module, builder, stmt, map_sym_tab, local_sym_tab, struc
8181 local_sym_tab [var_name ])
8282 # local_sym_tab[var_name] = var
8383 print (f"Assigned constant { rval .value } to { var_name } " )
84+ elif isinstance (rval .value , str ):
85+ str_val = rval .value .encode ('utf-8' ) + b'\x00 '
86+ str_const = ir .Constant (ir .ArrayType (
87+ ir .IntType (8 ), len (str_val )), bytearray (str_val ))
88+ global_str = ir .GlobalVariable (
89+ module , str_const .type , name = f"{ var_name } _str" )
90+ global_str .linkage = 'internal'
91+ global_str .global_constant = True
92+ global_str .initializer = str_const
93+ str_ptr = builder .bitcast (
94+ global_str , ir .PointerType (ir .IntType (8 )))
95+ builder .store (str_ptr , local_sym_tab [var_name ])
96+ print (f"Assigned string constant '{ rval .value } ' to { var_name } " )
8497 else :
8598 print ("Unsupported constant type" )
8699 elif isinstance (rval , ast .Call ):
@@ -389,7 +402,7 @@ def allocate_mem(module, builder, body, func, ret_type, map_sym_tab, local_sym_t
389402 else :
390403 print ("Unsupported assignment value type" )
391404 continue
392- local_sym_tab [var_name ] = var
405+ local_sym_tab [var_name ] = ( var , ir_type )
393406 return local_sym_tab
394407
395408
0 commit comments