Esempio n. 1
0
        public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false)
        {
            ObjectDataSignatureBuilder dataBuilder = new ObjectDataSignatureBuilder();

            if (!relocsOnly)
            {
                dataBuilder.AddSymbol(this);

                EcmaModule       targetModule = factory.SignatureContext.GetTargetModule(_fieldDesc);
                SignatureContext innerContext = dataBuilder.EmitFixup(factory, _fixupKind, targetModule, factory.SignatureContext);

                if (_fixupKind == ReadyToRunFixupKind.Verify_FieldOffset)
                {
                    TypeDesc baseType = _fieldDesc.OwningType.BaseType;
                    if ((_fieldDesc.OwningType.BaseType != null) && !_fieldDesc.IsStatic && !_fieldDesc.OwningType.IsValueType)
                    {
                        dataBuilder.EmitUInt((uint)_fieldDesc.OwningType.FieldBaseOffset().AsInt);
                    }
                    else
                    {
                        dataBuilder.EmitUInt(0);
                    }
                }

                if ((_fixupKind == ReadyToRunFixupKind.Check_FieldOffset) ||
                    (_fixupKind == ReadyToRunFixupKind.Verify_FieldOffset))
                {
                    dataBuilder.EmitUInt((uint)_fieldDesc.Offset.AsInt);
                }

                dataBuilder.EmitFieldSignature(_fieldDesc, innerContext);
            }

            return(dataBuilder.ToObjectData());
        }
Esempio n. 2
0
        public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false)
        {
            ObjectDataSignatureBuilder dataBuilder = new ObjectDataSignatureBuilder();

            if (!relocsOnly)
            {
                dataBuilder.AddSymbol(this);

                ModuleToken moduleToken = GetModuleToken(factory);

                IEcmaModule      targetModule = moduleToken.Module;
                SignatureContext innerContext = dataBuilder.EmitFixup(factory, _fixupKind, targetModule, factory.SignatureContext);

                var metadata = ReadyToRunStandaloneMethodMetadata.Compute(_method);
                dataBuilder.EmitUInt(checked ((uint)metadata.ConstantData.Length));
                dataBuilder.EmitBytes(metadata.ConstantData);
                dataBuilder.EmitUInt(checked ((uint)metadata.TypeRefs.Length));
                foreach (var typeRef in metadata.TypeRefs)
                {
                    if (factory.SignatureContext.Resolver.GetModuleTokenForType((EcmaType)typeRef, allowDynamicallyCreatedReference: true, throwIfNotFound: false).Module == null)
                    {
                        // If there isn't a module token yet for this type, force it to exist
                        factory.ManifestMetadataTable._mutableModule.TryGetEntityHandle(typeRef);
                    }
                    dataBuilder.EmitTypeSignature(typeRef, innerContext);
                }

                MethodWithToken method = new MethodWithToken(_method, moduleToken, null, unboxing: false, context: null);
                dataBuilder.EmitMethodSignature(method, enforceDefEncoding: false, enforceOwningType: false, innerContext, false);
            }

            return(dataBuilder.ToObjectData());
        }
