Example #1
0
        public void BVORAssociativityPropagateConstantUp()
        {
            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.BVOR(x, foldedResult);
                unfoldedResult = sb.BVOR(x, unfoldedResult);
                CheckIsBvType(foldedResult, 4);
                CheckIsBvType(unfoldedResult, 4);
            }

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

            var topAsBVOR = ExprUtil.AsBVOR(foldedResult);

            Assert.IsNotNull(topAsBVOR);
            // Check the constant is the top left argument
            Assert.IsNotNull(ExprUtil.AsLiteral(topAsBVOR.Args[0]));
        }
Example #2
0
        public void BVORAssociativityAddNearbyConstants()
        {
            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.BVOR(cfb.ConstantBV(5, 4), foldedResult);
                unfoldedResult = sb.BVOR(sb.ConstantBV(5, 4), unfoldedResult);
                CheckIsBvType(foldedResult, 4);
                CheckIsBvType(unfoldedResult, 4);
            }
            Assert.AreEqual("BVOR4(5bv4, BVOR4(5bv4, BVOR4(5bv4, x)))", unfoldedResult.ToString());
            Assert.AreEqual("BVOR4(5bv4, x)", foldedResult.ToString());

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

            var topAsBVOR = ExprUtil.AsBVOR(foldedResult);

            Assert.IsNotNull(topAsBVOR);
            // Check the constant is the top left argument
            Assert.IsNotNull(ExprUtil.AsLiteral(topAsBVOR.Args[0]));;
        }
Example #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.BVOR(v0.Item2, v1.Item2);
            var simpleResult = sfb.BVOR(v0.Item2, v1.Item2);

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