From 92d6f0a5d33e3f160780008e27bded93ca0aa900 Mon Sep 17 00:00:00 2001 From: David Mak Date: Fri, 3 Nov 2023 11:50:18 +0800 Subject: [PATCH] core: Implement bitwise not for unsigned ints and fix implementation --- nac3core/src/codegen/expr.rs | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/nac3core/src/codegen/expr.rs b/nac3core/src/codegen/expr.rs index df7bb06a..1518b2dc 100644 --- a/nac3core/src/codegen/expr.rs +++ b/nac3core/src/codegen/expr.rs @@ -1352,25 +1352,16 @@ pub fn gen_expr<'ctx, 'a, G: CodeGenerator>( } _ => val.into(), } - } else if [ctx.primitives.int32, ctx.primitives.int64].contains(&ty) { + } else if [ctx.primitives.int32, ctx.primitives.int64, ctx.primitives.uint32, ctx.primitives.uint64].contains(&ty) { let val = val.into_int_value(); match op { ast::Unaryop::USub => ctx.builder.build_int_neg(val, "neg").into(), ast::Unaryop::Invert => ctx.builder.build_not(val, "not").into(), - ast::Unaryop::Not => ctx - .builder - .build_int_compare( - IntPredicate::EQ, - val, - val.get_type().const_zero(), - "not", - ) - .into(), + ast::Unaryop::Not => ctx.builder.build_xor(val, val.get_type().const_all_ones(), "not").into(), _ => val.into(), } } else if ty == ctx.primitives.float { - let val = - if let BasicValueEnum::FloatValue(val) = val { val } else { unreachable!() }; + let val = val.into_float_value(); match op { ast::Unaryop::USub => ctx.builder.build_float_neg(val, "neg").into(), ast::Unaryop::Not => ctx