Ejemplo n.º 1
0
        /// <summary>
        /// Get a dex if-test opcode for the given code
        /// </summary>
        internal static RCode ToIfTest(this AstCode code)
        {
            switch (code)
            {
            case AstCode.Cle:
                return(RCode.If_le);

            case AstCode.Cle_Un:
                return(RCode.If_le);

            case AstCode.Clt:
                return(RCode.If_lt);

            case AstCode.Clt_Un:
                return(RCode.If_lt);

            case AstCode.Ceq:
                return(RCode.If_eq);

            case AstCode.Cne:
                return(RCode.If_ne);

            case AstCode.Cgt:
                return(RCode.If_gt);

            case AstCode.Cgt_Un:
                return(RCode.If_gt);

            case AstCode.Cge:
                return(RCode.If_ge);

            case AstCode.Cge_Un:
                return(RCode.If_ge);

            case AstCode.__Beq:
                return(RCode.If_eq);

            case AstCode.__Bne_Un:
                return(RCode.If_ne);

            case AstCode.__Ble:
            case AstCode.__Ble_Un:
                return(RCode.If_le);

            case AstCode.__Blt:
            case AstCode.__Blt_Un:
                return(RCode.If_lt);

            case AstCode.__Bgt:
            case AstCode.__Bgt_Un:
                return(RCode.If_gt);

            case AstCode.__Bge:
            case AstCode.__Bge_Un:
                return(RCode.If_ge);

            default:
                throw new ArgumentOutOfRangeException("code", code.ToString());
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Convert condition to branch/zero.
        ///
        /// </summary>
        public static AstCode ToBranchZ(this AstCode code)
        {
            switch (code)
            {
            case AstCode.Cle:
            case AstCode.Cle_Un:
                return(AstCode.BrIfLe);

            case AstCode.Clt:
            case AstCode.Clt_Un:
                return(AstCode.BrIfLt);

            case AstCode.Ceq:
                return(AstCode.BrIfEq);

            case AstCode.Cne:
                return(AstCode.BrIfNe);

            case AstCode.Cgt:
            case AstCode.Cgt_Un:
                return(AstCode.BrIfGt);

            case AstCode.Cge:
            case AstCode.Cge_Un:
                return(AstCode.BrIfGe);

            default:
                throw new ArgumentOutOfRangeException("code", code.ToString());
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Reverses the code, taking account float/double NaN comparisons
        /// </summary>
        private static AstCode ReverseCode(AstCode code, XTypeReference type)
        {
            bool isFlt = type.IsDouble() || type.IsFloat();

            if (!isFlt)
            {
                return(code.Reverse());
            }

            switch (code)
            {
            case AstCode.Ceq:
                return(AstCode.Cne);

            case AstCode.Cne:
                return(AstCode.Ceq);

            case AstCode.Cle:
                return(AstCode.Cgt_Un);

            case AstCode.Cle_Un:
                return(AstCode.Cgt);

            case AstCode.Clt:
                return(AstCode.Cge_Un);

            case AstCode.Clt_Un:
                return(AstCode.Cge);

            case AstCode.Cgt:
                return(AstCode.Cle_Un);

            case AstCode.Cgt_Un:
                return(AstCode.Cle);

            case AstCode.Cge:
                return(AstCode.Clt_Un);

            case AstCode.Cge_Un:
                return(AstCode.Clt);

            default:
                throw new ArgumentOutOfRangeException("code", code.ToString());
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Reverse conditions
        /// </summary>
        public static AstCode Reverse(this AstCode code)
        {
            switch (code)
            {
            case AstCode.Cle:
                return(AstCode.Cgt);

            case AstCode.Cle_Un:
                return(AstCode.Cgt_Un);

            case AstCode.Clt:
                return(AstCode.Cge);

            case AstCode.Clt_Un:
                return(AstCode.Cge_Un);

            case AstCode.Ceq:
                return(AstCode.Cne);

            case AstCode.Cne:
                return(AstCode.Ceq);

            case AstCode.Cgt:
                return(AstCode.Cle);

            case AstCode.Cgt_Un:
                return(AstCode.Cle_Un);

            case AstCode.Cge:
                return(AstCode.Clt);

            case AstCode.Cge_Un:
                return(AstCode.Clt_Un);

            case AstCode.CIsNull:
                return(AstCode.CIsNotNull);

            case AstCode.CIsNotNull:
                return(AstCode.CIsNull);

            default:
                throw new ArgumentOutOfRangeException("code", code.ToString());
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Convert condition to branch
        /// </summary>
        public static AstCode ToBranch(this AstCode code)
        {
            switch (code)
            {
            case AstCode.Cle:
                return(AstCode.__Ble);

            case AstCode.Cle_Un:
                return(AstCode.__Ble_Un);

            case AstCode.Clt:
                return(AstCode.__Blt);

            case AstCode.Clt_Un:
                return(AstCode.__Blt_Un);

            case AstCode.Ceq:
                return(AstCode.__Beq);

            case AstCode.Cne:
                return(AstCode.__Bne_Un);

            case AstCode.Cgt:
                return(AstCode.__Bgt);

            case AstCode.Cgt_Un:
                return(AstCode.__Bgt_Un);

            case AstCode.Cge:
                return(AstCode.__Bge);

            case AstCode.Cge_Un:
                return(AstCode.__Bge_Un);

            default:
                throw new ArgumentOutOfRangeException("code", code.ToString());
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Reverses the code, taking account float/double NaN comparisons
        /// </summary>
        private static AstCode ReverseCode(AstCode code, XTypeReference type)
        {
            bool isFlt = type.IsDouble() || type.IsFloat();

            if (!isFlt)
                return code.Reverse();

            switch (code)
            {
                case AstCode.Ceq:
                    return AstCode.Cne;
                case AstCode.Cne:
                    return AstCode.Ceq;
                case AstCode.Cle:
                    return AstCode.Cgt_Un;
                case AstCode.Cle_Un:
                    return AstCode.Cgt;
                case AstCode.Clt:
                    return AstCode.Cge_Un;
                case AstCode.Clt_Un:
                    return AstCode.Cge;
                case AstCode.Cgt:
                    return AstCode.Cle_Un;
                case AstCode.Cgt_Un:
                    return AstCode.Cle;
                case AstCode.Cge:
                    return AstCode.Clt_Un;
                case AstCode.Cge_Un:
                    return AstCode.Clt;
                default:
                    throw new ArgumentOutOfRangeException("code", code.ToString());
            }            
        }
Ejemplo n.º 7
0
 public static string GetName(this AstCode code)
 {
     return(code.ToString().ToLowerInvariant().TrimStart('_').Replace('_', '.'));
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Get a dex if-testz opcode for the given code
        /// </summary>
        internal static RCode ToIfTestZ(this AstCode code)
        {
            switch (code)
            {
            case AstCode.Cle:
                return(RCode.If_lez);

            case AstCode.Cle_Un:
                return(RCode.If_lez);

            case AstCode.Clt:
                return(RCode.If_ltz);

            case AstCode.Clt_Un:
                return(RCode.If_ltz);

            case AstCode.Ceq:
                return(RCode.If_eqz);

            case AstCode.Cne:
                return(RCode.If_nez);

            case AstCode.Cgt:
                return(RCode.If_gtz);

            case AstCode.Cgt_Un:
                return(RCode.If_gtz);

            case AstCode.Cge:
                return(RCode.If_gez);

            case AstCode.Cge_Un:
                return(RCode.If_gez);

            case AstCode.__Beq:
                return(RCode.If_eqz);

            case AstCode.__Bne_Un:
                return(RCode.If_nez);

            case AstCode.__Ble:
            case AstCode.__Ble_Un:
                return(RCode.If_lez);

            case AstCode.__Blt:
            case AstCode.__Blt_Un:
                return(RCode.If_ltz);

            case AstCode.__Bgt:
            case AstCode.__Bgt_Un:
                return(RCode.If_gtz);

            case AstCode.__Bge:
            case AstCode.__Bge_Un:
                return(RCode.If_gez);

            case AstCode.CIsNotNull:
                return(RCode.If_nez);

            case AstCode.CIsNull:
                return(RCode.If_eqz);

            case AstCode.Brtrue:
                return(RCode.If_nez);

            case AstCode.Brfalse:
                return(RCode.If_eqz);

            case AstCode.BrIfEq:
                return(RCode.If_eqz);

            case AstCode.BrIfNe:
                return(RCode.If_nez);

            case AstCode.BrIfGe:
                return(RCode.If_gez);

            case AstCode.BrIfGt:
                return(RCode.If_gtz);

            case AstCode.BrIfLe:
                return(RCode.If_lez);

            case AstCode.BrIfLt:
                return(RCode.If_ltz);

            default:
                throw new ArgumentOutOfRangeException("code", code.ToString());
            }
        }