Exemplo n.º 1
0
        public static Constant SimplifyTwoConstants(BinaryOperator op, Constant l, Constant r)
        {
            var lType = (PrimitiveType)l.DataType;
            var rType = (PrimitiveType)r.DataType;

            return(op.ApplyConstants(l, r));
        }
Exemplo n.º 2
0
        private void RunApply(int a, int b, BinaryOperator op, int expected)
        {
            Constant c1 = Constant.Word32(a);
            Constant c2 = Constant.Word32(b);
            Constant c3 = op.ApplyConstants(c1, c2);

            Assert.AreEqual(expected, (int)c3.ToInt64());
        }
Exemplo n.º 3
0
        public static Constant SimplifyTwoConstants(BinaryOperator op, Constant l, Constant r)
        {
            var lType = (PrimitiveType)l.DataType;
            var rType = (PrimitiveType)r.DataType;

            if ((lType.Domain & rType.Domain) == 0)
            {
                throw new ArgumentException(string.Format("Can't add types of disjoint domains {0} and {1}", l.DataType, r.DataType));
            }
            return(op.ApplyConstants(l, r));
        }
Exemplo n.º 4
0
        public bool Match(Slice slice)
        {
            MemoryAccess acc = slice.Expression as MemoryAccess;

            if (acc == null)
            {
                return(false);
            }

            b = acc.EffectiveAddress;
            Constant         offset = Constant.Create(b.DataType, 0);
            BinaryOperator   op     = Operator.IAdd;
            BinaryExpression ea     = b as BinaryExpression;

            if (ea != null)
            {
                Constant c = ea.Right as Constant;
                if (c != null)
                {
                    offset = c;
                    b      = ea.Left;
                }
            }
            else
            {
                b = acc.EffectiveAddress;
            }
            int bitBegin = slice.Offset;
            int bitEnd   = bitBegin + slice.DataType.BitSize;

            if (0 <= bitBegin && bitEnd <= acc.DataType.BitSize)
            {
                offset = op.ApplyConstants(offset, Constant.Create(acc.EffectiveAddress.DataType, slice.Offset / 8));
                var newEa = new BinaryExpression(op, offset.DataType, b, offset);
                if (acc is SegmentedAccess seg)
                {
                    b = new SegmentedAccess(seg.MemoryId, seg.BasePointer, newEa, slice.DataType);
                }
                else
                {
                    b = new MemoryAccess(acc.MemoryId, newEa, slice.DataType);
                }
                return(true);
            }
            return(false);
        }