Esempio n. 3
0
        public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false)
        {
            ReadyToRunCodegenNodeFactory r2rFactory = (ReadyToRunCodegenNodeFactory)factory;
            ObjectDataSignatureBuilder   builder    = new ObjectDataSignatureBuilder();

            builder.AddSymbol(this);

            if (!relocsOnly)
            {
                SignatureContext innerContext = builder.EmitFixup(r2rFactory, ReadyToRunFixupKind.READYTORUN_FIXUP_DelegateCtor, _methodToken.Module, _signatureContext);

                builder.EmitMethodSignature(
                    _targetMethod.Method,
                    constrainedType: null,
                    methodToken: _methodToken,
                    enforceDefEncoding: false,
                    innerContext,
                    isUnboxingStub: false,
                    isInstantiatingStub: false);

                builder.EmitTypeSignature(_delegateType, innerContext);
            }

            return(builder.ToObjectData());
        }
        public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false)
        {
            ObjectDataSignatureBuilder builder = new ObjectDataSignatureBuilder();

            builder.AddSymbol(this);

            string[] supportedAndUnsupportedSplit = _instructionSetsSupport.Split(',');

            string[] instructionSetsSupported             = supportedAndUnsupportedSplit[0] == "" ? Array.Empty <string>() : supportedAndUnsupportedSplit[0].Split('+');
            string[] instructionSetsExplicitlyUnsupported = supportedAndUnsupportedSplit[1] == "" ? Array.Empty <string>() : supportedAndUnsupportedSplit[1].Split('-');

            // This type of fixup is not dependent on module
            builder.EmitByte(checked ((byte)ReadyToRunFixupKind.Check_InstructionSetSupport));

            builder.EmitUInt((uint)(instructionSetsSupported.Length + instructionSetsExplicitlyUnsupported.Length));

            foreach (string instructionSetString in instructionSetsSupported)
            {
                uint valueToEmit = (((uint)InstructionSetFromString(instructionSetString)) << 1) | 1;
                builder.EmitUInt(valueToEmit);
            }

            foreach (string instructionSetString in instructionSetsExplicitlyUnsupported)
            {
                uint valueToEmit = (((uint)InstructionSetFromString(instructionSetString)) << 1) | 0;
                builder.EmitUInt(valueToEmit);
            }

            return(builder.ToObjectData());
        }
        public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false)
        {
            ObjectDataSignatureBuilder builder = new ObjectDataSignatureBuilder();

            builder.AddSymbol(this);
            builder.EmitByte((byte)ReadyToRunFixupKind.Helper);
            builder.EmitUInt((uint)_helperID);
            return(builder.ToObjectData());
        }
        public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false)
        {
            ReadyToRunCodegenNodeFactory r2rFactory  = (ReadyToRunCodegenNodeFactory)factory;
            ObjectDataSignatureBuilder   dataBuilder = new ObjectDataSignatureBuilder();

            if (!relocsOnly)
            {
                dataBuilder.AddSymbol(this);

                switch (_runtimeLookupKind)
                {
                case CORINFO_RUNTIME_LOOKUP_KIND.CORINFO_LOOKUP_CLASSPARAM:
                    dataBuilder.EmitByte((byte)ReadyToRunFixupKind.READYTORUN_FIXUP_TypeDictionaryLookup);
                    break;

                case CORINFO_RUNTIME_LOOKUP_KIND.CORINFO_LOOKUP_METHODPARAM:
                    dataBuilder.EmitByte((byte)ReadyToRunFixupKind.READYTORUN_FIXUP_MethodDictionaryLookup);
                    break;

                case CORINFO_RUNTIME_LOOKUP_KIND.CORINFO_LOOKUP_THISOBJ:
                    dataBuilder.EmitByte((byte)ReadyToRunFixupKind.READYTORUN_FIXUP_ThisObjDictionaryLookup);
                    dataBuilder.EmitTypeSignature(_methodContext.ContextType, _signatureContext);
                    break;

                default:
                    throw new NotImplementedException();
                }

                dataBuilder.EmitByte((byte)_fixupKind);
                if (_typeArgument != null)
                {
                    dataBuilder.EmitTypeSignature(_typeArgument, _signatureContext);
                }
                else if (_methodArgument != null)
                {
                    dataBuilder.EmitMethodSignature(
                        method: _methodArgument.Method,
                        constrainedType: null,
                        methodToken: _methodArgument.Token,
                        enforceDefEncoding: false,
                        context: _signatureContext,
                        isUnboxingStub: false,
                        isInstantiatingStub: true);
                }
                else if (_fieldArgument != null)
                {
                    dataBuilder.EmitFieldSignature(_fieldArgument, _signatureContext);
                }
                else
                {
                    throw new NotImplementedException();
                }
            }

            return(dataBuilder.ToObjectData());
        }
