コード例 #1
0
        public void ToString_CompareInstruction(CompareKind compareKind, string expectedString)
        {
            var compareInstruction = new CompareInstruction(compareKind);

            Assert.Equal(expectedString, compareInstruction.ToString());
        }
コード例 #2
0
        ExecuteComparisonInstructionBackward(CompareInstruction compareInstruction,
                                             Operand varOperand, Path path)
        {
            Expression result             = null;
            Operator   comparisonOperator = null;

            switch (compareInstruction.ConditionCode)
            {
            case ConditionCode.GT:
                comparisonOperator = OperatorStore.GreaterThanOp;
                break;

            case ConditionCode.UGT:
                comparisonOperator = OperatorStore.UGreaterThanOp;
                break;

            case ConditionCode.FGT:
                comparisonOperator = OperatorStore.FGreaterThanOp;
                break;

            case ConditionCode.GE:
                comparisonOperator = OperatorStore.GreaterThanEqualOp;
                break;

            case ConditionCode.UGE:
                comparisonOperator = OperatorStore.UGreaterThanEqualOp;
                break;

            case ConditionCode.FGE:
                comparisonOperator = OperatorStore.FGreaterThanEqualOp;
                break;

            case ConditionCode.LT:
                comparisonOperator = OperatorStore.LessThanOp;
                break;

            case ConditionCode.ULT:
                comparisonOperator = OperatorStore.ULessThanOp;
                break;

            case ConditionCode.FLT:
                comparisonOperator = OperatorStore.FLessThanOp;
                break;

            case ConditionCode.LE:
                comparisonOperator = OperatorStore.LessThanEqualOp;
                break;

            case ConditionCode.ULE:
                comparisonOperator = OperatorStore.ULessThanEqualOp;
                break;

            case ConditionCode.FLE:
                comparisonOperator = OperatorStore.FLessThanEqualOp;
                break;

            case ConditionCode.EQ:
                comparisonOperator = OperatorStore.EqualOp;
                break;

            case ConditionCode.NE:
                comparisonOperator = OperatorStore.NotEqualOp;
                break;

            default:
                throw new NotImplementedException("PHOENIX: Compare instruction Opcode " +
                                                  "not implemented in symbolic tracer: " + compareInstruction.ToString());
            }

            Operand    srcOp1   = compareInstruction.SourceOperand1;
            Operand    srcOp2   = compareInstruction.SourceOperand2;
            Expression srcExpr1 = TraceOperandBackward(srcOp1, varOperand, path);
            Expression srcExpr2 = TraceOperandBackward(srcOp2, varOperand, path);

            result = new Expression(comparisonOperator, srcExpr1, srcExpr2,
                                    path.Config.WORD_BITSIZE);
            result.Type = compareInstruction.DestinationOperand.Type;

            BranchInstruction branchInstruction = compareInstruction.Next.AsBranchInstruction;

            if (branchInstruction != null)
            {
                if (path.Blocks[path.Blocks.IndexOf(compareInstruction.BasicBlock) + 1] ==
                    branchInstruction.FalseLabelInstruction.BasicBlock)
                {
                    result      = new Expression(OperatorStore.NotOp, result, result.BitSize);
                    result.Type = compareInstruction.DestinationOperand.Type;
                }
            }

            return(result);
        }