@@ -240,12 +240,25 @@ def handle_assign(
240240 logger .info ("Unsupported assignment value type" )
241241
242242
243+ def _convert_to_bool (builder , val ):
244+ if val .type == ir .IntType (1 ):
245+ return val
246+ if isinstance (val .type , ir .PointerType ):
247+ zero = ir .Constant (val .type , None )
248+ else :
249+ zero = ir .Constant (val .type , 0 )
250+ return builder .icmp_signed ("!=" , val , zero )
251+
252+
243253def handle_cond (func , module , builder , cond , local_sym_tab , map_sym_tab ):
254+ if True :
255+ val = eval_expr (func , module , builder , cond , local_sym_tab , map_sym_tab )[0 ]
256+ return _convert_to_bool (builder , val )
244257 if isinstance (cond , ast .Constant ):
245258 if isinstance (cond .value , bool ) or isinstance (cond .value , int ):
246- return ir .Constant (ir .IntType (1 ), int (bool ( cond .value ) ))
259+ return ir .Constant (ir .IntType (1 ), int (cond .value ))
247260 else :
248- logger . info ("Unsupported constant type in condition" )
261+ raise ValueError ("Unsupported constant type in condition" )
249262 return None
250263 elif isinstance (cond , ast .Name ):
251264 if cond .id in local_sym_tab :
0 commit comments