Esempio n. 7
0
        public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false)
        {
            ReadyToRunCodegenNodeFactory r2rFactory  = (ReadyToRunCodegenNodeFactory)factory;
            ObjectDataSignatureBuilder   dataBuilder = new ObjectDataSignatureBuilder();

            dataBuilder.AddSymbol(this);

            dataBuilder.EmitFixup(r2rFactory, ReadyToRunFixupKind.READYTORUN_FIXUP_StringHandle, _token.Module, _signatureContext);
            dataBuilder.EmitUInt(_token.TokenRid);

            return(dataBuilder.ToObjectData());
        }
        public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false)
        {
            ReadyToRunCodegenNodeFactory r2rFactory  = (ReadyToRunCodegenNodeFactory)factory;
            ObjectDataSignatureBuilder   dataBuilder = new ObjectDataSignatureBuilder();

            dataBuilder.AddSymbol(this);

            dataBuilder.EmitByte((byte)ReadyToRunFixupKind.READYTORUN_FIXUP_NewArray);
            dataBuilder.EmitTypeSignature(_arrayType, _signatureContext);

            return(dataBuilder.ToObjectData());
        }
Esempio n. 9
0
        public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false)
        {
            ReadyToRunCodegenNodeFactory r2rFactory  = (ReadyToRunCodegenNodeFactory)factory;
            ObjectDataSignatureBuilder   dataBuilder = new ObjectDataSignatureBuilder();

            dataBuilder.AddSymbol(this);

            // TODO: module override for external module strings
            dataBuilder.EmitByte((byte)ReadyToRunFixupKind.READYTORUN_FIXUP_StringHandle);
            dataBuilder.EmitUInt(_token.TokenRid);

            return(dataBuilder.ToObjectData());
        }
Esempio n. 10
0
        public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false)
        {
            if (relocsOnly)
            {
                // Method fixup signature doesn't contain any direct relocs
                return(new ObjectData(data: Array.Empty <byte>(), relocs: null, alignment: 0, definedSymbols: null));
            }

            ReadyToRunCodegenNodeFactory r2rFactory  = (ReadyToRunCodegenNodeFactory)factory;
            ObjectDataSignatureBuilder   dataBuilder = new ObjectDataSignatureBuilder();

            dataBuilder.AddSymbol(this);

            // Optimize some of the fixups into a more compact form
            ReadyToRunFixupKind fixupKind = _fixupKind;
            bool optimized = false;

            if (!_isUnboxingStub && !_isInstantiatingStub && _method.ConstrainedType == null &&
                fixupKind == ReadyToRunFixupKind.READYTORUN_FIXUP_MethodEntry)
            {
                if (!_method.Method.OwningType.HasInstantiation)
                {
                    if (_method.Token.TokenType == CorTokenType.mdtMethodDef)
                    {
                        fixupKind = ReadyToRunFixupKind.READYTORUN_FIXUP_MethodEntry_DefToken;
                    }
                    else if (_method.Token.TokenType == CorTokenType.mdtMemberRef)
                    {
                        fixupKind = ReadyToRunFixupKind.READYTORUN_FIXUP_MethodEntry_RefToken;
                    }
                    optimized = true;
                }
            }

            SignatureContext innerContext = dataBuilder.EmitFixup(r2rFactory, fixupKind, _method.Token.Module, _signatureContext);

            if (optimized && _method.Token.TokenType == CorTokenType.mdtMethodDef)
            {
                dataBuilder.EmitMethodDefToken(_method.Token);
            }
            else if (optimized && _method.Token.TokenType == CorTokenType.mdtMemberRef)
            {
                dataBuilder.EmitMethodRefToken(_method.Token);
            }
            else
            {
                dataBuilder.EmitMethodSignature(_method, enforceDefEncoding: false, enforceOwningType: false, innerContext, _isUnboxingStub, _isInstantiatingStub);
            }

            return(dataBuilder.ToObjectData());
        }
Esempio n. 11
0
        public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false)
        {
            ObjectDataSignatureBuilder dataBuilder = new ObjectDataSignatureBuilder();

            if (!relocsOnly)
            {
                dataBuilder.AddSymbol(this);

                dataBuilder.EmitFixup(factory, ReadyToRunFixupKind.StringHandle, _token.Module, _signatureContext);
                dataBuilder.EmitUInt(_token.TokenRid);
            }

            return(dataBuilder.ToObjectData());
        }
Esempio n. 12
0
        public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false)
        {
            ReadyToRunCodegenNodeFactory r2rFactory  = (ReadyToRunCodegenNodeFactory)factory;
            ObjectDataSignatureBuilder   dataBuilder = new ObjectDataSignatureBuilder();

            dataBuilder.AddSymbol(this);

            EcmaModule       targetModule = _signatureContext.GetTargetModule(_arrayType);
            SignatureContext innerContext = dataBuilder.EmitFixup(r2rFactory, ReadyToRunFixupKind.READYTORUN_FIXUP_NewArray, targetModule, _signatureContext);

            dataBuilder.EmitTypeSignature(_arrayType, innerContext);

            return(dataBuilder.ToObjectData());
        }
Esempio n. 13
0
        public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false)
        {
            ObjectDataSignatureBuilder dataBuilder = new ObjectDataSignatureBuilder();

            if (!relocsOnly)
            {
                dataBuilder.AddSymbol(this);

                EcmaModule       targetModule = factory.SignatureContext.GetTargetModule(_typeDesc);
                SignatureContext innerContext = dataBuilder.EmitFixup(factory, _fixupKind, targetModule, factory.SignatureContext);
                dataBuilder.EmitTypeSignature(_typeDesc, innerContext);
            }

            return(dataBuilder.ToObjectData());
        }
Esempio n. 14
0
        public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false)
        {
            ReadyToRunCodegenNodeFactory r2rFactory  = (ReadyToRunCodegenNodeFactory)factory;
            ObjectDataSignatureBuilder   dataBuilder = new ObjectDataSignatureBuilder();

            if (!relocsOnly)
            {
                dataBuilder.AddSymbol(this);

                dataBuilder.EmitByte((byte)_fixupKind);
                dataBuilder.EmitFieldSignature(_fieldDesc, _signatureContext);
            }

            return(dataBuilder.ToObjectData());
        }
Esempio n. 15
0
        public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false)
        {
            ObjectDataSignatureBuilder dataBuilder = new ObjectDataSignatureBuilder();

            if (!relocsOnly)
            {
                dataBuilder.AddSymbol(this);

                EcmaModule       targetModule = _signatureContext.GetTargetModule(_arrayType);
                SignatureContext innerContext = dataBuilder.EmitFixup(factory, ReadyToRunFixupKind.NewArray, targetModule, _signatureContext);
                dataBuilder.EmitTypeSignature(_arrayType, innerContext);
            }

            return(dataBuilder.ToObjectData());
        }
Esempio n. 16
0
        public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false)
        {
            ReadyToRunCodegenNodeFactory r2rFactory  = (ReadyToRunCodegenNodeFactory)factory;
            ObjectDataSignatureBuilder   dataBuilder = new ObjectDataSignatureBuilder();

            if (!relocsOnly)
            {
                dataBuilder.AddSymbol(this);

                EcmaModule       targetModule = _signatureContext.GetTargetModule(_typeDesc);
                SignatureContext innerContext = dataBuilder.EmitFixup(r2rFactory, ReadyToRunFixupKind.NewObject, targetModule, _signatureContext);
                dataBuilder.EmitTypeSignature(_typeDesc, innerContext);
            }

            return(dataBuilder.ToObjectData());
        }
