Exemplo n.º 1
0
        private IReadOnlyCollection <MethodDesc> CreateInitializerList(TypeSystemContext context)
        {
            List <ModuleDesc> assembliesWithInitalizers = new List <ModuleDesc>();

            // Build a list of assemblies that have an initializer that needs to run before
            // any user code runs.
            foreach (string initAssemblyName in _initAssemblies)
            {
                ModuleDesc assembly = context.ResolveAssembly(new AssemblyName(initAssemblyName));
                assembliesWithInitalizers.Add(assembly);
            }

            var libraryInitializers = new LibraryInitializers(context, assembliesWithInitalizers);

            List <MethodDesc> initializerList = new List <MethodDesc>(libraryInitializers.LibraryInitializerMethods);

            // If there are any AppContext switches the user wishes to enable, generate code that sets them.
            if (_appContextSwitches.Count > 0)
            {
                MethodDesc appContextInitMethod = new Internal.IL.Stubs.StartupCode.AppContextInitializerMethod(
                    context.GeneratedAssembly.GetGlobalModuleType(), _appContextSwitches);
                initializerList.Add(appContextInitMethod);
            }

            return(initializerList);
        }
Exemplo n.º 2
0
        private void ProcessAssemblyDirective(IRootingServiceProvider rootProvider, XElement assemblyElement)
        {
            var assemblyNameAttribute = assemblyElement.Attribute("Name");
            if (assemblyNameAttribute == null)
                throw new Exception();

            ModuleDesc assembly = _context.ResolveAssembly(new AssemblyName(assemblyNameAttribute.Value));

            rootProvider.RootModuleMetadata(assembly, "RD.XML root");

            var dynamicDegreeAttribute = assemblyElement.Attribute("Dynamic");
            if (dynamicDegreeAttribute != null)
            {
                if (dynamicDegreeAttribute.Value != "Required All")
                    throw new NotSupportedException();

                foreach (TypeDesc type in ((EcmaModule)assembly).GetAllTypes())
                {
                    RootingHelpers.TryRootType(rootProvider, type, "RD.XML root");
                }
            }

            foreach (var element in assemblyElement.Elements())
            {
                switch (element.Name.LocalName)
                {
                    case "Type":
                        ProcessTypeDirective(rootProvider, assembly, element);
                        break;
                    default:
                        throw new NotSupportedException();
                }
            }
        }
        public ModuleDesc ResolveModuleID(long handle, bool throwIfNotFound = true)
        {
            lock (_lock)
            {
                ModuleDescInfo minfo;
                if (_modules.TryGetValue(handle, out minfo))
                {
                    if (minfo.Module != null)
                    {
                        return(minfo.Module);
                    }

                    string simpleName = minfo.TraceManagedModule.Name;

                    if (!File.Exists(minfo.TraceManagedModule.FilePath) && minfo.TraceManagedModule.FilePath.EndsWith(".il.dll") && simpleName.EndsWith(".il"))
                    {
                        simpleName = simpleName.Substring(0, simpleName.Length - 3);
                    }

                    minfo.Module = _context.ResolveAssembly(new AssemblyName(simpleName), throwIfNotFound);
                    return(minfo.Module);
                }
                else
                {
                    if (throwIfNotFound)
                    {
                        throw new Exception("Unknown ModuleID value");
                    }
                    return(null);
                }
            }
        }
Exemplo n.º 4
0
        public ModuleDesc ResolveModuleID(long handle, bool throwIfNotFound = true)
        {
            lock (_lock)
            {
                ModuleDescInfo minfo;
                if (_modules.TryGetValue(handle, out minfo))
                {
                    if (minfo.Module != null)
                    {
                        return(minfo.Module);
                    }

                    minfo.Module = _context.ResolveAssembly(new AssemblyName(minfo.AssemblyName), throwIfNotFound);
                    return(minfo.Module);
                }
                else
                {
                    if (throwIfNotFound)
                    {
                        throw new Exception("Unknown ModuleID value");
                    }
                    return(null);
                }
            }
        }
