本文整理汇总了C#中ILCompiler.DependencyAnalysis.NodeFactory.NecessaryTypeSymbol方法的典型用法代码示例。如果您正苦于以下问题:C# NodeFactory.NecessaryTypeSymbol方法的具体用法?C# NodeFactory.NecessaryTypeSymbol怎么用?C# NodeFactory.NecessaryTypeSymbol使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ILCompiler.DependencyAnalysis.NodeFactory
的用法示例。
在下文中一共展示了NodeFactory.NecessaryTypeSymbol方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OutputRelatedType
protected override void OutputRelatedType(NodeFactory factory, ref ObjectDataBuilder objData)
{
//
// Cloned types use the related type field to point via an IAT slot at their true implementation
//
objData.EmitPointerReloc(factory.NecessaryTypeSymbol(_type));
}
示例2: GetData
public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false)
{
ObjectDataBuilder objData = new ObjectDataBuilder(factory);
// The interface dispatch cell has an alignment requirement of 2 * [Pointer size] as part of the
// synchronization mechanism of the two values in the runtime.
objData.Alignment = _targetMethod.Context.Target.PointerSize * 2;
objData.DefinedSymbols.Add(this);
objData.EmitPointerReloc(factory.ExternSymbol("RhpInitialDynamicInterfaceDispatch"));
// The second cell field uses the two lower-order bits to communicate the contents.
// We add 1 to signal IDC_CachePointerIsInterfacePointer. See src\Native\Runtime\inc\rhbinder.h.
objData.EmitPointerReloc(factory.NecessaryTypeSymbol(_targetMethod.OwningType), 1);
// End the run of dispatch cells
objData.EmitZeroPointer();
// Avoid consulting VTable slots until they're guaranteed complete during final data emission
if (!relocsOnly)
{
int interfaceMethodSlot = VirtualMethodSlotHelper.GetVirtualMethodSlot(factory, _targetMethod);
if (factory.Target.PointerSize == 8)
{
objData.EmitLong(interfaceMethodSlot);
}
else
{
throw new NotImplementedException();
}
}
return objData.ToObjectData();
}
示例3: GetData
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 ISymbolNode[] { this });
var writer = new NativeWriter();
var typeMapHashTable = new VertexHashtable();
Section hashTableSection = writer.NewSection();
hashTableSection.Place(typeMapHashTable);
foreach (var node in factory.MetadataManager.GetCctorContextMapping())
{
MetadataType type = node.Type;
Debug.Assert(factory.TypeSystemContext.HasLazyStaticConstructor(type));
// If this type doesn't generate an EEType in the current compilation, don't report it in the table.
// If nobody can get to the EEType, they can't ask to run the cctor. We don't need to force generate it.
if (!factory.MetadataManager.TypeGeneratesEEType(type))
continue;
// Hash table is hashed by the hashcode of the owning type.
// Each entry has: the EEType of the type, followed by the non-GC static base.
// The non-GC static base is prefixed by the class constructor context.
// Unfortunately we need to adjust for the cctor context just so that we can subtract it again at runtime...
int delta = NonGCStaticsNode.GetClassConstructorContextStorageSize(factory.TypeSystemContext.Target, type);
Vertex vertex = writer.GetTuple(
writer.GetUnsignedConstant(_externalReferences.GetIndex(factory.NecessaryTypeSymbol(type))),
writer.GetUnsignedConstant(_externalReferences.GetIndex(node, delta))
);
int hashCode = type.GetHashCode();
typeMapHashTable.Append((uint)hashCode, hashTableSection.Place(vertex));
}
MemoryStream ms = new MemoryStream();
writer.Save(ms);
byte[] hashTableBytes = ms.ToArray();
_endSymbol.SetSymbolOffset(hashTableBytes.Length);
return new ObjectData(hashTableBytes, Array.Empty<Relocation>(), 1, new ISymbolNode[] { this, _endSymbol });
}
示例4: GetData
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 ISymbolNode[] { this });
var writer = new NativeWriter();
var typeMapHashTable = new VertexHashtable();
Section hashTableSection = writer.NewSection();
hashTableSection.Place(typeMapHashTable);
foreach (var mappingEntry in factory.MetadataManager.GetTypeDefinitionMapping())
{
if (!factory.CompilationModuleGroup.ContainsType(mappingEntry.Entity))
continue;
// Types that don't have EETypes don't need mapping table entries because there's no risk of them
// not unifying to the same System.Type at runtime.
if (!factory.MetadataManager.TypeGeneratesEEType(mappingEntry.Entity))
continue;
// Go with a necessary type symbol. It will be upgraded to a constructed one if a constructed was emitted.
IEETypeNode typeSymbol = factory.NecessaryTypeSymbol(mappingEntry.Entity);
Vertex vertex = writer.GetTuple(
writer.GetUnsignedConstant(_externalReferences.GetIndex(typeSymbol)),
writer.GetUnsignedConstant((uint)mappingEntry.MetadataHandle)
);
int hashCode = typeSymbol.Type.GetHashCode();
typeMapHashTable.Append((uint)hashCode, hashTableSection.Place(vertex));
}
MemoryStream ms = new MemoryStream();
writer.Save(ms);
byte[] hashTableBytes = ms.ToArray();
_endSymbol.SetSymbolOffset(hashTableBytes.Length);
return new ObjectData(hashTableBytes, Array.Empty<Relocation>(), 1, new ISymbolNode[] { this, _endSymbol });
}
示例5: ReadyToRunHelperNode
public ReadyToRunHelperNode(NodeFactory factory, ReadyToRunHelperId id, Object target)
{
_id = id;
_target = target;
switch (id)
{
case ReadyToRunHelperId.NewHelper:
case ReadyToRunHelperId.NewArr1:
{
// Make sure that if the EEType can't be generated, we throw the exception now.
// This way we can fail generating code for the method that references the EEType
// and (depending on the policy), we could avoid scraping the entire compilation.
TypeDesc type = (TypeDesc)target;
factory.ConstructedTypeSymbol(type);
}
break;
case ReadyToRunHelperId.IsInstanceOf:
case ReadyToRunHelperId.CastClass:
{
// Make sure that if the EEType can't be generated, we throw the exception now.
// This way we can fail generating code for the method that references the EEType
// and (depending on the policy), we could avoid scraping the entire compilation.
TypeDesc type = (TypeDesc)target;
factory.NecessaryTypeSymbol(type);
Debug.Assert(!type.IsNullable, "Nullable needs to be unwrapped");
}
break;
case ReadyToRunHelperId.GetNonGCStaticBase:
case ReadyToRunHelperId.GetGCStaticBase:
case ReadyToRunHelperId.GetThreadStaticBase:
{
// Make sure we can compute static field layout now so we can fail early
DefType defType = (DefType)target;
defType.ComputeStaticFieldLayout(StaticLayoutKind.StaticRegionSizesAndFields);
}
break;
}
}
示例6: GetData
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 ISymbolNode[] { this });
var writer = new NativeWriter();
var typeMapHashTable = new VertexHashtable();
Section hashTableSection = writer.NewSection();
hashTableSection.Place(typeMapHashTable);
foreach (var arrayType in factory.MetadataManager.GetArrayTypeMapping())
{
if (!arrayType.IsSzArray)
continue;
if (!factory.MetadataManager.TypeGeneratesEEType(arrayType))
continue;
// TODO: This should only be emitted for arrays of value types. The type loader builds everything else.
// Go with a necessary type symbol. It will be upgraded to a constructed one if a constructed was emitted.
IEETypeNode arrayTypeSymbol = factory.NecessaryTypeSymbol(arrayType);
Vertex vertex = writer.GetUnsignedConstant(_externalReferences.GetIndex(arrayTypeSymbol));
int hashCode = arrayType.GetHashCode();
typeMapHashTable.Append((uint)hashCode, hashTableSection.Place(vertex));
}
MemoryStream ms = new MemoryStream();
writer.Save(ms);
byte[] hashTableBytes = ms.ToArray();
_endSymbol.SetSymbolOffset(hashTableBytes.Length);
return new ObjectData(hashTableBytes, Array.Empty<Relocation>(), 1, new ISymbolNode[] { this, _endSymbol });
}
示例7: DependencyNodeIterator
public DependencyNodeIterator(IEnumerable<DependencyNode> nodes, NodeFactory factory)
{
_nodes = new List<DependencyNode>();
_typeToNodeMap = new Dictionary<TypeDesc, EETypeNode>();
_visited = new HashSet<DependencyNode>();
foreach (var node in nodes)
{
if (node is EETypeNode)
{
var typeNode = node as EETypeNode;
if (!_typeToNodeMap.ContainsKey(typeNode.Type))
_typeToNodeMap[typeNode.Type] = typeNode;
else if (typeNode is ConstructedEETypeNode)
_typeToNodeMap[typeNode.Type] = typeNode;
}
else
if (node is CppMethodCodeNode)
{
// TODO: Remove once the type depedencies are tracked properly
// Ensure that there is going to be a forward type definition for the method containing type
var methodNode = node as CppMethodCodeNode;
var methodType = methodNode.Method.OwningType;
if (!_typeToNodeMap.ContainsKey(methodType))
_typeToNodeMap[methodType] = (EETypeNode)factory.NecessaryTypeSymbol(methodType);
}
// Assume ordering doesn't matter
else _nodes.Add(node);
}
foreach (var node in _typeToNodeMap.Values)
{
AddTypeNode(node);
}
}
示例8: OutputGenericInstantiationDetails
private void OutputGenericInstantiationDetails(NodeFactory factory, ref ObjectDataBuilder objData)
{
if (_type.HasInstantiation && !_type.IsTypeDefinition)
{
objData.EmitPointerReloc(factory.NecessaryTypeSymbol(_type.GetTypeDefinition()));
GenericCompositionDetails details;
if (_type.GetTypeDefinition() == factory.ArrayOfTEnumeratorType)
{
// Generic array enumerators use special variance rules recognized by the runtime
details = new GenericCompositionDetails(_type.Instantiation, new[] { GenericVariance.ArrayCovariant });
}
else
details = new GenericCompositionDetails(_type);
objData.EmitPointerReloc(factory.GenericComposition(details));
}
}
示例9: OutputNullableTypeParameter
private void OutputNullableTypeParameter(NodeFactory factory, ref ObjectDataBuilder objData)
{
if (_type.IsNullable)
{
objData.EmitPointerReloc(factory.NecessaryTypeSymbol(_type.Instantiation[0]));
}
}
示例10: OutputRelatedType
protected virtual void OutputRelatedType(NodeFactory factory, ref ObjectDataBuilder objData)
{
ISymbolNode relatedTypeNode = null;
if (_type.IsArray || _type.IsPointer || _type.IsByRef)
{
var parameterType = ((ParameterizedType)_type).ParameterType;
relatedTypeNode = factory.NecessaryTypeSymbol(parameterType);
}
else
{
TypeDesc baseType = _type.BaseType;
if (baseType != null)
{
relatedTypeNode = GetBaseTypeNode(factory);
}
}
if (relatedTypeNode != null)
{
objData.EmitPointerReloc(relatedTypeNode);
}
else
{
objData.EmitZeroPointer();
}
}
示例11: GetBaseTypeNode
protected virtual ISymbolNode GetBaseTypeNode(NodeFactory factory)
{
return _type.BaseType != null ? factory.NecessaryTypeSymbol(_type.BaseType) : null;
}
示例12: OutputInterfaceMap
protected override void OutputInterfaceMap(NodeFactory factory, ref ObjectDataBuilder objData)
{
foreach (var itf in _type.RuntimeInterfaces)
{
objData.EmitPointerReloc(factory.NecessaryTypeSymbol(itf));
}
}
示例13: EmitCode
protected override void EmitCode(NodeFactory factory, ref X64Emitter encoder, bool relocsOnly)
{
switch (Id)
{
case ReadyToRunHelperId.NewHelper:
encoder.EmitLEAQ(encoder.TargetRegister.Arg0, factory.ConstructedTypeSymbol((TypeDesc)Target));
encoder.EmitJMP(factory.ExternSymbol("__allocate_object"));
break;
case ReadyToRunHelperId.VirtualCall:
if (relocsOnly)
break;
AddrMode loadFromThisPtr = new AddrMode(encoder.TargetRegister.Arg0, null, 0, 0, AddrModeSize.Int64);
encoder.EmitMOV(encoder.TargetRegister.Result, ref loadFromThisPtr);
{
int slot = VirtualMethodSlotHelper.GetVirtualMethodSlot(factory, (MethodDesc)Target);
Debug.Assert(slot != -1);
AddrMode jmpAddrMode = new AddrMode(encoder.TargetRegister.Result, null, EETypeNode.GetVTableOffset(factory.Target.PointerSize) + (slot * factory.Target.PointerSize), 0, AddrModeSize.Int64);
encoder.EmitJmpToAddrMode(ref jmpAddrMode);
}
break;
case ReadyToRunHelperId.IsInstanceOf:
encoder.EmitLEAQ(encoder.TargetRegister.Arg1, factory.NecessaryTypeSymbol((TypeDesc)Target));
encoder.EmitJMP(factory.ExternSymbol("__isinst_class"));
break;
case ReadyToRunHelperId.CastClass:
encoder.EmitLEAQ(encoder.TargetRegister.Arg1, factory.NecessaryTypeSymbol((TypeDesc)Target));
encoder.EmitJMP(factory.ExternSymbol("__castclass_class"));
break;
case ReadyToRunHelperId.NewArr1:
encoder.EmitLEAQ(encoder.TargetRegister.Arg1, factory.NecessaryTypeSymbol((TypeDesc)Target));
encoder.EmitJMP(factory.ExternSymbol("__allocate_array"));
break;
case ReadyToRunHelperId.GetNonGCStaticBase:
if (!((MetadataType)Target).HasStaticConstructor)
{
Debug.Assert(Id == ReadyToRunHelperId.GetNonGCStaticBase);
encoder.EmitLEAQ(encoder.TargetRegister.Result, factory.TypeNonGCStaticsSymbol((MetadataType)Target));
encoder.EmitRET();
}
else
{
// We need to trigger the cctor before returning the base
encoder.EmitLEAQ(encoder.TargetRegister.Arg0, factory.TypeCctorContextSymbol((MetadataType)Target));
encoder.EmitLEAQ(encoder.TargetRegister.Arg1, factory.TypeNonGCStaticsSymbol((MetadataType)Target));
encoder.EmitJMP(factory.HelperEntrypoint(HelperEntrypoint.EnsureClassConstructorRunAndReturnNonGCStaticBase));
}
break;
case ReadyToRunHelperId.GetThreadStaticBase:
encoder.EmitINT3();
break;
case ReadyToRunHelperId.GetGCStaticBase:
if (!((MetadataType)Target).HasStaticConstructor)
{
encoder.EmitLEAQ(encoder.TargetRegister.Result, factory.TypeGCStaticsSymbol((MetadataType)Target));
AddrMode loadFromRax = new AddrMode(encoder.TargetRegister.Result, null, 0, 0, AddrModeSize.Int64);
encoder.EmitMOV(encoder.TargetRegister.Result, ref loadFromRax);
encoder.EmitMOV(encoder.TargetRegister.Result, ref loadFromRax);
encoder.EmitRET();
}
else
{
// We need to trigger the cctor before returning the base
encoder.EmitLEAQ(encoder.TargetRegister.Arg0, factory.TypeCctorContextSymbol((MetadataType)Target));
encoder.EmitLEAQ(encoder.TargetRegister.Arg1, factory.TypeGCStaticsSymbol((MetadataType)Target));
AddrMode loadFromRdx = new AddrMode(encoder.TargetRegister.Arg1, null, 0, 0, AddrModeSize.Int64);
encoder.EmitMOV(encoder.TargetRegister.Arg1, ref loadFromRdx);
encoder.EmitMOV(encoder.TargetRegister.Arg1, ref loadFromRdx);
encoder.EmitJMP(factory.HelperEntrypoint(HelperEntrypoint.EnsureClassConstructorRunAndReturnGCStaticBase));
}
break;
case ReadyToRunHelperId.DelegateCtor:
{
DelegateInfo target = (DelegateInfo)Target;
encoder.EmitLEAQ(encoder.TargetRegister.Arg2, factory.MethodEntrypoint(target.Target));
if (target.ShuffleThunk != null)
encoder.EmitLEAQ(encoder.TargetRegister.Arg3, factory.MethodEntrypoint(target.ShuffleThunk));
encoder.EmitJMP(factory.MethodEntrypoint(target.Ctor));
}
break;
default:
throw new NotImplementedException();
}
}
示例14: GetData
public override ObjectData GetData(NodeFactory factory, bool relocsOnly)
{
ObjectDataBuilder objData = new ObjectDataBuilder(factory);
objData.Alignment = 16;
objData.DefinedSymbols.Add(this);
if (_type.IsArray)
{
objData.EmitShort((short)((ArrayType)_type).ElementType.GetElementSize()); // m_ComponentSize
objData.EmitShort(0x4); // m_flags: IsArray(0x4)
}
else if (_type.IsString)
{
objData.EmitShort(2); // m_ComponentSize
objData.EmitShort(0); // m_flags: 0
}
else
{
objData.EmitShort(0); // m_ComponentSize
objData.EmitShort(0); // m_flags: 0
}
int pointerSize = _type.Context.Target.PointerSize;
int minimumObjectSize = pointerSize * 3;
int objectSize;
if (_type is MetadataType)
{
objectSize = pointerSize +
((MetadataType)_type).InstanceByteCount; // +pointerSize for SyncBlock
}
else if (_type is ArrayType)
{
objectSize = 3 * pointerSize; // SyncBlock + EETypePtr + Length
int rank = ((ArrayType)_type).Rank;
if (rank > 1)
objectSize +=
2 * _type.Context.GetWellKnownType(WellKnownType.Int32).GetElementSize() * rank;
}
else
throw new NotImplementedException();
objectSize = AlignmentHelper.AlignUp(objectSize, pointerSize);
objectSize = Math.Max(minimumObjectSize, objectSize);
if (_type.IsString)
{
// If this is a string, throw away objectSize we computed so far. Strings are special.
// SyncBlock + EETypePtr + length + firstChar
objectSize = 2 * pointerSize +
_type.Context.GetWellKnownType(WellKnownType.Int32).GetElementSize() +
_type.Context.GetWellKnownType(WellKnownType.Char).GetElementSize();
}
objData.EmitInt(objectSize);
if (Type.BaseType != null)
{
if (_constructed)
{
objData.EmitPointerReloc(factory.ConstructedTypeSymbol(Type.BaseType));
}
else
{
objData.EmitPointerReloc(factory.NecessaryTypeSymbol(Type.BaseType));
}
}
else
{
objData.EmitZeroPointer();
}
if (_constructed)
{
OutputVirtualSlots(ref objData, _type, _type, factory);
}
return objData.ToObjectData();
}
示例15: GetData
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 ISymbolNode[] { this });
ObjectDataBuilder builder = new ObjectDataBuilder(factory);
foreach (var mappingEntry in factory.MetadataManager.GetTypeDefinitionMapping())
{
if (!factory.CompilationModuleGroup.ContainsType(mappingEntry.Entity))
continue;
// We are looking for any EEType - constructed or not, it has to be in the mapping
// table so that we can map it to metadata.
EETypeNode node = null;
if (!mappingEntry.Entity.IsGenericDefinition)
{
node = factory.ConstructedTypeSymbol(mappingEntry.Entity) as EETypeNode;
}
if (node == null || !node.Marked)
{
// This might have been a typeof() expression.
node = factory.NecessaryTypeSymbol(mappingEntry.Entity) as EETypeNode;
}
if (node.Marked)
{
// TODO: this format got very inefficient due to not being able to use RVAs
// replace with a hash table
builder.EmitPointerReloc(node);
builder.EmitInt(mappingEntry.MetadataHandle);
if (factory.Target.PointerSize == 8)
builder.EmitInt(0); // Pad
}
}
_endSymbol.SetSymbolOffset(builder.CountBytes);
builder.DefinedSymbols.Add(this);
builder.DefinedSymbols.Add(_endSymbol);
return builder.ToObjectData();
}