Esempio n. 17
0
        public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false)
        {
            if (relocsOnly)
            {
                // Method fixup signature doesn't contain any direct relocs
                return(new ObjectData(data: Array.Empty <byte>(), relocs: null, alignment: 0, definedSymbols: null));
            }

            ReadyToRunCodegenNodeFactory r2rFactory  = (ReadyToRunCodegenNodeFactory)factory;
            ObjectDataSignatureBuilder   dataBuilder = new ObjectDataSignatureBuilder();

            dataBuilder.AddSymbol(this);
            SignatureContext innerContext = dataBuilder.EmitFixup(r2rFactory, _fixupKind, _method.Token.Module, _signatureContext);

            dataBuilder.EmitMethodSignature(_method, enforceDefEncoding: false, innerContext, _isUnboxingStub, _isInstantiatingStub);

            return(dataBuilder.ToObjectData());
        }
Esempio n. 18
0
        public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false)
        {
            ObjectDataSignatureBuilder dataBuilder = new ObjectDataSignatureBuilder();

            if (!relocsOnly)
            {
                dataBuilder.AddSymbol(this);

                IEcmaModule      targetModule = _fieldWithToken.Token.Module;
                SignatureContext innerContext = dataBuilder.EmitFixup(factory, _fixupKind, targetModule, factory.SignatureContext);
                uint             baseOffset   = 0;
                uint             fieldOffset  = (uint)_fieldWithToken.Field.Offset.AsInt;

                if (_fixupKind == ReadyToRunFixupKind.Verify_FieldOffset)
                {
                    TypeDesc baseType = _fieldWithToken.Field.OwningType.BaseType;
                    if ((_fieldWithToken.Field.OwningType.BaseType != null) &&
                        !_fieldWithToken.Field.IsStatic &&
                        !_fieldWithToken.Field.OwningType.IsValueType)
                    {
                        MetadataType owningType = (MetadataType)_fieldWithToken.Field.OwningType;
                        baseOffset = (uint)owningType.FieldBaseOffset().AsInt;
                        if (factory.CompilationModuleGroup.NeedsAlignmentBetweenBaseTypeAndDerived((MetadataType)baseType, owningType))
                        {
                            fieldOffset -= baseOffset;
                            baseOffset   = 0;
                        }
                    }
                    dataBuilder.EmitUInt(baseOffset);
                }

                if ((_fixupKind == ReadyToRunFixupKind.Check_FieldOffset) ||
                    (_fixupKind == ReadyToRunFixupKind.Verify_FieldOffset))
                {
                    dataBuilder.EmitUInt(fieldOffset);
                }

                dataBuilder.EmitFieldSignature(_fieldWithToken, innerContext);
            }

            return(dataBuilder.ToObjectData());
        }
        public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false)
        {
            ObjectDataSignatureBuilder dataBuilder = new ObjectDataSignatureBuilder();

            if (!relocsOnly)
            {
                dataBuilder.AddSymbol(this);

                SignatureContext innerContext = dataBuilder.EmitFixup(factory, _fixupKind, _declMethod.Token.Module, factory.SignatureContext);
                dataBuilder.EmitUInt((uint)(_implMethod != null ? ReadyToRunVirtualFunctionOverrideFlags.VirtualFunctionOverridden : ReadyToRunVirtualFunctionOverrideFlags.None));
                dataBuilder.EmitMethodSignature(_declMethod, enforceDefEncoding: false, enforceOwningType: false, innerContext, isInstantiatingStub: false);
                dataBuilder.EmitTypeSignature(_implType, innerContext);
                if (_implMethod != null)
                {
                    dataBuilder.EmitMethodSignature(_implMethod, enforceDefEncoding: false, enforceOwningType: false, innerContext, isInstantiatingStub: false);
                }
            }

            return(dataBuilder.ToObjectData());
        }
Esempio n. 20
0
        public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false)
        {
            ObjectDataSignatureBuilder dataBuilder = new ObjectDataSignatureBuilder();

            if (!relocsOnly)
            {
                dataBuilder.AddSymbol(this);

                EcmaModule       targetModule = factory.SignatureContext.GetTargetModule(_fieldDesc);
                SignatureContext innerContext = dataBuilder.EmitFixup(factory, _fixupKind, targetModule, factory.SignatureContext);

                if (_fixupKind == ReadyToRunFixupKind.Check_FieldOffset)
                {
                    dataBuilder.EmitInt(_fieldDesc.Offset.AsInt);
                }

                dataBuilder.EmitFieldSignature(_fieldDesc, innerContext);
            }

            return(dataBuilder.ToObjectData());
        }
