コード例 #1
0
        public void BVXORAssociativityPropagateConstantUp()
        {
            var builderPair = GetSimpleAndConstantFoldingBuilder();
            var sb          = builderPair.Item1;
            var cfb         = builderPair.Item2;

            Expr foldedResult   = sb.ConstantBV(5, 4);
            Expr unfoldedResult = foldedResult;

            for (int index = 0; index < 3; ++index)
            {
                var x = GetVarAndIdExpr("x" + index.ToString(), BasicType.GetBvType(4)).Item2;
                foldedResult   = cfb.BVXOR(x, foldedResult);
                unfoldedResult = sb.BVXOR(x, unfoldedResult);
                CheckIsBvType(foldedResult, 4);
                CheckIsBvType(unfoldedResult, 4);
            }

            Assert.AreEqual("BVXOR4(x2, BVXOR4(x1, BVXOR4(x0, 5bv4)))", unfoldedResult.ToString());
            Assert.AreEqual("BVXOR4(5bv4, BVXOR4(x2, BVXOR4(x1, x0)))", foldedResult.ToString());
            Assert.IsFalse(foldedResult.Equals(unfoldedResult));

            var topAsBVXOR = ExprUtil.AsBVXOR(foldedResult);

            Assert.IsNotNull(topAsBVXOR);
            // Check the constant is the top left argument
            Assert.IsNotNull(ExprUtil.AsLiteral(topAsBVXOR.Args[0]));
        }
コード例 #2
0
        public void BVXORAssociativityAddNearbyConstants()
        {
            var builderPair = GetSimpleAndConstantFoldingBuilder();
            var sb          = builderPair.Item1;
            var cfb         = builderPair.Item2;

            var x = GetVarAndIdExpr("x", BasicType.GetBvType(4)).Item2;

            Expr foldedResult   = x;
            Expr unfoldedResult = foldedResult;

            for (int index = 1; index <= 3; ++index)
            {
                foldedResult   = cfb.BVXOR(cfb.ConstantBV(5, 4), foldedResult);
                unfoldedResult = sb.BVXOR(sb.ConstantBV(5, 4), unfoldedResult);
                CheckIsBvType(foldedResult, 4);
                CheckIsBvType(unfoldedResult, 4);
            }
            Assert.AreEqual("BVXOR4(5bv4, BVXOR4(5bv4, BVXOR4(5bv4, x)))", unfoldedResult.ToString());
            Assert.AreEqual("BVXOR4(5bv4, x)", foldedResult.ToString());

            Assert.IsFalse(foldedResult.Equals(unfoldedResult));

            var topAsBVXOR = ExprUtil.AsBVXOR(foldedResult);

            Assert.IsNotNull(topAsBVXOR);
            // Check the constant is the top left argument
            Assert.IsNotNull(ExprUtil.AsLiteral(topAsBVXOR.Args[0]));;
        }
コード例 #3
0
        public void NoFold()
        {
            var builderPair  = GetSimpleAndConstantFoldingBuilder();
            var sfb          = builderPair.Item1;
            var cfb          = builderPair.Item2;
            var v0           = GetVarAndIdExpr("x", BasicType.GetBvType(8));
            var v1           = GetVarAndIdExpr("y", BasicType.GetBvType(8));
            var foldedResult = cfb.BVXOR(v0.Item2, v1.Item2);
            var simpleResult = sfb.BVXOR(v0.Item2, v1.Item2);

            CheckIsBvType(foldedResult, 8);
            CheckIsBvType(simpleResult, 8);
            Assert.IsNotNull(ExprUtil.AsBVXOR(foldedResult));
            Assert.AreEqual(simpleResult, foldedResult);
        }