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);
                    }
                }
            }
Exemplo n.º 3
0
        // TODO
        // bool _hasModifiers;

        public EcmaSignatureParser(EcmaModule module, BlobReader reader)
        {
            _module = module;
            _reader = reader;

            // _hasModifiers = false;
        }
Exemplo n.º 4
0
        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);
            }
        }
Exemplo n.º 7
0
        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");
        }
Exemplo n.º 8
0
 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);
             }
         }
     }
 }
Exemplo n.º 9
0
        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
        }
Exemplo n.º 10
0
        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;
        }
Exemplo n.º 13
0
        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);
                    }
                }
            }
        }
Exemplo n.º 14
0
        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);
        }
Exemplo n.º 15
0
        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");
        }
Exemplo n.º 16
0
 public EcmaModule CreateModuleForSimpleName(string simpleName)
 {
     EcmaModule module = new EcmaModule(this, new PEReader(File.OpenRead(simpleName + ".dll")));
     _modules.Add(simpleName, module);
     return module;
 }
Exemplo n.º 17
0
 public CustomAttributeTypeProvider(EcmaModule module)
 {
     _module = module;
 }
Exemplo n.º 18
0
 public EcmaObjectLookupHashtable(EcmaModule module)
 {
     _module = module;
 }
Exemplo n.º 19
0
        // TODO
        // bool _hasModifiers;

        public EcmaSignatureParser(EcmaModule module, BlobReader reader)
        {
            _module = module;
            _reader = reader;
        }
Exemplo n.º 20
0
 public ExportedMethodsRootProvider(EcmaModule module)
 {
     _module = module;
 }
Exemplo n.º 21
0
        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);
        }
Exemplo n.º 22
0
 private EcmaMethodIL(EcmaModule module, int rva)
 {
     _module = module;
     _methodBody = module.PEReader.GetMethodBody(rva);
 }
 private bool IsModuleInCompilationGroup(EcmaModule module)
 {
     return _compilationModuleSet.Contains(module);
 }
Exemplo n.º 24
0
        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;
        }
Exemplo n.º 25
0
 private EcmaMethodIL(EcmaMethod method, int rva)
 {
     _method = method;
     _module = method.Module;
     _methodBody = _module.PEReader.GetMethodBody(rva);
 }
Exemplo n.º 26
0
        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;
        }
Exemplo n.º 27
0
 internal EcmaGenericParameter(EcmaModule module, GenericParameterHandle handle)
 {
     _module = module;
     _handle = handle;
 }
Exemplo n.º 28
0
        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");
        }
Exemplo n.º 29
0
 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);
 }
Exemplo n.º 32
0
        // TODO
        // bool _hasModifiers;

        public EcmaSignatureParser(EcmaModule module, BlobReader reader)
        {
            _module = module;
            _reader = reader;
        }
Exemplo n.º 33
0
 internal EcmaGenericParameter(EcmaModule module, GenericParameterHandle handle)
 {
     _module = module;
     _handle = handle;
 }
Exemplo n.º 34
0
 public LibraryRootProvider(EcmaModule module)
 {
     _module = module;
 }