Exemplo n.º 5
0
        private void InitializeSimdModules(TypeDesc type)
        {
            TypeSystemContext context = type.Context;

            ArrayBuilder <ModuleDesc> simdModules = new ArrayBuilder <ModuleDesc>();

            ModuleDesc module = context.ResolveAssembly(new AssemblyName("System.Numerics"), false);

            if (module != null)
            {
                simdModules.Add(module);
            }

            module = context.ResolveAssembly(new AssemblyName("System.Numerics.Vectors"), false);
            if (module != null)
            {
                simdModules.Add(module);
            }

            _simdModulesCached = simdModules.ToArray();
        }
Exemplo n.º 6
0
        private void ProcessAssemblyDirective(IRootingServiceProvider rootProvider, XElement assemblyElement)
        {
            var assemblyNameAttribute = assemblyElement.Attribute("Name");

            if (assemblyNameAttribute == null)
            {
                throw new Exception();
            }

            ModuleDesc assembly = _context.ResolveAssembly(new AssemblyName(assemblyNameAttribute.Value));

            var dynamicDegreeAttribute = assemblyElement.Attribute("Dynamic");

            if (dynamicDegreeAttribute != null)
            {
                if (dynamicDegreeAttribute.Value != "Required All")
                {
                    throw new NotSupportedException();
                }

                // Reuse LibraryRootProvider to root everything
                new LibraryRootProvider((EcmaModule)assembly).AddCompilationRoots(rootProvider);
            }

            foreach (var element in assemblyElement.Elements())
            {
                switch (element.Name.LocalName)
                {
                case "Type":
                    ProcessTypeDirective(rootProvider, assembly, element);
                    break;

                default:
                    throw new NotSupportedException();
                }
            }
        }
        private static bool ResolveType(string name, ModuleDesc callingModule, out TypeDesc type, out ModuleDesc referenceModule)
        {
            // This can do enough resolution to resolve "Foo" or "Foo, Assembly, PublicKeyToken=...".
            // The reflection resolution rules are complicated. This is only needed for a heuristic,
            // not for correctness, so this shortcut is okay.

            type            = null;
            referenceModule = null;

            int i = 0;

            // Consume type name part
            StringBuilder typeName      = new StringBuilder();
            StringBuilder typeNamespace = new StringBuilder();

            while (i < name.Length && (char.IsLetterOrDigit(name[i]) || name[i] == '.' || name[i] == '`'))
            {
                if (name[i] == '.')
                {
                    if (typeNamespace.Length > 0)
                    {
                        typeNamespace.Append('.');
                    }
                    typeNamespace.Append(typeName);
                    typeName.Clear();
                }
                else
                {
                    typeName.Append(name[i]);
                }
                i++;
            }

            // Consume any comma or white space
            while (i < name.Length && (name[i] == ' ' || name[i] == ','))
            {
                i++;
            }

            // Consume assembly name
            StringBuilder assemblyName = new StringBuilder();

            while (i < name.Length && (char.IsLetterOrDigit(name[i]) || name[i] == '.'))
            {
                assemblyName.Append(name[i]);
                i++;
            }

            TypeSystemContext context = callingModule.Context;

            // If the name was assembly-qualified, resolve the assembly
            // If it wasn't qualified, we resolve in the calling assembly

            referenceModule = callingModule;
            if (assemblyName.Length > 0)
            {
                referenceModule = context.ResolveAssembly(new AssemblyName(assemblyName.ToString()), false);
                if (referenceModule == null)
                {
                    return(false);
                }
            }

            // Resolve type in the assembly
            type = referenceModule.GetType(typeNamespace.ToString(), typeName.ToString(), false);

            // If it didn't resolve and wasn't assembly-qualified, we also try core library
            if (type == null && assemblyName.Length == 0)
            {
                referenceModule = context.SystemModule;
                type            = referenceModule.GetType(typeNamespace.ToString(), typeName.ToString(), false);
            }

            return(type != null);
        }