e_new = expr_simp(e_input) print "original: ", str(e_input), "new: ", str(e_new) rez = e_new == e_check if not rez: raise ValueError( 'bug in expr_simp simp(%s) is %s and should be %s' % (e_input, e_new, e_check) ) # Test conds to_test = [ (((a - b) ^ ((a ^ b) & ((a - b) ^ a))).msb(), ExprOp_inf_signed(a, b)), ((((a - b) ^ ((a ^ b) & ((a - b) ^ a))) ^ a ^ b).msb(), ExprOp_inf_unsigned(a, b)), (ExprOp_inf_unsigned(ExprInt(-1, 32), ExprInt(3, 32)), ExprInt(0, 1)), (ExprOp_inf_signed(ExprInt(-1, 32), ExprInt(3, 32)), ExprInt(1, 1)), (ExprOp_inf_unsigned(a, b) ^ (a ^ b).msb(), ExprOp_inf_signed(a, b)), (ExprOp_inf_signed(a, b) ^ (a ^ b).msb(), ExprOp_inf_unsigned(a, b)), (ExprOp_equal(ExprInt(12, 32), ExprInt(10, 32)), ExprInt(0, 1)), (ExprOp_equal(ExprInt(12, 32), ExprInt(12, 32)), ExprInt(1, 1)), (ExprOp_equal(ExprInt(12, 32), ExprInt(-12, 32)), ExprInt(0, 1)), (ExprCond(a - b, ExprInt(0, 1), ExprInt(1, 1)), ExprOp_equal(a, b)), (ExprCond(a + b, ExprInt(0, 1), ExprInt(1, 1)), ExprOp_equal(a, -b)), (ExprOp_inf_signed(ExprInt(-2, 32), ExprInt(3, 32)), ExprInt(1, 1)), (ExprOp_inf_signed(ExprInt(3, 32), ExprInt(-3, 32)), ExprInt(0, 1)), (ExprOp_inf_signed(ExprInt(2, 32), ExprInt(3, 32)), ExprInt(1, 1)), (ExprOp_inf_signed(ExprInt(-3, 32), ExprInt(-2, 32)), ExprInt(1, 1)), (ExprOp_inf_signed(ExprInt(0, 32), ExprInt(2, 32)), ExprInt(1, 1)), (ExprOp_inf_signed(ExprInt(-3, 32), ExprInt(0, 32)), ExprInt(1, 1)),
# print "#" * 80 # print str(e), str(e_check) e_new = expr_simp(e) print "original: ", str(e), "new: ", str(e_new) rez = e_new == e_check if not rez: raise ValueError('bug in expr_simp simp(%s) is %s and should be %s' % (e, e_new, e_check)) # Test conds to_test = [ (((a - b) ^ ((a ^ b) & ((a - b) ^ a))).msb(), ExprOp_inf_signed(a, b)), ((((a - b) ^ ((a ^ b) & ((a - b) ^ a))) ^ a ^ b).msb(), ExprOp_inf_unsigned(a, b)), (ExprOp_inf_unsigned(ExprInt32(-1), ExprInt32(3)), ExprInt1(0)), (ExprOp_inf_signed(ExprInt32(-1), ExprInt32(3)), ExprInt1(1)), (ExprOp_inf_unsigned(a, b) ^ (a ^ b).msb(), ExprOp_inf_signed(a, b)), (ExprOp_inf_signed(a, b) ^ (a ^ b).msb(), ExprOp_inf_unsigned(a, b)), (ExprOp_equal(ExprInt32(12), ExprInt32(10)), ExprInt1(0)), (ExprOp_equal(ExprInt32(12), ExprInt32(12)), ExprInt1(1)), (ExprOp_equal(ExprInt32(12), ExprInt32(-12)), ExprInt1(0)), (ExprCond(a - b, ExprInt1(0), ExprInt1(1)), ExprOp_equal(a, b)), (ExprCond(a + b, ExprInt1(0), ExprInt1(1)), ExprOp_equal(a, -b)), ] expr_simp_cond = ExpressionSimplifier() expr_simp.enable_passes(ExpressionSimplifier.PASS_COND) for e, e_check in to_test[:]: