示例#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
        public override MethodIL GetMethodIL(MethodDesc method)
        {
            if (method is EcmaMethod 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)ecmaMethod.OwningType).HasCustomAttribute("System.Runtime.InteropServices", "McgIntrinsicsAttribute"))
                {
                    var name = ecmaMethod.Name;
                    if (name == "Call" || name.StartsWith("StdCall"))
                    {
                        return(CalliIntrinsic.EmitIL(ecmaMethod));
                    }
                    else
                    if (name == "AddrOf")
                    {
                        return(AddrOfIntrinsic.EmitIL(ecmaMethod));
                    }
                }

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

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

                // TODO: Remove: Workaround for missing ClearInitLocals transforms in CoreRT CoreLib
                bool clearInitLocals = ecmaMethod.Module == ecmaMethod.Context.SystemModule;

                MethodIL methodIL = EcmaMethodIL.Create(ecmaMethod, clearInitLocals);
                if (methodIL != null)
                {
                    return(methodIL);
                }

                return(null);
            }
            else
            if (method is MethodForInstantiatedType || method is InstantiatedMethod)
            {
                // Intrinsics specialized per instantiation
                if (method.IsIntrinsic)
                {
                    MethodIL methodIL = TryGetPerInstantiationIntrinsicMethodIL(method);
                    if (methodIL != null)
                    {
                        return(methodIL);
                    }
                }

                var methodDefinitionIL = GetMethodIL(method.GetTypicalMethodDefinition());
                if (methodDefinitionIL == null)
                {
                    return(null);
                }
                return(new InstantiatedMethodIL(method, methodDefinitionIL));
            }
            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);
            }
        }
示例#3
0
        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);
            }
        }