Esempio n. 21
0
        public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false)
        {
            ObjectDataSignatureBuilder dataBuilder = new ObjectDataSignatureBuilder();

            if (!relocsOnly)
            {
                dataBuilder.AddSymbol(this);

                EcmaModule       targetModule = factory.SignatureContext.GetTargetModule(_typeDesc);
                SignatureContext innerContext = dataBuilder.EmitFixup(factory, _fixupKind, targetModule, factory.SignatureContext);
                dataBuilder.EmitTypeSignature(_typeDesc, innerContext);

                if ((_fixupKind == ReadyToRunFixupKind.Check_TypeLayout) ||
                    (_fixupKind == ReadyToRunFixupKind.Verify_TypeLayout))
                {
                    EncodeTypeLayout(dataBuilder, _typeDesc);
                }
            }

            return(dataBuilder.ToObjectData());
        }
Esempio n. 22
0
        public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false)
        {
            ObjectDataSignatureBuilder builder = new ObjectDataSignatureBuilder();

            builder.AddSymbol(this);

            if (!relocsOnly)
            {
                SignatureContext innerContext = builder.EmitFixup(factory, ReadyToRunFixupKind.DelegateCtor, _methodToken.Module, factory.SignatureContext);

                builder.EmitMethodSignature(
                    new MethodWithToken(_targetMethod.Method, _methodToken, constrainedType: null, unboxing: false),
                    enforceDefEncoding: false,
                    enforceOwningType: false,
                    innerContext,
                    isInstantiatingStub: _targetMethod.Method.HasInstantiation);

                builder.EmitTypeSignature(_delegateType, innerContext);
            }

            return(builder.ToObjectData());
        }
Esempio n. 23
0
        public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false)
        {
            if (relocsOnly)
            {
                return(new ObjectData(Array.Empty <byte>(), null, 1, null));
            }

            ReadyToRunCodegenNodeFactory r2rFactory = (ReadyToRunCodegenNodeFactory)factory;

            // Determine the need for module override
            EcmaModule targetModule;

            if (_methodArgument != null)
            {
                targetModule = _methodArgument.Token.Module;
            }
            else if (_typeArgument != null)
            {
                targetModule = _signatureContext.GetTargetModule(_typeArgument);
            }
            else if (_fieldArgument != null)
            {
                targetModule = _signatureContext.GetTargetModule(_fieldArgument);
            }
            else
            {
                throw new NotImplementedException();
            }

            ReadyToRunFixupKind fixupToEmit;
            TypeDesc            contextTypeToEmit = null;

            switch (_runtimeLookupKind)
            {
            case CORINFO_RUNTIME_LOOKUP_KIND.CORINFO_LOOKUP_CLASSPARAM:
                fixupToEmit = ReadyToRunFixupKind.READYTORUN_FIXUP_TypeDictionaryLookup;
                break;

            case CORINFO_RUNTIME_LOOKUP_KIND.CORINFO_LOOKUP_METHODPARAM:
                fixupToEmit = ReadyToRunFixupKind.READYTORUN_FIXUP_MethodDictionaryLookup;
                break;

            case CORINFO_RUNTIME_LOOKUP_KIND.CORINFO_LOOKUP_THISOBJ:
                fixupToEmit       = ReadyToRunFixupKind.READYTORUN_FIXUP_ThisObjDictionaryLookup;
                contextTypeToEmit = _methodContext.ContextType;
                break;

            default:
                throw new NotImplementedException();
            }

            ObjectDataSignatureBuilder dataBuilder = new ObjectDataSignatureBuilder();

            dataBuilder.AddSymbol(this);

            SignatureContext innerContext = dataBuilder.EmitFixup(r2rFactory, fixupToEmit, targetModule, _signatureContext);

            if (contextTypeToEmit != null)
            {
                dataBuilder.EmitTypeSignature(contextTypeToEmit, innerContext);
            }

            dataBuilder.EmitByte((byte)_fixupKind);
            if (_methodArgument != null)
            {
                dataBuilder.EmitMethodSignature(
                    method: _methodArgument.Method,
                    constrainedType: _typeArgument,
                    methodToken: _methodArgument.Token,
                    enforceDefEncoding: false,
                    context: innerContext,
                    isUnboxingStub: false,
                    isInstantiatingStub: true);
            }
            else if (_typeArgument != null)
            {
                dataBuilder.EmitTypeSignature(_typeArgument, innerContext);
            }
            else if (_fieldArgument != null)
            {
                dataBuilder.EmitFieldSignature(_fieldArgument, innerContext);
            }
            else
            {
                throw new NotImplementedException();
            }

            return(dataBuilder.ToObjectData());
        }
