Beispiel #1
0
        private static bool IsLeftToRightReassociable(
            IntrinsicPrototype prototype,
            out IntrinsicPrototype rightPrototype)
        {
            string op;
            string rightOp;
            bool   isChecked;

            if (ArithmeticIntrinsics.TryParseArithmeticIntrinsicName(prototype.Name, out op, out isChecked) &&
                !isChecked &&
                intArithLeftToRight.TryGetValue(op, out rightOp) &&
                prototype.ParameterTypes.All(x => x.IsIntegerType()))
            {
                rightPrototype = ArithmeticIntrinsics.CreatePrototype(
                    rightOp,
                    isChecked,
                    prototype.ResultType,
                    prototype.ParameterTypes);
                return(true);
            }
            else
            {
                rightPrototype = null;
                return(false);
            }
        }
Beispiel #2
0
        private static bool IsAssociative(IntrinsicPrototype prototype)
        {
            string op;
            bool   isChecked;

            if (ArithmeticIntrinsics.TryParseArithmeticIntrinsicName(prototype.Name, out op, out isChecked) &&
                !isChecked &&
                assocIntArith.Contains(op))
            {
                return(prototype.ParameterTypes.All(x => x.IsIntegerType()));
            }
            else
            {
                return(false);
            }
        }
Beispiel #3
0
        /// <summary>
        /// The default constant instruction evaluation function.
        /// </summary>
        /// <param name="prototype">
        /// The prorotype of the instruction to evaluate.
        /// </param>
        /// <param name="arguments">
        /// A list of arguments to the instruction, all of which
        /// must be constants.
        /// </param>
        /// <returns>
        /// <c>null</c> if the instruction cannot be evaluated; otherwise, the constant
        /// to which the instruction evaluates.
        /// </returns>
        public static Constant EvaluateDefault(
            InstructionPrototype prototype,
            IReadOnlyList <Constant> arguments)
        {
            if (prototype is CopyPrototype ||
                prototype is ReinterpretCastPrototype)
            {
                return(arguments[0]);
            }
            else if (prototype is ConstantPrototype)
            {
                var constProto = (ConstantPrototype)prototype;
                if (constProto.Value is DefaultConstant)
                {
                    // Try to specialize 'default' constants.
                    var intSpec = constProto.ResultType.GetIntegerSpecOrNull();
                    if (intSpec != null)
                    {
                        return(new IntegerConstant(0, intSpec));
                    }
                }
                return(constProto.Value);
            }
            else if (prototype is IntrinsicPrototype)
            {
                string   arithOp;
                Constant result;

                if (ArithmeticIntrinsics.TryParseArithmeticIntrinsicName(
                        ((IntrinsicPrototype)prototype).Name,
                        out arithOp) &&
                    ArithmeticIntrinsics.TryEvaluate(
                        arithOp,
                        prototype.ResultType,
                        arguments,
                        out result))
                {
                    return(result);
                }
            }
            return(null);
        }