public NodeFactory( CompilerTypeSystemContext context, ReadyToRunCompilationModuleGroupBase compilationModuleGroup, ProfileDataManager profileDataManager, NameMangler nameMangler, CopiedCorHeaderNode corHeaderNode, DebugDirectoryNode debugDirectoryNode, ResourceData win32Resources, ReadyToRunFlags flags, NodeFactoryOptimizationFlags nodeFactoryOptimizationFlags, ulong imageBase) { OptimizationFlags = nodeFactoryOptimizationFlags; TypeSystemContext = context; CompilationModuleGroup = compilationModuleGroup; ProfileDataManager = profileDataManager; Target = context.Target; NameMangler = nameMangler; MetadataManager = new ReadyToRunTableManager(context); CopiedCorHeaderNode = corHeaderNode; DebugDirectoryNode = debugDirectoryNode; Resolver = compilationModuleGroup.Resolver; Header = new GlobalHeaderNode(Target, flags); ImageBase = imageBase; if (!win32Resources.IsEmpty) { Win32ResourcesNode = new Win32ResourcesNode(win32Resources); } if (CompilationModuleGroup.IsCompositeBuildMode) { // Create a null top-level signature context to force producing module overrides for all signaturess SignatureContext = new SignatureContext(null, Resolver); } else { SignatureContext = new SignatureContext(CompilationModuleGroup.CompilationModuleSet.Single(), Resolver); } CreateNodeCaches(); }
public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false) { // This node does not trigger generation of other nodes. if (relocsOnly) { return(new ObjectData(Array.Empty <byte>(), Array.Empty <Relocation>(), 1, new ISymbolDefinitionNode[] { this })); } NativeWriter writer = new NativeWriter(); Section section = writer.NewSection(); VertexHashtable typesHashtable = new VertexHashtable(); section.Place(typesHashtable); ReadyToRunTableManager r2rManager = (ReadyToRunTableManager)factory.MetadataManager; foreach (TypeInfo <TypeDefinitionHandle> defTypeInfo in r2rManager.GetDefinedTypes()) { TypeDefinitionHandle defTypeHandle = defTypeInfo.Handle; int hashCode = 0; for (; ;) { TypeDefinition defType = defTypeInfo.MetadataReader.GetTypeDefinition(defTypeHandle); string namespaceName = defTypeInfo.MetadataReader.GetString(defType.Namespace); string typeName = defTypeInfo.MetadataReader.GetString(defType.Name); hashCode ^= ReadyToRunHashCode.NameHashCode(namespaceName, typeName); if (!defType.Attributes.IsNested()) { break; } defTypeHandle = defType.GetDeclaringType(); } typesHashtable.Append(unchecked ((uint)hashCode), section.Place(new UnsignedConstant(((uint)MetadataTokens.GetRowNumber(defTypeInfo.Handle) << 1) | 0))); } foreach (TypeInfo <ExportedTypeHandle> expTypeInfo in r2rManager.GetExportedTypes()) { ExportedTypeHandle expTypeHandle = expTypeInfo.Handle; int hashCode = 0; for (; ;) { ExportedType expType = expTypeInfo.MetadataReader.GetExportedType(expTypeHandle); string namespaceName = expTypeInfo.MetadataReader.GetString(expType.Namespace); string typeName = expTypeInfo.MetadataReader.GetString(expType.Name); hashCode ^= ReadyToRunHashCode.NameHashCode(namespaceName, typeName); if (expType.Implementation.Kind != HandleKind.ExportedType) { // Not a nested class break; } expTypeHandle = (ExportedTypeHandle)expType.Implementation; } typesHashtable.Append(unchecked ((uint)hashCode), section.Place(new UnsignedConstant(((uint)MetadataTokens.GetRowNumber(expTypeInfo.Handle) << 1) | 1))); } MemoryStream writerContent = new MemoryStream(); writer.Save(writerContent); return(new ObjectData( data: writerContent.ToArray(), relocs: null, alignment: 8, definedSymbols: new ISymbolDefinitionNode[] { this })); }