Beispiel #1
0
 public StructStringKeyFormatterImplementor(ModuleDefinition module, TypeProvider provider, DataHelper dataHelper, AutomataEmbeddingHelper automataHelper)
 {
     this.module         = module;
     this.provider       = provider;
     this.dataHelper     = dataHelper;
     this.automataHelper = automataHelper;
 }
Beispiel #2
0
 public GenericClassImplementorFacade(ModuleDefinition module, TypeProvider provider, DataHelper dataHelper, AutomataEmbeddingHelper automataHelper)
 {
     this.module         = module;
     this.provider       = provider;
     this.dataHelper     = dataHelper;
     this.automataHelper = automataHelper;
 }
Beispiel #3
0
 public ClassStringKeyAllMessagePackPrimitiveImplementor(ModuleDefinition module, TypeProvider provider, DataHelper dataHelper, AutomataEmbeddingHelper automataHelper)
 {
     this.module         = module;
     this.provider       = provider;
     this.dataHelper     = dataHelper;
     this.automataHelper = automataHelper;
 }
Beispiel #4
0
 public GenericFormatterBaseTypeDefinitionGenerator(TypeDefinition resolver, TypeProvider provider, DataHelper dataHelper, AutomataEmbeddingHelper automataHelper)
 {
     this.resolver       = resolver;
     this.provider       = provider;
     this.dataHelper     = dataHelper;
     this.automataHelper = automataHelper;
     this.module         = resolver.Module;
 }
Beispiel #5
0
 public GenericClassStringKeyFormatterImplementor(ModuleDefinition module, TypeProvider provider, DataHelper dataHelper, ModuleImporter importer, AutomataEmbeddingHelper automataHelper)
 {
     this.module         = module;
     this.provider       = provider;
     this.dataHelper     = dataHelper;
     this.importer       = importer;
     this.automataHelper = automataHelper;
 }
Beispiel #6
0
        public void Generate(
            string inputPath,
            string resolverName,
            string[] libraryPaths,
            string[] definitionPaths,
            bool useMapMode,
            double loadFactor)
        {
            if (disposed)
            {
                throw new InvalidOperationException("Generate method can be called once.");
            }

            var sw = new Stopwatch();
            ModuleDefinition inputModule;
            TypeDefinition   resolverTypeDefinition;
            TypeProvider     provider;

            moduleDefinitions = new ModuleDefinition[1 + libraryPaths.Length];
            using (new Watcher(sw, logger, "Module Reading"))
            {
                moduleDefinitions[0] = inputModule = ModuleDefinition.ReadModule(inputPath, readerParam);

                logger("log inputModule\nassembly : " + inputModule.Assembly.FullName + "\nfile : " + inputModule.FileName);

                var resolverFinder = new FormatterResolverFinder();
                resolverTypeDefinition = resolverFinder.Find(inputModule, resolverName);

                logger("log resolver\nname : " + resolverTypeDefinition.FullName);

                var messagePackAssemblyNameReference = inputModule.AssemblyReferences.First(x => x.Name == "MessagePack");
                ReadModules(libraryPaths, moduleDefinitions);
                definitionModuleDefinitions = new ModuleDefinition[definitionPaths.Length];
                for (var index = 0; index < definitionPaths.Length; index++)
                {
                    var path = definitionPaths[index];
                    definitionModuleDefinitions[index] = ModuleDefinition.ReadModule(path, doNotWriteReaderParam);
                }

                var verifier = new ModuleRelationshipVerifier();
                verifier.Verify(inputModule, moduleDefinitions);

                provider = new TypeProvider(inputModule, messagePackAssemblyNameReference, reportHook);
            }

            CollectedInfo[]         collectedInfos;
            EnumSerializationInfo[] enumSerializationInfos;
            using (new Watcher(sw, logger, "Method Collect"))
            {
                collectedInfos = CollectInfo(useMapMode, moduleDefinitions);
                logger("collected serialization info length : " + collectedInfos.Length);
                var enumTypeCollector = new EnumTypeCollector();
                enumSerializationInfos = enumTypeCollector.Collect(collectedInfos);
                logger("collected enum serialization info length : " + enumSerializationInfos.Length);
            }

            using (new Watcher(sw, logger, "Ensure Internal Access"))
            {
                EnsureInternalAccessibility(inputModule, collectedInfos, provider.SystemObjectHelper);
            }

            FormatterTableItemInfo[] formatterInfos;
            using (new Watcher(sw, logger, "Formatter Generation"))
            {
                var dataHelper     = new DataHelper(resolverTypeDefinition.Module, provider.SystemValueTypeHelper.ValueType);
                var automataHelper = new AutomataEmbeddingHelper(resolverTypeDefinition, provider.SystemReadOnlySpanHelper, dataHelper);
                formatterInfos = CalculateFormatterInfos(loadFactor, resolverTypeDefinition, provider, collectedInfos, enumSerializationInfos, automataHelper, dataHelper);
            }

            using (new Watcher(sw, logger, "Formatter Table Generation"))
            {
                var pairGenerator  = new TypeKeyInterfaceMessagePackFormatterValuePairGenerator(provider);
                var tableGenerator = new FixedTypeKeyInterfaceMessagePackFormatterValueHashtableGenerator(inputModule, pairGenerator, provider.SystemObjectHelper, provider.SystemTypeHelper, provider.Importer, provider.SystemArrayHelper, loadFactor);
                var(tableType, getFormatterMethodInfo) = tableGenerator.Generate(formatterInfos);
                resolverTypeDefinition.NestedTypes.Add(tableType);

                var resolverInjector = new ResolverInjector(inputModule, resolverTypeDefinition, provider);
                resolverInjector.Implement(getFormatterMethodInfo);

                PrivateAccessEnabler.EnablePrivateAccess(inputModule, provider.SystemRuntimeExtensionsScope);
            }

            try
            {
                using (new Watcher(sw, logger, "Input DLL Writing"))
                {
                    inputModule.Write();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
Beispiel #7
0
        private static FormatterTableItemInfo[] CalculateFormatterInfos(double loadFactor, TypeDefinition resolverTypeDefinition, TypeProvider provider, CollectedInfo[] collectedInfos, EnumSerializationInfo[] enumSerializationInfos, AutomataEmbeddingHelper automataHelper, DataHelper dataHelper)
        {
            var answer = new List <FormatterTableItemInfo>();

            var generator          = new FormatterBaseTypeDefinitionGenerator(resolverTypeDefinition, provider, dataHelper, automataHelper, loadFactor);
            var baseFormatterInfos = generator.Generate(collectedInfos);

            answer.AddRange(baseFormatterInfos);

            var genericGenerator      = new GenericFormatterBaseTypeDefinitionGenerator(resolverTypeDefinition, provider, dataHelper, automataHelper);
            var genericFormatterInfos = genericGenerator.Generate(collectedInfos);

            answer.AddRange(genericFormatterInfos);

            var enumGenerator      = new EnumFormatterBaseTypeDefinitionGenerator(resolverTypeDefinition, provider);
            var enumFormatterInfos = enumGenerator.Generate(enumSerializationInfos);

            answer.AddRange(enumFormatterInfos);

            return(answer.ToArray());
        }