Exemple #1
0
        /// <summary>
        /// Allocate a register for the given type.
        /// </summary>
        protected override RegisterSpec Allocate(TypeReference type, bool forceObject, RCategory category, object parameter)
        {
            var isWide = !forceObject && type.IsWide();

            if (isWide)
            {
                var pair = body.AllocateWideRegister(category);
                switch (category)
                {
                case RCategory.Temp:
                    return(new RegisterSpec(pair.Item1, pair.Item2, type));

                case RCategory.Variable:
                case RCategory.VariablePreventOptimization:
                case RCategory.TempVariable:
                    return(new VariableRegisterSpec(pair.Item1, pair.Item2, type, (AstVariable)parameter));

                case RCategory.Argument:
                    return(new ArgumentRegisterSpec(pair.Item1, pair.Item2, type, ParameterWrapper.Wrap(parameter)));

                default:
                    throw new ArgumentException("Unknown category " + category);
                }
            }
            var isPrimitive = !forceObject && (type is PrimitiveType);
            var register    = body.AllocateRegister(category, isPrimitive ? RType.Value : RType.Object);

            switch (category)
            {
            case RCategory.Temp:
                return(new RegisterSpec(register, null, type));

            case RCategory.Variable:
            case RCategory.VariablePreventOptimization:
            case RCategory.TempVariable:
                return(new VariableRegisterSpec(register, null, type, (AstVariable)parameter));

            case RCategory.Argument:
                return(new ArgumentRegisterSpec(register, null, type, ParameterWrapper.Wrap(parameter)));

            default:
                throw new ArgumentException("Unknown category " + category);
            }
        }