Esempio n. 24
0
        public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false)
        {
            if (relocsOnly)
            {
                // Method fixup signature doesn't contain any direct relocs
                return(new ObjectData(data: Array.Empty <byte>(), relocs: null, alignment: 0, definedSymbols: null));
            }

            ObjectDataSignatureBuilder dataBuilder = new ObjectDataSignatureBuilder();

            dataBuilder.AddSymbol(this);

            // Optimize some of the fixups into a more compact form
            ReadyToRunFixupKind fixupKind = _fixupKind;
            bool optimized = false;

            if (!_method.Unboxing && !_isInstantiatingStub && _method.ConstrainedType == null &&
                fixupKind == ReadyToRunFixupKind.MethodEntry)
            {
                if (!_method.Method.HasInstantiation && !_method.Method.OwningType.HasInstantiation && !_method.Method.OwningType.IsArray)
                {
                    if (_method.Token.TokenType == CorTokenType.mdtMethodDef)
                    {
                        fixupKind = ReadyToRunFixupKind.MethodEntry_DefToken;
                        optimized = true;
                    }
                    else if (_method.Token.TokenType == CorTokenType.mdtMemberRef)
                    {
                        if (!_method.OwningTypeNotDerivedFromToken)
                        {
                            fixupKind = ReadyToRunFixupKind.MethodEntry_RefToken;
                            optimized = true;
                        }
                    }
                }
            }

            MethodWithToken method = _method;

            if (factory.CompilationModuleGroup.VersionsWithMethodBody(method.Method))
            {
                if (method.Token.TokenType == CorTokenType.mdtMethodSpec)
                {
                    method = new MethodWithToken(method.Method, factory.SignatureContext.GetModuleTokenForMethod(method.Method, throwIfNotFound: false), method.ConstrainedType, unboxing: _method.Unboxing, null);
                }
                else if (!optimized && (method.Token.TokenType == CorTokenType.mdtMemberRef))
                {
                    if (method.Method.OwningType.GetTypeDefinition() is EcmaType)
                    {
                        method = new MethodWithToken(method.Method, factory.SignatureContext.GetModuleTokenForMethod(method.Method, throwIfNotFound: false), method.ConstrainedType, unboxing: _method.Unboxing, null);
                    }
                }
            }

            SignatureContext innerContext = dataBuilder.EmitFixup(factory, fixupKind, method.Token.Module, factory.SignatureContext);

            if (optimized && method.Token.TokenType == CorTokenType.mdtMethodDef)
            {
                dataBuilder.EmitMethodDefToken(method.Token);
            }
            else if (optimized && method.Token.TokenType == CorTokenType.mdtMemberRef)
            {
                dataBuilder.EmitMethodRefToken(method.Token);
            }
            else
            {
                dataBuilder.EmitMethodSignature(method, enforceDefEncoding: false, enforceOwningType: false, innerContext, _isInstantiatingStub);
            }

            return(dataBuilder.ToObjectData());
        }