コード例 #1
0
ファイル: ILProvider.cs プロジェクト: rivy/corert
        private MethodIL CreateMethodIL(MethodDesc method)
        {
            if (method is EcmaMethod)
            {
                // TODO: Workaround: we should special case methods with Intrinsic attribute, but since
                //       CoreLib source is still not in the repo, we have to work with what we have, which is
                //       an MCG attribute on the type itself...
                if (((MetadataType)method.OwningType).HasCustomAttribute("System.Runtime.InteropServices", "McgIntrinsicsAttribute"))
                {
                    var name = method.Name;
                    if (name == "Call")
                    {
                        return(CalliIntrinsic.EmitIL(method));
                    }
                    else
                    if (name == "AddrOf")
                    {
                        return(AddrOfIntrinsic.EmitIL(method));
                    }
                }

                if (method.IsIntrinsic)
                {
                    MethodIL result = TryGetIntrinsicMethodIL(method);
                    if (result != null)
                    {
                        return(result);
                    }
                }

                if (method.IsPInvoke)
                {
                    var pregenerated = McgInteropSupport.TryGetPregeneratedPInvoke(method);
                    if (pregenerated == null)
                    {
                        return(PInvokeILEmitter.EmitIL(method));
                    }
                    method = pregenerated;
                }

                if (method.IsRuntimeImplemented)
                {
                    MethodIL result = TryGetRuntimeImplementedMethodIL(method);
                    if (result != null)
                    {
                        return(result);
                    }
                }

                MethodIL methodIL = EcmaMethodIL.Create((EcmaMethod)method);
                if (methodIL != null)
                {
                    return(methodIL);
                }

                if (!method.IsInternalCall && !method.IsRuntimeImplemented)
                {
                    return(MissingMethodBodyILEmitter.EmitIL(method));
                }

                return(null);
            }
            else
            if (method is MethodForInstantiatedType || method is InstantiatedMethod)
            {
                if (method.IsIntrinsic && method.Name == "CreateInstanceIntrinsic")
                {
                    // CreateInstanceIntrinsic is specialized per instantiation
                    return(CreateInstanceIntrinsic.EmitIL(method));
                }

                var methodDefinitionIL = GetMethodIL(method.GetTypicalMethodDefinition());
                if (methodDefinitionIL == null)
                {
                    return(null);
                }
                return(new InstantiatedMethodIL(method, methodDefinitionIL, method.OwningType.Instantiation, method.Instantiation));
            }
            else
            if (method is ILStubMethod)
            {
                return(((ILStubMethod)method).EmitIL());
            }
            else
            if (method is ArrayMethod)
            {
                return(ArrayMethodILEmitter.EmitIL((ArrayMethod)method));
            }
            else
            {
                Debug.Assert(!(method is PInvokeTargetNativeMethod), "Who is asking for IL of PInvokeTargetNativeMethod?");
                return(null);
            }
        }
コード例 #2
0
ファイル: ILProvider.cs プロジェクト: gitchomik/corert
        private MethodIL CreateMethodIL(MethodDesc method)
        {
            if (method is EcmaMethod)
            {
                // TODO: Workaround: we should special case methods with Intrinsic attribute, but since
                //       CoreLib source is still not in the repo, we have to work with what we have, which is
                //       an MCG attribute on the type itself...
                if (((MetadataType)method.OwningType).HasCustomAttribute("System.Runtime.InteropServices", "McgIntrinsicsAttribute"))
                {
                    var name = method.Name;
                    if (name == "Call")
                    {
                        return(CalliIntrinsic.EmitIL(method));
                    }
                    else
                    if (name == "AddrOf")
                    {
                        return(AddrOfIntrinsic.EmitIL(method));
                    }
                }

                if (method.IsIntrinsic)
                {
                    MethodIL result = TryGetIntrinsicMethodIL(method);
                    if (result != null)
                    {
                        return(result);
                    }
                }

                if (method.IsPInvoke)
                {
                    var pregenerated = McgInteropSupport.TryGetPregeneratedPInvoke(method);
                    if (pregenerated == null)
                    {
                        return(PInvokeMarshallingILEmitter.EmitIL(method));
                    }
                    method = pregenerated;
                }

                return(EcmaMethodIL.Create((EcmaMethod)method));
            }
            else
            if (method is MethodForInstantiatedType)
            {
                var methodDefinitionIL = GetMethodIL(method.GetTypicalMethodDefinition());
                if (methodDefinitionIL == null)
                {
                    return(null);
                }
                return(new InstantiatedMethodIL(methodDefinitionIL, method.OwningType.Instantiation, new Instantiation()));
            }
            else
            if (method is InstantiatedMethod)
            {
                var methodDefinitionIL = GetMethodIL(method.GetMethodDefinition());
                if (methodDefinitionIL == null)
                {
                    return(null);
                }
                return(new InstantiatedMethodIL(methodDefinitionIL, new Instantiation(), method.Instantiation));
            }
            else
            if (method is ILStubMethod)
            {
                return(((ILStubMethod)method).EmitIL());
            }
            else
            if (method is ArrayMethod)
            {
                return(ArrayMethodILEmitter.EmitIL((ArrayMethod)method));
            }
            else
            {
                return(null);
            }
        }