private void AddCompilationRootsForMultifileLibrary(EcmaModule module) { foreach (TypeDesc type in module.GetAllTypes()) { // Skip delegates (since their Invoke methods have no IL) and uninstantiated generic types if (type.IsDelegate || type.ContainsGenericVariables) continue; EcmaType ecmaType = type as EcmaType; if (ecmaType.Attributes.HasFlag(System.Reflection.TypeAttributes.Public)) { foreach (EcmaMethod method in ecmaType.GetMethods()) { // Skip methods with no IL and uninstantiated generic methods if (method.IsIntrinsic || method.IsAbstract || method.ContainsGenericVariables) continue; if (method.ImplAttributes.HasFlag(System.Reflection.MethodImplAttributes.InternalCall)) continue; _rootProvider.AddCompilationRoot(method, "Library module method"); } } } }
public AssemblyFeatureInfo(EcmaModule module, IReadOnlyDictionary <string, bool> featureSwitchValues) { Module = module; RemovedAttributes = new HashSet <TypeDesc>(); PEMemoryBlock resourceDirectory = module.PEReader.GetSectionData(module.PEReader.PEHeaders.CorHeader.ResourcesDirectory.RelativeVirtualAddress); foreach (var resourceHandle in module.MetadataReader.ManifestResources) { ManifestResource resource = module.MetadataReader.GetManifestResource(resourceHandle); // Don't try to process linked resources or resources in other assemblies if (!resource.Implementation.IsNil) { continue; } string resourceName = module.MetadataReader.GetString(resource.Name); if (resourceName == "ILLink.LinkAttributes.xml") { BlobReader reader = resourceDirectory.GetReader((int)resource.Offset, resourceDirectory.Length - (int)resource.Offset); int length = (int)reader.ReadUInt32(); UnmanagedMemoryStream ms; unsafe { ms = new UnmanagedMemoryStream(reader.CurrentPointer, length); } RemovedAttributes = LinkAttributesReader.GetRemovedAttributes(module.Context, XmlReader.Create(ms), module, featureSwitchValues); } } }
// TODO // bool _hasModifiers; public EcmaSignatureParser(EcmaModule module, BlobReader reader) { _module = module; _reader = reader; // _hasModifiers = false; }
public StaticFieldLayoutTests() { _context = new TestTypeSystemContext(TargetArchitecture.X64); var systemModule = _context.CreateModuleForSimpleName("CoreTestAssembly"); _context.SetSystemModule(systemModule); _testModule = systemModule; }
public VirtualFunctionOverrideTests() { _context = new TestTypeSystemContext(TargetArchitecture.X64); var systemModule = _context.CreateModuleForSimpleName("CoreTestAssembly"); _context.SetSystemModule(systemModule); _testModule = systemModule; _stringType = _context.GetWellKnownType(WellKnownType.String); _voidType = _context.GetWellKnownType(WellKnownType.Void); }
private void AddCompilationRootsForMultifileLibrary(EcmaModule module, IRootingServiceProvider rootProvider) { foreach (TypeDesc type in module.GetAllTypes()) { // Skip delegates (since their Invoke methods have no IL) and uninstantiated generic types if (type.IsDelegate || type.ContainsGenericVariables) continue; rootProvider.AddCompilationRoot(type, "Library module type"); RootMethods(type, "Library module method", rootProvider); } }
private void AddMainMethodCompilationRoot(EcmaModule module) { if (StartupCodeMain != null) throw new Exception("Multiple entrypoint modules"); int entryPointToken = module.PEReader.PEHeaders.CorHeader.EntryPointTokenOrRelativeVirtualAddress; MethodDesc mainMethod = module.GetMethod(MetadataTokens.EntityHandle(entryPointToken)); var owningType = module.GetGlobalModuleType(); StartupCodeMain = new StartupCodeMainMethod(owningType, mainMethod); _rootProvider.AddCompilationRoot(StartupCodeMain, "Startup Code Main Method", "__managed__Main"); }
protected void AddCompilationRootsForRuntimeExports(EcmaModule module) { foreach (var type in module.GetAllTypes()) { foreach (var method in type.GetMethods()) { if (method.HasCustomAttribute("System.Runtime", "RuntimeExportAttribute")) { string exportName = ((EcmaMethod)method).GetAttributeStringValue("System.Runtime", "RuntimeExportAttribute"); _rootProvider.AddCompilationRoot(method, "Runtime export", exportName); } } } }
internal EcmaType(EcmaModule module, TypeDefinitionHandle handle) { _module = module; _handle = handle; _typeDefinition = module.MetadataReader.GetTypeDefinition(handle); _baseType = this; // Not yet initialized flag #if DEBUG // Initialize name eagerly in debug builds for convenience this.ToString(); #endif }
public void SetSystemModule(EcmaModule systemModule) { _systemModule = systemModule; // Sanity check the name table Debug.Assert(s_wellKnownTypeNames[(int)WellKnownType.MulticastDelegate - 1] == "MulticastDelegate"); // Initialize all well known types - it will save us from checking the name for each loaded type for (int typeIndex = 0; typeIndex < _wellKnownTypes.Length; typeIndex++) { MetadataType type = _systemModule.GetType("System", s_wellKnownTypeNames[typeIndex]); type.SetWellKnownType((WellKnownType)(typeIndex + 1)); _wellKnownTypes[typeIndex] = type; } }
public bool GeneratesMetadata(EcmaModule module, ExportedTypeHandle exportedTypeHandle) { try { // Generate the forwarder only if we generated the target type. // If the target type is in a different compilation group, assume we generated it there. var targetType = (MetadataType)module.GetObject(exportedTypeHandle); return(GeneratesMetadata(targetType) || !_factory.CompilationModuleGroup.ContainsType(targetType)); } catch (TypeSystemException) { // No harm in generating a forwarder that didn't resolve. // We'll get matching behavior at runtime. return(true); } }
public ArchitectureSpecificFieldLayoutTests() { _contextX64 = new TestTypeSystemContext(TargetArchitecture.X64); var systemModuleX64 = _contextX64.CreateModuleForSimpleName("CoreTestAssembly"); _contextX64.SetSystemModule(systemModuleX64); _testModuleX64 = systemModuleX64; _contextARM = new TestTypeSystemContext(TargetArchitecture.ARM); var systemModuleARM = _contextARM.CreateModuleForSimpleName("CoreTestAssembly"); _contextARM.SetSystemModule(systemModuleARM); _testModuleARM = systemModuleARM; _contextX86 = new TestTypeSystemContext(TargetArchitecture.X86); var systemModuleX86 = _contextX86.CreateModuleForSimpleName("CoreTestAssembly"); _contextX86.SetSystemModule(systemModuleX86); _testModuleX86 = systemModuleX86; }
protected void AddCompilationRootsForExports(EcmaModule module) { foreach (var type in module.GetAllTypes()) { foreach (var method in type.GetMethods()) { EcmaMethod ecmaMethod = (EcmaMethod)method; if (ecmaMethod.IsRuntimeExport) { string runtimeExportName = ecmaMethod.GetRuntimeExportName(); if (runtimeExportName != null) _rootProvider.AddCompilationRoot(method, "Runtime export", runtimeExportName); } if (ecmaMethod.IsNativeCallable) { string nativeCallableExportName = ecmaMethod.GetNativeCallableExportName(); if (nativeCallableExportName != null) _rootProvider.AddCompilationRoot(method, "Native callable", nativeCallableExportName); } } } }
internal TypeDesc GetTypeDescFromQHandle(QTypeDefinition qTypeDefinition) { #if ECMA_METADATA_SUPPORT if (qTypeDefinition.IsNativeFormatMetadataBased) #endif { MetadataReader nativeFormatMetadataReader = qTypeDefinition.NativeFormatReader; TypeDefinitionHandle typeDefinitionHandle = qTypeDefinition.NativeFormatHandle; NativeFormatModuleInfo module = ModuleList.Instance.GetModuleInfoForMetadataReader(nativeFormatMetadataReader); NativeFormatMetadataUnit metadataUnit = ResolveMetadataUnit(module); NativeFormatType nativeFormatType = (NativeFormatType)metadataUnit.GetType(typeDefinitionHandle); return(nativeFormatType); } #if ECMA_METADATA_SUPPORT else if (qTypeDefinition.IsEcmaFormatMetadataBased) { EcmaModuleInfo module = ModuleList.Instance.GetModuleInfoForMetadataReader(qTypeDefinition.EcmaFormatReader); Ecma.EcmaModule ecmaModule = ResolveEcmaModule(module); Ecma.EcmaType ecmaType = (Ecma.EcmaType)ecmaModule.GetType(qTypeDefinition.EcmaFormatHandle); return(ecmaType); } #endif return(null); }
private void AddMainMethodCompilationRoot(EcmaModule module, IRootingServiceProvider rootProvider) { if (StartupCodeMain != null) throw new Exception("Multiple entrypoint modules"); MethodDesc mainMethod = module.EntryPoint; if (mainMethod == null) throw new Exception("No managed entrypoint defined for executable module"); var owningType = module.GetGlobalModuleType(); StartupCodeMain = new StartupCodeMainMethod(owningType, mainMethod); rootProvider.AddCompilationRoot(StartupCodeMain, "Startup Code Main Method", "__managed__Main"); }
public EcmaModule CreateModuleForSimpleName(string simpleName) { EcmaModule module = new EcmaModule(this, new PEReader(File.OpenRead(simpleName + ".dll"))); _modules.Add(simpleName, module); return module; }
public CustomAttributeTypeProvider(EcmaModule module) { _module = module; }
public EcmaObjectLookupHashtable(EcmaModule module) { _module = module; }
// TODO // bool _hasModifiers; public EcmaSignatureParser(EcmaModule module, BlobReader reader) { _module = module; _reader = reader; }
public ExportedMethodsRootProvider(EcmaModule module) { _module = module; }
private void AddModule(string simpleName, string filePath, EcmaModule module) { _modules.Add(simpleName, module); ModuleData moduleData = new ModuleData() { Path = filePath }; InitializeSymbolReader(moduleData); _moduleData.Add(module, moduleData); }
private EcmaMethodIL(EcmaModule module, int rva) { _module = module; _methodBody = module.PEReader.GetMethodBody(rva); }
private bool IsModuleInCompilationGroup(EcmaModule module) { return _compilationModuleSet.Contains(module); }
public EcmaModule GetModuleForSimpleName(string simpleName) { EcmaModule existingModule; if (_modules.TryGetValue(simpleName, out existingModule)) return existingModule; string filePath; if (!InputFilePaths.TryGetValue(simpleName, out filePath)) { if (!ReferenceFilePaths.TryGetValue(simpleName, out filePath)) throw new FileNotFoundException("Assembly not found: " + simpleName); } EcmaModule module = new EcmaModule(this, new PEReader(File.OpenRead(filePath))); MetadataReader metadataReader = module.MetadataReader; string actualSimpleName = metadataReader.GetString(metadataReader.GetAssemblyDefinition().Name); if (!actualSimpleName.Equals(simpleName, StringComparison.OrdinalIgnoreCase)) throw new FileNotFoundException("Assembly name does not match filename " + filePath); AddModule(simpleName, filePath, module); return module; }
private EcmaMethodIL(EcmaMethod method, int rva) { _method = method; _module = method.Module; _methodBody = _module.PEReader.GetMethodBody(rva); }
public EcmaModule GetModuleFromPath(string filePath) { // This method is not expected to be called frequently. Linear search is acceptable. foreach (var entry in _moduleData) { if (entry.Value.Path == filePath) return entry.Key; } EcmaModule module = new EcmaModule(this, new PEReader(File.OpenRead(filePath))); MetadataReader metadataReader = module.MetadataReader; string simpleName = metadataReader.GetString(metadataReader.GetAssemblyDefinition().Name); if (_modules.ContainsKey(simpleName)) throw new FileNotFoundException("Module with same simple name already exists " + filePath); AddModule(simpleName, filePath, module); return module; }
internal EcmaGenericParameter(EcmaModule module, GenericParameterHandle handle) { _module = module; _handle = handle; }
private void AddCompilationRootsForMainMethod(EcmaModule module) { if (_mainMethod != null) throw new Exception("Multiple entrypoint modules"); int entryPointToken = module.PEReader.PEHeaders.CorHeader.EntryPointTokenOrRelativeVirtualAddress; _mainMethod = module.GetMethod(MetadataTokens.EntityHandle(entryPointToken)); AddCompilationRoot(_mainMethod, "Main method", "__managed__Main"); }
public EcmaMethodIL(EcmaModule module, MethodBodyBlock methodBody) { _module = module; _methodBody = methodBody; }
public bool GeneratesMetadata(EcmaModule module, CustomAttributeHandle caHandle) { return(_factory.CustomAttributeMetadata(new ReflectableCustomAttribute(module, caHandle)).Marked); }
private bool IsModuleInCompilationGroup(EcmaModule module) { return InputModules.Contains(module); }
// TODO // bool _hasModifiers; public EcmaSignatureParser(EcmaModule module, BlobReader reader) { _module = module; _reader = reader; }
internal EcmaGenericParameter(EcmaModule module, GenericParameterHandle handle) { _module = module; _handle = handle; }
public LibraryRootProvider(EcmaModule module) { _module = module; }