Пример #1
0
        /// <summary>
        /// Determines whether [is call target supported] [the specified target type].
        /// </summary>
        /// <param name="targetType">Type of the target.</param>
        /// <param name="flags">The flags.</param>
        /// <returns>
        ///     <c>true</c> if [is call target supported] [the specified target type]; otherwise, <c>false</c>.
        /// </returns>
        private static bool IsCallTargetSupported(TableType targetType, InvokeSupportFlags flags)
        {
            bool result = false;

            if (targetType == TableType.MethodDef && InvokeSupportFlags.MethodDef == (flags & InvokeSupportFlags.MethodDef))
            {
                result = true;
            }
            else if (targetType == TableType.MemberRef && InvokeSupportFlags.MemberRef == (flags & InvokeSupportFlags.MemberRef))
            {
                result = true;
            }
            else if (targetType == TableType.MethodSpec && InvokeSupportFlags.MethodSpec == (flags & InvokeSupportFlags.MethodSpec))
            {
                result = true;
            }

            return(result);
        }
Пример #2
0
        /// <summary>
        /// Determines whether [is call target supported] [the specified target type].
        /// </summary>
        /// <param name="targetType">Type of the target.</param>
        /// <param name="flags">The flags.</param>
        /// <returns>
        /// 	<c>true</c> if [is call target supported] [the specified target type]; otherwise, <c>false</c>.
        /// </returns>
        private static bool IsCallTargetSupported(TableType targetType, InvokeSupportFlags flags)
        {
            bool result = false;

            if (targetType == TableType.MethodDef && InvokeSupportFlags.MethodDef == (flags & InvokeSupportFlags.MethodDef))
                result = true;
            else if (targetType == TableType.MemberRef && InvokeSupportFlags.MemberRef == (flags & InvokeSupportFlags.MemberRef))
                result = true;
            else if (targetType == TableType.MethodSpec && InvokeSupportFlags.MethodSpec == (flags & InvokeSupportFlags.MethodSpec))
                result = true;

            return result;
        }
Пример #3
0
        /// <summary>
        /// Decodes the invocation target.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="decoder">The IL decoder, which provides decoding functionality.</param>
        /// <param name="flags">Flags, which control the</param>
        /// <returns></returns>
        protected static Token DecodeInvocationTarget(Context ctx, IInstructionDecoder decoder, InvokeSupportFlags flags)
        {
            // Retrieve the immediate argument - it contains the token
            // of the methoddef, methodref, methodspec or callsite to call.
            Token callTarget = decoder.DecodeTokenType();

            if (!IsCallTargetSupported(callTarget.Table, flags))
                throw new InvalidOperationException(@"Invalid IL call target specification.");

            ITypeModule module = decoder.Method.Module;
            RuntimeMethod method = null;

            switch (callTarget.Table)
            {
                case TableType.MethodDef:
                    method = module.GetMethod(callTarget);
                    break;

                case TableType.MemberRef:
                    method = module.GetMethod(callTarget, decoder.Method.DeclaringType);
                    if (method.DeclaringType.IsGeneric)
                        decoder.Compiler.Scheduler.ScheduleTypeForCompilation(method.DeclaringType);
                    break;

                case TableType.MethodSpec:
                    method = module.GetMethod(callTarget);
                    decoder.Compiler.Scheduler.ScheduleTypeForCompilation(method.DeclaringType);
                    break;

                default:
                    Debug.Assert(false, @"Should never reach this!");
                    break;
            }

            if (method.DeclaringType.ContainsOpenGenericParameters)
            {
                method = decoder.GenericTypePatcher.PatchMethod(method.DeclaringType.Module, decoder.Method.DeclaringType as CilGenericType, method);
                decoder.Compiler.Scheduler.ScheduleTypeForCompilation(method.DeclaringType);
            }

            SetInvokeTarget(ctx, decoder.Compiler, method);

            return callTarget;
        }
        /// <summary>
        /// Decodes the invocation target.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="decoder">The IL decoder, which provides decoding functionality.</param>
        /// <param name="flags">Flags, which control the</param>
        /// <returns></returns>
        protected static MosaMethod DecodeInvocationTarget(InstructionNode ctx, IInstructionDecoder decoder, InvokeSupportFlags flags)
        {
            var method = (MosaMethod)decoder.Instruction.Operand;

            decoder.Compiler.Scheduler.TrackMethodInvoked(method);

            SetInvokeTarget(ctx, decoder.Compiler, method);

            return method;
        }
Пример #5
0
        /// <summary>
        /// Decodes the invocation target.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="decoder">The IL decoder, which provides decoding functionality.</param>
        /// <param name="flags">Flags, which control the</param>
        /// <returns></returns>
        protected static MosaMethod DecodeInvocationTarget(InstructionNode ctx, IInstructionDecoder decoder, InvokeSupportFlags flags)
        {
            var method = (MosaMethod)decoder.Instruction.Operand;

            decoder.Compiler.Scheduler.TrackMethodInvoked(method);

            SetInvokeTarget(ctx, decoder.Compiler, method);

            return(method);
        }
