public bool Equals(SignatureContext other) { return(GlobalContext == other.GlobalContext && LocalContext == other.LocalContext); }
public TypeFixupSignature(ReadyToRunFixupKind fixupKind, TypeDesc typeDesc, SignatureContext signatureContext) { _fixupKind = fixupKind; _typeDesc = typeDesc; _signatureContext = signatureContext; }
private void EmitMethodSpecificationSignature(MethodWithToken method, uint flags, bool enforceDefEncoding, SignatureContext context) { ModuleToken methodToken = method.Token; if (method.Method.HasInstantiation) { flags |= (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_MethodInstantiation; if (!method.Token.IsNull) { if (method.Token.TokenType == CorTokenType.mdtMethodSpec) { MethodSpecification methodSpecification = methodToken.MetadataReader.GetMethodSpecification((MethodSpecificationHandle)methodToken.Handle); methodToken = new ModuleToken(methodToken.Module, methodSpecification.Method); } } } if (methodToken.IsNull && !enforceDefEncoding) { methodToken = context.GetModuleTokenForMethod(method.Method, throwIfNotFound: false); } if (methodToken.IsNull) { flags |= (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_OwnerType; methodToken = context.GetModuleTokenForMethod(method.Method); } if (method.Method.OwningType.HasInstantiation) { // resolveToken currently resolves the token in the context of a given scope; // in such case, we receive a method on instantiated type along with the // generic definition token. flags |= (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_OwnerType; } switch (methodToken.TokenType) { case CorTokenType.mdtMethodDef: break; case CorTokenType.mdtMemberRef: flags |= (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_MemberRefToken; break; default: throw new NotImplementedException(); } EmitUInt(flags); if ((flags & (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_OwnerType) != 0) { EmitTypeSignature(method.Method.OwningType, context); } EmitTokenRid(methodToken.Token); if ((flags & (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_MethodInstantiation) != 0) { Instantiation instantiation = method.Method.Instantiation; EmitUInt((uint)instantiation.Length); for (int typeParamIndex = 0; typeParamIndex < instantiation.Length; typeParamIndex++) { EmitTypeSignature(instantiation[typeParamIndex], context); } } }
public SignatureContext EmitFixup(ReadyToRunCodegenNodeFactory factory, ReadyToRunFixupKind fixupKind, EcmaModule targetModule, SignatureContext outerContext) { if (targetModule == outerContext.LocalContext) { EmitByte((byte)fixupKind); return(outerContext); } else { EmitByte((byte)(fixupKind | ReadyToRunFixupKind.ModuleOverride)); EmitUInt((uint)factory.ManifestMetadataTable.ModuleToIndex(targetModule)); return(outerContext.InnerContext(targetModule)); } }
public FieldFixupSignature(ReadyToRunFixupKind fixupKind, FieldDesc fieldDesc, SignatureContext signatureContext) { _fixupKind = fixupKind; _fieldDesc = fieldDesc; _signatureContext = signatureContext; // Ensure types in signature are loadable and resolvable, otherwise we'll fail later while emitting the signature signatureContext.Resolver.CompilerContext.EnsureLoadableType(fieldDesc.OwningType); }
public void EmitMethodSignature( MethodWithToken method, bool enforceDefEncoding, bool enforceOwningType, SignatureContext context, bool isUnboxingStub, bool isInstantiatingStub) { uint flags = 0; if (isUnboxingStub) { flags |= (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_UnboxingStub; } if (isInstantiatingStub) { flags |= (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_InstantiatingStub; } if (method.ConstrainedType != null) { flags |= (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_Constrained; } if (enforceOwningType) { flags |= (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_OwnerType; } if ((method.Method.HasInstantiation || method.Method.OwningType.HasInstantiation) && !method.Method.IsGenericMethodDefinition) { EmitMethodSpecificationSignature(method, flags, enforceDefEncoding, context); } else { switch (method.Token.TokenType) { case CorTokenType.mdtMethodDef: { EmitUInt(flags); if ((flags & (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_OwnerType) != 0) { EmitTypeSignature(method.Method.OwningType, context); } EmitMethodDefToken(method.Token); } break; case CorTokenType.mdtMemberRef: { flags |= (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_MemberRefToken; MemberReference memberRef = method.Token.MetadataReader.GetMemberReference((MemberReferenceHandle)method.Token.Handle); if (method.Token.Module.GetObject(memberRef.Parent) != (object)method.Method.OwningType) { // We have a memberref token for a different type - encode owning type explicitly in the signature flags |= (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_OwnerType; } EmitUInt(flags); if ((flags & (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_OwnerType) != 0) { EmitTypeSignature(method.Method.OwningType, context); } EmitMethodRefToken(method.Token); } break; default: throw new NotImplementedException(); } } if (method.ConstrainedType != null) { EmitTypeSignature(method.ConstrainedType, context); } }
private void EmitPointerTypeSignature(PointerType type, SignatureContext context) { EmitElementType(CorElementType.ELEMENT_TYPE_PTR); EmitTypeSignature(type.ParameterType, context); }
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 && !_method.Method.OwningType.IsArray) { if (_method.Token.TokenType == CorTokenType.mdtMethodDef) { fixupKind = ReadyToRunFixupKind.READYTORUN_FIXUP_MethodEntry_DefToken; optimized = true; } else if (_method.Token.TokenType == CorTokenType.mdtMemberRef) { fixupKind = ReadyToRunFixupKind.READYTORUN_FIXUP_MethodEntry_RefToken; optimized = true; } } } MethodWithToken method = _method; if (factory.CompilationModuleGroup.VersionsWithMethodBody(method.Method)) { if (method.Token.TokenType == CorTokenType.mdtMethodSpec) { method = new MethodWithToken(method.Method, _signatureContext.GetModuleTokenForMethod(method.Method, throwIfNotFound: false), method.ConstrainedType); } else if (!optimized && (method.Token.TokenType == CorTokenType.mdtMemberRef)) { if (method.Method.OwningType.GetTypeDefinition() is EcmaType) { method = new MethodWithToken(method.Method, _signatureContext.GetModuleTokenForMethod(method.Method, throwIfNotFound: false), method.ConstrainedType); } } } 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()); }
public void EmitTypeSignature(TypeDesc typeDesc, SignatureContext context) { if (typeDesc is RuntimeDeterminedType runtimeDeterminedType) { switch (runtimeDeterminedType.RuntimeDeterminedDetailsType.Kind) { case GenericParameterKind.Type: EmitElementType(CorElementType.ELEMENT_TYPE_VAR); break; case GenericParameterKind.Method: EmitElementType(CorElementType.ELEMENT_TYPE_MVAR); break; default: throw new NotImplementedException(); } EmitUInt((uint)runtimeDeterminedType.RuntimeDeterminedDetailsType.Index); return; } if (typeDesc.HasInstantiation && !typeDesc.IsGenericDefinition) { EmitInstantiatedTypeSignature((InstantiatedType)typeDesc, context); return; } switch (typeDesc.Category) { case TypeFlags.Array: EmitArrayTypeSignature((ArrayType)typeDesc, context); return; case TypeFlags.SzArray: EmitSzArrayTypeSignature((ArrayType)typeDesc, context); return; case TypeFlags.Pointer: EmitPointerTypeSignature((PointerType)typeDesc, context); return; case TypeFlags.ByRef: EmitByRefTypeSignature((ByRefType)typeDesc, context); break; case TypeFlags.Void: EmitElementType(CorElementType.ELEMENT_TYPE_VOID); return; case TypeFlags.Boolean: EmitElementType(CorElementType.ELEMENT_TYPE_BOOLEAN); return; case TypeFlags.Char: EmitElementType(CorElementType.ELEMENT_TYPE_CHAR); return; case TypeFlags.SByte: EmitElementType(CorElementType.ELEMENT_TYPE_I1); return; case TypeFlags.Byte: EmitElementType(CorElementType.ELEMENT_TYPE_U1); return; case TypeFlags.Int16: EmitElementType(CorElementType.ELEMENT_TYPE_I2); return; case TypeFlags.UInt16: EmitElementType(CorElementType.ELEMENT_TYPE_U2); return; case TypeFlags.Int32: EmitElementType(CorElementType.ELEMENT_TYPE_I4); return; case TypeFlags.UInt32: EmitElementType(CorElementType.ELEMENT_TYPE_U4); return; case TypeFlags.Int64: EmitElementType(CorElementType.ELEMENT_TYPE_I8); return; case TypeFlags.UInt64: EmitElementType(CorElementType.ELEMENT_TYPE_U8); return; case TypeFlags.IntPtr: EmitElementType(CorElementType.ELEMENT_TYPE_I); return; case TypeFlags.UIntPtr: EmitElementType(CorElementType.ELEMENT_TYPE_U); return; case TypeFlags.Single: EmitElementType(CorElementType.ELEMENT_TYPE_R4); return; case TypeFlags.Double: EmitElementType(CorElementType.ELEMENT_TYPE_R8); return; case TypeFlags.Interface: case TypeFlags.Class: if (typeDesc.IsString) { EmitElementType(CorElementType.ELEMENT_TYPE_STRING); } else if (typeDesc.IsObject) { EmitElementType(CorElementType.ELEMENT_TYPE_OBJECT); } else if (typeDesc.IsCanonicalDefinitionType(CanonicalFormKind.Specific)) { EmitElementType(CorElementType.ELEMENT_TYPE_CANON_ZAPSIG); } else { ModuleToken token = context.GetModuleTokenForType((EcmaType)typeDesc); EmitModuleOverride(token.Module, context); EmitElementType(CorElementType.ELEMENT_TYPE_CLASS); EmitToken(token.Token); } return; case TypeFlags.ValueType: case TypeFlags.Nullable: case TypeFlags.Enum: { ModuleToken token = context.GetModuleTokenForType((EcmaType)typeDesc); EmitModuleOverride(token.Module, context); EmitElementType(CorElementType.ELEMENT_TYPE_VALUETYPE); EmitToken(token.Token); return; } default: throw new NotImplementedException(); } }
private void EmitTypeToken(EcmaType type, SignatureContext context) { ModuleToken token = context.GetModuleTokenForType(type); EmitToken(token.Token); }
private void EmitMethodSpecificationSignature(MethodWithToken method, uint flags, bool enforceDefEncoding, bool enforceOwningType, SignatureContext context) { ModuleToken methodToken = method.Token; if (method.Method.HasInstantiation && !method.Method.IsGenericMethodDefinition) { flags |= (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_MethodInstantiation; if (!method.Token.IsNull) { if (method.Token.TokenType == CorTokenType.mdtMethodSpec) { MethodSpecification methodSpecification = methodToken.MetadataReader.GetMethodSpecification((MethodSpecificationHandle)methodToken.Handle); methodToken = new ModuleToken(methodToken.Module, methodSpecification.Method); } } } Debug.Assert(!methodToken.IsNull); switch (methodToken.TokenType) { case CorTokenType.mdtMethodDef: break; case CorTokenType.mdtMemberRef: flags |= (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_MemberRefToken; break; default: throw new NotImplementedException(); } if ((method.Token.Module != context.LocalContext) && (!enforceOwningType || (enforceDefEncoding && methodToken.TokenType == CorTokenType.mdtMemberRef))) { // If enforeOwningType is set, this is an entry for the InstanceEntryPoint or InstrumentationDataTable nodes // which are not used in quite the same way, and for which the MethodDef is always matched to the module // which defines the type flags |= (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_UpdateContext; } EmitUInt(flags); if ((flags & (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_UpdateContext) != 0) { uint moduleIndex = (uint)context.Resolver.GetModuleIndex(method.Token.Module); EmitUInt(moduleIndex); context = context.InnerContext(method.Token.Module); } if ((flags & (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_OwnerType) != 0) { // The type here should be the type referred to by the memberref (if this is one, not the type where the method was eventually found! EmitTypeSignature(method.OwningType, context); } EmitTokenRid(methodToken.Token); if ((flags & (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_MethodInstantiation) != 0) { Instantiation instantiation = method.Method.Instantiation; EmitUInt((uint)instantiation.Length); SignatureContext methodInstantiationsContext; if ((flags & (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_UpdateContext) != 0) { methodInstantiationsContext = context; } else { methodInstantiationsContext = context.OuterContext; } for (int typeParamIndex = 0; typeParamIndex < instantiation.Length; typeParamIndex++) { EmitTypeSignature(instantiation[typeParamIndex], methodInstantiationsContext); } } }
public MethodWithGCInfo(MethodDesc methodDesc, SignatureContext signatureContext) { GCInfoNode = new MethodGCInfoNode(this); _method = methodDesc; SignatureContext = signatureContext; }
public FieldFixupSignature(ReadyToRunFixupKind fixupKind, FieldDesc fieldDesc, SignatureContext signatureContext) { _fixupKind = fixupKind; _fieldDesc = fieldDesc; _signatureContext = signatureContext; }
public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false) { if (relocsOnly) { return(new ObjectData(Array.Empty <byte>(), null, 1, null)); } // Determine the need for module override EcmaModule targetModule; if (_methodArgument != null) { targetModule = _methodArgument.Token.Module; } else if (_typeArgument != null) { targetModule = factory.SignatureContext.GetTargetModule(_typeArgument); } else if (_fieldArgument != null) { targetModule = factory.SignatureContext.GetTargetModule(_fieldArgument); } else { throw new NotImplementedException(); } ReadyToRunFixupKind fixupToEmit; TypeDesc contextTypeToEmit = null; switch (_runtimeLookupKind) { case CORINFO_RUNTIME_LOOKUP_KIND.CORINFO_LOOKUP_CLASSPARAM: fixupToEmit = ReadyToRunFixupKind.TypeDictionaryLookup; break; case CORINFO_RUNTIME_LOOKUP_KIND.CORINFO_LOOKUP_METHODPARAM: fixupToEmit = ReadyToRunFixupKind.MethodDictionaryLookup; break; case CORINFO_RUNTIME_LOOKUP_KIND.CORINFO_LOOKUP_THISOBJ: fixupToEmit = ReadyToRunFixupKind.ThisObjDictionaryLookup; contextTypeToEmit = _methodContext.ContextType; break; default: throw new NotImplementedException(); } ObjectDataSignatureBuilder dataBuilder = new ObjectDataSignatureBuilder(); dataBuilder.AddSymbol(this); SignatureContext innerContext = dataBuilder.EmitFixup(factory, fixupToEmit, targetModule, factory.SignatureContext); if (contextTypeToEmit != null) { dataBuilder.EmitTypeSignature(contextTypeToEmit, innerContext); } dataBuilder.EmitByte((byte)_fixupKind); if (_methodArgument != null) { Debug.Assert(_methodArgument.Unboxing == false); dataBuilder.EmitMethodSignature( _methodArgument, enforceDefEncoding: false, enforceOwningType: false, context: innerContext, 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()); }
private void EmitByRefTypeSignature(ByRefType type, SignatureContext context) { EmitElementType(CorElementType.ELEMENT_TYPE_BYREF); EmitTypeSignature(type.ParameterType, context); }
public NewArrayFixupSignature(ArrayType arrayType, SignatureContext signatureContext) { _arrayType = arrayType; _signatureContext = signatureContext; }
private void EmitSzArrayTypeSignature(ArrayType type, SignatureContext context) { Debug.Assert(type.IsSzArray); EmitElementType(CorElementType.ELEMENT_TYPE_SZARRAY); EmitTypeSignature(type.ElementType, context); }
public StringImport(ImportSectionNode table, ModuleToken token, SignatureContext signatureContext) : base(table, new StringImportSignature(token, signatureContext)) { _token = token; }
public void EmitMethodSignature( MethodWithToken method, bool enforceDefEncoding, bool enforceOwningType, SignatureContext context, bool isInstantiatingStub) { uint flags = 0; if (method.Unboxing) { flags |= (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_UnboxingStub; } if (isInstantiatingStub) { flags |= (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_InstantiatingStub; } if (method.ConstrainedType != null) { flags |= (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_Constrained; } if (enforceOwningType) { flags |= (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_OwnerType; } if ((method.Method.HasInstantiation || method.Method.OwningType.HasInstantiation) && !method.Method.IsGenericMethodDefinition) { EmitMethodSpecificationSignature(method, flags, enforceDefEncoding, context); } else { switch (method.Token.TokenType) { case CorTokenType.mdtMethodDef: { EmitUInt(flags); if ((flags & (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_OwnerType) != 0) { EmitTypeSignature(method.Method.OwningType, context); } EmitMethodDefToken(method.Token); } break; case CorTokenType.mdtMemberRef: { flags |= (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_MemberRefToken; // Owner type is needed for type specs to instantiating stubs or generics with signature variables still present if (!method.Method.OwningType.IsDefType && ((flags & (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_InstantiatingStub) != 0 || method.Method.OwningType.ContainsSignatureVariables())) { flags |= (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_OwnerType; } else if (method.Method.IsArrayMethod()) { var memberRefMethod = method.Token.Module.GetMethod(MetadataTokens.EntityHandle((int)method.Token.Token)); if (memberRefMethod.OwningType != method.Method.OwningType) { flags |= (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_OwnerType; } } EmitUInt(flags); if ((flags & (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_OwnerType) != 0) { EmitTypeSignature(method.Method.OwningType, context); } EmitMethodRefToken(method.Token); } break; default: throw new NotImplementedException(); } } if (method.ConstrainedType != null) { EmitTypeSignature(method.ConstrainedType, context); } }