Exemplo n.º 1
0
        /// <summary>
        /// Pops the required arguments from the stack.
        /// </summary>
        /// <param name="location">The current location.</param>
        /// <param name="methodBase">The method to use for the argument types.</param>
        /// <param name="instanceValue">The instance value (if available).</param>
        public ImmutableArray <ValueReference> PopMethodArgs(
            Location location,
            MethodBase methodBase,
            Value instanceValue)
        {
            var parameters      = methodBase.GetParameters();
            var parameterOffset = methodBase.GetParameterOffset();
            var result          = ImmutableArray.CreateBuilder <ValueReference>(
                parameters.Length + parameterOffset);

            // Handle main params
            for (int i = parameters.Length - 1; i >= 0; --i)
            {
                var param    = parameters[i];
                var argument = Pop(
                    Builder.CreateType(param.ParameterType),
                    param.ParameterType.IsUnsignedInt() ?
                    ConvertFlags.TargetUnsigned : ConvertFlags.None);
                result.Add(argument);
            }

            // Check instance value
            if (parameterOffset > 0)
            {
                if (instanceValue == null)
                {
                    var declaringType = Builder.CreateType(methodBase.DeclaringType);
                    if (!Intrinsics.IsIntrinsicArrayType(methodBase.DeclaringType))
                    {
                        declaringType = Builder.CreatePointerType(
                            declaringType,
                            MemoryAddressSpace.Generic);
                    }
                    instanceValue = Pop(
                        declaringType,
                        ConvertFlags.None);
                }
                else
                {
                    // Wire instance
                    instanceValue = Builder.CreateAddressSpaceCast(
                        location,
                        instanceValue,
                        MemoryAddressSpace.Generic);
                }

                result.Add(instanceValue);
            }

            result.Reverse();
            return(result.MoveToImmutable());
        }