Пример #1
0
        internal override void Transform(LLFunction pFunction)
        {
            LLLocation locationLeftOperand  = mLeftOperandSource.Load(pFunction);
            LLLocation locationRightOperand = mRightOperandSource.Load(pFunction);

            LLType typeOperands = LLModule.BinaryResult(locationLeftOperand.Type, locationRightOperand.Type);

            locationLeftOperand  = pFunction.CurrentBlock.EmitConversion(locationLeftOperand, typeOperands);
            locationRightOperand = pFunction.CurrentBlock.EmitConversion(locationRightOperand, typeOperands);

            LLLocation locationTemporary = LLTemporaryLocation.Create(pFunction.CreateTemporary(LLModule.BooleanType));

            if (typeOperands.Primitive == LLPrimitive.Float)
            {
                LLCompareFloatsCondition condition = LLCompareFloatsCondition.oeq;
                switch (mCompareType)
                {
                case HLCompareType.Equal: condition = LLCompareFloatsCondition.oeq; break;

                case HLCompareType.NotEqual: condition = LLCompareFloatsCondition.one; break;

                case HLCompareType.GreaterThan: condition = LLCompareFloatsCondition.ogt; break;

                case HLCompareType.GreaterThanOrEqual: condition = LLCompareFloatsCondition.oge; break;

                case HLCompareType.LessThan: condition = LLCompareFloatsCondition.olt; break;

                case HLCompareType.LessThanOrEqual: condition = LLCompareFloatsCondition.ole; break;

                default: throw new NotSupportedException();
                }
                pFunction.CurrentBlock.EmitCompareFloats(locationTemporary, locationLeftOperand, locationRightOperand, condition);
            }
            else
            {
                LLCompareIntegersCondition condition = LLCompareIntegersCondition.eq;
                switch (mCompareType)
                {
                case HLCompareType.Equal: condition = LLCompareIntegersCondition.eq; break;

                case HLCompareType.NotEqual: condition = LLCompareIntegersCondition.ne; break;

                case HLCompareType.GreaterThan: condition = typeOperands.Primitive == LLPrimitive.Unsigned ? LLCompareIntegersCondition.ugt : LLCompareIntegersCondition.sgt; break;

                case HLCompareType.GreaterThanOrEqual: condition = typeOperands.Primitive == LLPrimitive.Unsigned ? LLCompareIntegersCondition.uge : LLCompareIntegersCondition.sge; break;

                case HLCompareType.LessThan: condition = typeOperands.Primitive == LLPrimitive.Unsigned ? LLCompareIntegersCondition.ult : LLCompareIntegersCondition.slt; break;

                case HLCompareType.LessThanOrEqual: condition = typeOperands.Primitive == LLPrimitive.Unsigned ? LLCompareIntegersCondition.ule : LLCompareIntegersCondition.sle; break;

                default: throw new NotSupportedException();
                }
                pFunction.CurrentBlock.EmitCompareIntegers(locationTemporary, locationLeftOperand, locationRightOperand, condition);
            }

            mDestination.Store(pFunction, locationTemporary);
        }
Пример #2
0
        internal override void Transform(LLFunction pFunction)
        {
            LLLocation locationLeftOperand  = mLeftOperandSource.Load(pFunction);
            LLLocation locationRightOperand = mRightOperandSource.Load(pFunction);

            LLType typeOperands = LLModule.BinaryResult(locationLeftOperand.Type, locationRightOperand.Type);

            locationLeftOperand  = pFunction.CurrentBlock.EmitConversion(locationLeftOperand, typeOperands);
            locationRightOperand = pFunction.CurrentBlock.EmitConversion(locationRightOperand, typeOperands);

            LLLocation locationTemporary = LLTemporaryLocation.Create(pFunction.CreateTemporary(typeOperands));

            pFunction.CurrentBlock.EmitMultiply(locationTemporary, locationLeftOperand, locationRightOperand);

            mDestination.Store(pFunction, locationTemporary);
        }