Пример #6
0
        /// <summary>
        /// Decodes the invocation target.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="decoder">The IL decoder, which provides decoding functionality.</param>
        /// <param name="flags">Flags, which control the</param>
        protected static TokenTypes DecodeInvocationTarget(Context ctx, IInstructionDecoder decoder, InvokeSupportFlags flags)
        {
            // Holds the token of the call target
            TokenTypes callTarget, targetType;
            // Method
            RuntimeMethod method = null;

            // Retrieve the immediate argument - it contains the token
            // of the methoddef, methodref, methodspec or callsite to call.
            decoder.Decode(out callTarget);
            targetType = (TokenTypes.TableMask & callTarget);
            if (!IsCallTargetSupported(targetType, flags))
                throw new InvalidOperationException(@"Invalid IL call target specification.");

            switch (targetType) {
                case TokenTypes.MethodDef:
                    method = RuntimeBase.Instance.TypeLoader.GetMethod(decoder.Method, decoder.Method.Module, callTarget);
                    break;

                case TokenTypes.MemberRef:
                    method = RuntimeBase.Instance.TypeLoader.GetMethod(decoder.Method, decoder.Method.Module, callTarget);
                    if (method.DeclaringType.IsGeneric == true)
                    {
                        ScheduleMethodForCompilation(decoder, method);
                    }
                    break;

                case TokenTypes.MethodSpec:
                    method = DecodeMethodSpecification(decoder, callTarget);
                    break;

                default:
                    Debug.Assert(false, @"Should never reach this!");
                    break;
            }

            SetInvokeTarget(ctx, decoder.Compiler, method);

            return callTarget;
        }
Пример #7
0
        /// <summary>
        /// Decodes the invocation target.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="decoder">The IL decoder, which provides decoding functionality.</param>
        /// <param name="flags">Flags, which control the</param>
        /// <returns></returns>
        protected static Token DecodeInvocationTarget(Context ctx, IInstructionDecoder decoder, InvokeSupportFlags flags)
        {
            // Retrieve the immediate argument - it contains the token
            // of the methoddef, methodref, methodspec or callsite to call.
            Token callTarget = decoder.DecodeTokenType();

            if (!IsCallTargetSupported(callTarget.Table, flags))
            {
                throw new InvalidOperationException(@"Invalid IL call target specification.");
            }

            RuntimeMethod method = null;
            ITypeModule   module = null;

            Mosa.Runtime.TypeSystem.Generic.CilGenericType genericType = decoder.Method.DeclaringType as Mosa.Runtime.TypeSystem.Generic.CilGenericType;
            if (genericType != null)
            {
                module = (decoder.Method.DeclaringType as Mosa.Runtime.TypeSystem.Generic.CilGenericType).BaseGenericType.Module;
            }
            else
            {
                module = decoder.Method.Module;
            }

            switch (callTarget.Table)
            {
            case TableType.MethodDef:
                method = module.GetMethod(callTarget);
                break;

            case TableType.MemberRef:
                method = module.GetMethod(callTarget, decoder.Method.DeclaringType);
                if (method.DeclaringType.IsGeneric)
                {
                    decoder.Compiler.Scheduler.ScheduleTypeForCompilation(method.DeclaringType);
                }
                break;

            case TableType.MethodSpec:
                method = module.GetMethod(callTarget);
                decoder.Compiler.Scheduler.ScheduleTypeForCompilation(method.DeclaringType);
                break;

            default:
                Debug.Assert(false, @"Should never reach this!");
                break;
            }

            SetInvokeTarget(ctx, decoder.Compiler, method);

            return(callTarget);
        }
Пример #8
0
        /// <summary>
        /// Decodes the invocation target.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="decoder">The IL decoder, which provides decoding functionality.</param>
        /// <param name="flags">Flags, which control the</param>
        protected static void DecodeInvocationTarget(Context ctx, IInstructionDecoder decoder, InvokeSupportFlags flags)
        {
            // Holds the token of the call target
            TokenTypes callTarget, targetType;
            // Method
            RuntimeMethod method = null;

            // Retrieve the immediate argument - it contains the token
            // of the methoddef, methodref, methodspec or callsite to call.
            decoder.Decode(out callTarget);
            targetType = (TokenTypes.TableMask & callTarget);
            if (!IsCallTargetSupported(targetType, flags))
            {
                throw new InvalidOperationException(@"Invalid IL call target specification.");
            }

            switch (targetType)
            {
            case TokenTypes.MethodDef:
                method = RuntimeBase.Instance.TypeLoader.GetMethod(decoder.Method.Module, callTarget);
                break;

            case TokenTypes.MemberRef:
                method = RuntimeBase.Instance.TypeLoader.GetMethod(decoder.Method.Module, callTarget);
                break;

            case TokenTypes.MethodSpec:
                throw new NotImplementedException();

            default:
                Debug.Assert(false, @"Should never reach this!");
                break;
            }

            SetInvokeTarget(ctx, decoder.Compiler, method);
        }