コード例 #1
0
        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");
                    }
                }
            }
        }
コード例 #2
0
            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);
                    }
                }
            }
コード例 #3
0
        // TODO
        // bool _hasModifiers;

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

            // _hasModifiers = false;
        }
コード例 #4
0
        public StaticFieldLayoutTests()
        {
            _context = new TestTypeSystemContext(TargetArchitecture.X64);
            var systemModule = _context.CreateModuleForSimpleName("CoreTestAssembly");
            _context.SetSystemModule(systemModule);

            _testModule = systemModule;
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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);
            }
        }
コード例 #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");
        }
コード例 #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);
             }
         }
     }
 }
コード例 #9
0
ファイル: EcmaType.cs プロジェクト: noahfalk/corert
        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
        }
コード例 #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;
            }
        }
コード例 #11
0
 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);
     }
 }
コード例 #12
0
        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;
        }
コード例 #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);
                    }
                }
            }
        }
コード例 #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);
        }
コード例 #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");
        }
コード例 #16
0
 public EcmaModule CreateModuleForSimpleName(string simpleName)
 {
     EcmaModule module = new EcmaModule(this, new PEReader(File.OpenRead(simpleName + ".dll")));
     _modules.Add(simpleName, module);
     return module;
 }
コード例 #17
0
 public CustomAttributeTypeProvider(EcmaModule module)
 {
     _module = module;
 }
コード例 #18
0
ファイル: EcmaModule.cs プロジェクト: huamichaelchen/corert
 public EcmaObjectLookupHashtable(EcmaModule module)
 {
     _module = module;
 }
コード例 #19
0
        // TODO
        // bool _hasModifiers;

        public EcmaSignatureParser(EcmaModule module, BlobReader reader)
        {
            _module = module;
            _reader = reader;
        }
コード例 #20
0
 public ExportedMethodsRootProvider(EcmaModule module)
 {
     _module = module;
 }
コード例 #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);
        }
コード例 #22
0
ファイル: EcmaMethodIL.cs プロジェクト: noahfalk/corert
 private EcmaMethodIL(EcmaModule module, int rva)
 {
     _module = module;
     _methodBody = module.PEReader.GetMethodBody(rva);
 }
コード例 #23
0
 private bool IsModuleInCompilationGroup(EcmaModule module)
 {
     return _compilationModuleSet.Contains(module);
 }
コード例 #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;
        }
コード例 #25
0
ファイル: EcmaMethodIL.cs プロジェクト: justinvp/corert
 private EcmaMethodIL(EcmaMethod method, int rva)
 {
     _method = method;
     _module = method.Module;
     _methodBody = _module.PEReader.GetMethodBody(rva);
 }
コード例 #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;
        }
コード例 #27
0
 internal EcmaGenericParameter(EcmaModule module, GenericParameterHandle handle)
 {
     _module = module;
     _handle = handle;
 }
コード例 #28
0
ファイル: Compilation.cs プロジェクト: noahfalk/corert
        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");
        }
コード例 #29
0
ファイル: EcmaMethodIL.cs プロジェクト: AustinWise/corert
 public EcmaMethodIL(EcmaModule module, MethodBodyBlock methodBody)
 {
     _module = module;
     _methodBody = methodBody;
 }
コード例 #30
0
 public bool GeneratesMetadata(EcmaModule module, CustomAttributeHandle caHandle)
 {
     return(_factory.CustomAttributeMetadata(new ReflectableCustomAttribute(module, caHandle)).Marked);
 }
コード例 #31
0
 private bool IsModuleInCompilationGroup(EcmaModule module)
 {
     return InputModules.Contains(module);
 }
コード例 #32
0
        // TODO
        // bool _hasModifiers;

        public EcmaSignatureParser(EcmaModule module, BlobReader reader)
        {
            _module = module;
            _reader = reader;
        }
コード例 #33
0
 internal EcmaGenericParameter(EcmaModule module, GenericParameterHandle handle)
 {
     _module = module;
     _handle = handle;
 }
コード例 #34
0
 public LibraryRootProvider(EcmaModule module)
 {
     _module = module;
 }