/// <summary>
        /// Visitation function for <see cref="CIL.ICILVisitor.UnaryBranch"/>.
        /// </summary>
        /// <param name="ctx">The context.</param>
        void CIL.ICILVisitor.UnaryBranch(Context ctx)
        {
            IBranch branch = ctx.Branch;

            CIL.OpCode opcode = (ctx.Instruction as CIL.ICILInstruction).OpCode;
            Operand    op     = ctx.Operand1;

            ctx.SetInstruction(CPUx86.Instruction.CmpInstruction, ctx.Operand1, new ConstantOperand(new SigType(CilElementType.I4), 0));

            if (opcode == CIL.OpCode.Brtrue || opcode == CIL.OpCode.Brtrue_s)
            {
                ctx.AppendInstruction(CPUx86.Instruction.BranchInstruction, IR.ConditionCode.Equal);
            }
            else
            if (opcode == CIL.OpCode.Brfalse || opcode == CIL.OpCode.Brfalse_s)
            {
                ctx.AppendInstruction(CPUx86.Instruction.BranchInstruction, IR.ConditionCode.NotEqual);
            }
            else
            {
                throw new NotImplementedException();
            }

            ctx.SetBranch(branch.Targets[0]);
        }
Exemple #2
0
        /// <summary>
        /// Converts the specified opcode.
        /// </summary>
        /// <param name="opcode">The opcode.</param>
        /// <returns></returns>
        public static IR.ConditionCode ConvertCondition(CIL.OpCode opcode)
        {
            switch (opcode)
            {
            // Signed
            case CIL.OpCode.Beq_s: return(IR.ConditionCode.Equal);

            case CIL.OpCode.Bge_s: return(IR.ConditionCode.GreaterOrEqual);

            case CIL.OpCode.Bgt_s: return(IR.ConditionCode.GreaterThan);

            case CIL.OpCode.Ble_s: return(IR.ConditionCode.LessOrEqual);

            case CIL.OpCode.Blt_s: return(IR.ConditionCode.LessThan);

            // Unsigned
            case CIL.OpCode.Bne_un_s: return(IR.ConditionCode.NotEqual);

            case CIL.OpCode.Bge_un_s: return(IR.ConditionCode.UnsignedGreaterOrEqual);

            case CIL.OpCode.Bgt_un_s: return(IR.ConditionCode.UnsignedGreaterThan);

            case CIL.OpCode.Ble_un_s: return(IR.ConditionCode.UnsignedLessOrEqual);

            case CIL.OpCode.Blt_un_s: return(IR.ConditionCode.UnsignedLessThan);

            // Long form signed
            case CIL.OpCode.Beq: goto case CIL.OpCode.Beq_s;

            case CIL.OpCode.Bge: goto case CIL.OpCode.Bge_s;

            case CIL.OpCode.Bgt: goto case CIL.OpCode.Bgt_s;

            case CIL.OpCode.Ble: goto case CIL.OpCode.Ble_s;

            case CIL.OpCode.Blt: goto case CIL.OpCode.Blt_s;

            // Long form unsigned
            case CIL.OpCode.Bne_un: goto case CIL.OpCode.Bne_un_s;

            case CIL.OpCode.Bge_un: goto case CIL.OpCode.Bge_un_s;

            case CIL.OpCode.Bgt_un: goto case CIL.OpCode.Bgt_un_s;

            case CIL.OpCode.Ble_un: goto case CIL.OpCode.Ble_un_s;

            case CIL.OpCode.Blt_un: goto case CIL.OpCode.Blt_un_s;

            // Compare
            case CIL.OpCode.Ceq: return(IR.ConditionCode.Equal);

            case CIL.OpCode.Cgt: return(IR.ConditionCode.GreaterThan);

            case CIL.OpCode.Cgt_un: return(IR.ConditionCode.UnsignedGreaterThan);

            case CIL.OpCode.Clt: return(IR.ConditionCode.LessThan);

            case CIL.OpCode.Clt_un: return(IR.ConditionCode.UnsignedLessThan);

            default: throw new NotImplementedException();
            }
        }