Ejemplo n.º 1
0
 /// <summary>
 /// Generate converter for the value of an Const instruction.
 /// </summary>
 internal static Func <object, object> ConstValueConverter(this XTypeReference elementType, bool keepUnsigned)
 {
     if (elementType.IsBoolean())
     {
         return(x => Convert.ToBoolean(x) ? 1 : 0);
     }
     if (elementType.IsByte())
     {
         if (keepUnsigned)
         {
             return(x => (int)Convert.ToByte(x));
         }
         return(x => (int)((sbyte)unchecked (Convert.ToByte(x))));
     }
     if (elementType.IsSByte())
     {
         return(x => (int)(Convert.ToSByte(x)));
     }
     if (elementType.IsChar())
     {
         return(x => (int)(Convert.ToChar(x)));
     }
     if (elementType.IsUInt16())
     {
         return(x => (int)(Convert.ToUInt16(x)));
     }
     if (elementType.IsInt16())
     {
         return(x => (int)(Convert.ToInt16(x)));
     }
     if (elementType.IsInt32())
     {
         return(x => XConvert.ToInt(x));
     }
     if (elementType.IsUInt32())
     {
         return(x => XConvert.ToInt(x));                       // unchecked((int)Convert.ToUInt32(Convert.ToInt64(x) & 0xFFFFFFFF));
     }
     if (elementType.IsFloat())
     {
         return(x => Convert.ToSingle(x));
     }
     if (elementType.IsInt64())
     {
         return(x => XConvert.ToLong(x));
     }
     if (elementType.IsUInt64())
     {
         return(x => XConvert.ToLong(x));                        // unchecked((long)Convert.ToInt64(x));
     }
     if (elementType.IsDouble())
     {
         return(x => Convert.ToDouble(x));
     }
     if (elementType.IsDexObject() && !elementType.IsVoid())
     {
         return(x => x);
     }
     throw new NotSupportedException("Unknown type for constValueConverter " + elementType);
 }
Ejemplo n.º 2
0
        private static bool CanPullComparisonUp(AstCode code, XTypeReference arg1, XTypeReference arg2, PullTarget target)
        {
            if (arg1 == null || arg2 == null)
            {
                return(false);
            }

            bool isReference = arg1.IsDexObject() && arg1.IsDexObject();

            if (!isReference && !arg1.IsSame(arg2))
            {
                return(false);
            }

            if (target == PullTarget.Comparison)
            {
                return(true);
            }

            if (arg1.Is(XTypeReferenceKind.Float))
            {
                return(false);
            }
            if (arg1.IsDexWide())
            {
                return(false);
            }

            bool isEq = IsEqualsBranchOrComparison(code);

            if (isEq)
            {
                return(true);
            }


            bool isUnsigned = arg1.IsUInt16() || arg1.IsUInt32(); // TODO: check if we really have to exclude unsigned.

            if (isReference || isUnsigned)
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Generate an Move_result opcode.
 /// </summary>
 internal static RCode MoveResult(this XTypeReference type)
 {
     if (type.IsDexWide())
     {
         return(RCode.Move_result_wide);
     }
     if (type.IsVoid())
     {
         throw new ArgumentException("Unexpected void expression type");
     }
     if (type.IsDexValue())
     {
         return(RCode.Move_result);
     }
     if (type.IsDexObject())
     {
         return(RCode.Move_result_object);
     }
     throw new ArgumentException("Unknown type in move_result " + type);
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Generate a iput opcode.
 /// </summary>
 internal static RCode IPut(this XTypeReference type)
 {
     if (type.IsDexWide())
     {
         return(RCode.Iput_wide);
     }
     if (type.IsVoid())
     {
         throw new ArgumentException("Unexpected void expression type");
     }
     if (type.IsDexBoolean())
     {
         return(RCode.Iput_boolean);
     }
     if (type.IsDexChar())
     {
         return(RCode.Iput_char);
     }
     if (type.IsDexShort())
     {
         return(RCode.Iput_short);
     }
     if (type.IsDexByte())
     {
         return(RCode.Iput_byte);
     }
     if (type.IsDexValue())
     {
         return(RCode.Iput);
     }
     if (type.IsDexObject())
     {
         return(RCode.Iput_object);
     }
     throw new ArgumentException("Unknown type in iput " + type);
 }