Ejemplo n.º 1
0
        private Expression GetStackValue(int offset, DataType accessDataType)
        {
            Expression value;

            if (StackState.TryGetValue(offset, out value))
            {
                if (value == Constant.Invalid)
                {
                    return(value);
                }
                int excess = accessDataType.Size - value.DataType.Size;
                if (excess == 0)
                {
                    return(value);
                }
                if (excess > 0)
                {
                    // Example: word32 fetch from SP+04, where SP+04 is a word16 and SP+06 is a word16
                    int        remainder = offset + value.DataType.Size;
                    Expression v2;
                    if (StackState.TryGetValue(remainder, out v2))
                    {
                        if (v2 == Constant.Invalid || value == Constant.Invalid)
                        {
                            return(Constant.Invalid);
                        }
                        if (v2.DataType.Size + value.DataType.Size != accessDataType.Size)
                        {
                            return(Constant.Invalid);
                        }

                        //$BUGBUG: should evaluate the MkSequence, possibly creating a longer constant if v2 and value are
                        // constant.
                        //$BUGBUG: the sequence below is little-endian!!!
                        return(new MkSequence(accessDataType, v2, value));
                    }
                }
                else
                {
                    // Example: fetching a byte from SP+04, which previously was assigned an int32.
                    return(new Cast(accessDataType, value));
                }
            }
            else
            {
                int offset2;
                if (StackState.TryGetLowerBoundKey(offset, out offset2))
                {
                    var value2 = StackState[offset2];
                    if (offset2 + value2.DataType.Size > offset)
                    {
                        return(new Slice(accessDataType, StackState[offset2], ((offset - offset2) * 8)));
                    }
                }
            }
            return(Constant.Invalid);
        }