本文整理汇总了C#中NativeWriter.GetUnsignedConstant方法的典型用法代码示例。如果您正苦于以下问题:C# NativeWriter.GetUnsignedConstant方法的具体用法?C# NativeWriter.GetUnsignedConstant怎么用?C# NativeWriter.GetUnsignedConstant使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NativeWriter
的用法示例。
在下文中一共展示了NativeWriter.GetUnsignedConstant方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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 });
}
示例2: 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 });
}
示例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 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 });
}
示例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);
// Get a list of all methods that have a method body and metadata from the metadata manager.
foreach (var mappingEntry in factory.MetadataManager.GetMethodMapping())
{
MethodDesc method = mappingEntry.Entity;
// The current format requires us to have an EEType for the owning type. We might want to lift this.
if (!factory.MetadataManager.TypeGeneratesEEType(method.OwningType))
continue;
// We have a method body, we have a metadata token, but we can't get an invoke stub. Bail.
if (!factory.MetadataManager.HasReflectionInvokeStub(method))
continue;
InvokeTableFlags flags = 0;
if (method.HasInstantiation)
flags |= InvokeTableFlags.IsGenericMethod;
if (method.GetCanonMethodTarget(CanonicalFormKind.Specific).RequiresInstArg())
flags |= InvokeTableFlags.RequiresInstArg;
// TODO: better check for default public(!) constructor
if (method.IsConstructor && method.Signature.Length == 0)
flags |= InvokeTableFlags.IsDefaultConstructor;
// TODO: HasVirtualInvoke
if (!method.IsAbstract)
flags |= InvokeTableFlags.HasEntrypoint;
// Once we have a true multi module compilation story, we'll need to start emitting entries where this is not set.
flags |= InvokeTableFlags.HasMetadataHandle;
// TODO: native signature for P/Invokes and NativeCallable methods
if (method.IsRawPInvoke() || method.IsNativeCallable)
continue;
// Grammar of an entry in the hash table:
// Flags + DeclaringType + MetadataHandle/NameAndSig + Entrypoint + DynamicInvokeMethod + [NumGenericArgs + GenericArgs]
Vertex vertex = writer.GetUnsignedConstant((uint)flags);
if ((flags & InvokeTableFlags.HasMetadataHandle) != 0)
{
// Only store the offset portion of the metadata handle to get better integer compression
vertex = writer.GetTuple(vertex,
writer.GetUnsignedConstant((uint)(mappingEntry.MetadataHandle & MetadataGeneration.MetadataOffsetMask)));
}
else
{
// TODO: no MD handle case
}
// Go with a necessary type symbol. It will be upgraded to a constructed one if a constructed was emitted.
IEETypeNode owningTypeSymbol = factory.NecessaryTypeSymbol(method.OwningType);
vertex = writer.GetTuple(vertex,
writer.GetUnsignedConstant(_externalReferences.GetIndex(owningTypeSymbol)));
if ((flags & InvokeTableFlags.HasEntrypoint) != 0)
{
vertex = writer.GetTuple(vertex,
writer.GetUnsignedConstant(_externalReferences.GetIndex(
factory.MethodEntrypoint(method.GetCanonMethodTarget(CanonicalFormKind.Specific)))));
}
// TODO: data to generate the generic dictionary with the type loader
MethodDesc invokeStubMethod = factory.MetadataManager.GetReflectionInvokeStub(method);
MethodDesc canonInvokeStubMethod = invokeStubMethod.GetCanonMethodTarget(CanonicalFormKind.Specific);
if (invokeStubMethod != canonInvokeStubMethod)
{
vertex = writer.GetTuple(vertex,
writer.GetUnsignedConstant(_externalReferences.GetIndex(factory.FatFunctionPointer(invokeStubMethod), FatFunctionPointerConstants.Offset) << 1));
}
else
{
vertex = writer.GetTuple(vertex,
writer.GetUnsignedConstant(_externalReferences.GetIndex(factory.MethodEntrypoint(invokeStubMethod)) << 1));
}
if ((flags & InvokeTableFlags.IsGenericMethod) != 0)
{
if ((flags & InvokeTableFlags.RequiresInstArg) == 0 || (flags & InvokeTableFlags.HasEntrypoint) == 0)
{
VertexSequence args = new VertexSequence();
for (int i = 0; i < method.Instantiation.Length; i++)
{
uint argId = _externalReferences.GetIndex(factory.NecessaryTypeSymbol(method.Instantiation[i]));
args.Append(writer.GetUnsignedConstant(argId));
//.........这里部分代码省略.........
示例5: 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 fieldMapHashTable = new VertexHashtable();
Section hashTableSection = writer.NewSection();
hashTableSection.Place(fieldMapHashTable);
foreach (var fieldMapping in factory.MetadataManager.GetFieldMapping())
{
FieldDesc field = fieldMapping.Entity;
if (field.IsLiteral || field.HasRva)
continue;
FieldTableFlags flags;
if (field.IsThreadStatic)
{
flags = FieldTableFlags.ThreadStatic;
}
else if (field.IsStatic)
{
flags = FieldTableFlags.Static;
if (field.HasGCStaticBase)
flags |= FieldTableFlags.IsGcSection;
}
else
{
flags = FieldTableFlags.Instance;
}
// TODO: support emitting field info without a handle for generics in multifile
flags |= FieldTableFlags.HasMetadataHandle;
if (field.OwningType.IsCanonicalSubtype(CanonicalFormKind.Universal))
flags |= FieldTableFlags.IsUniversalCanonicalEntry;
// Grammar of a hash table entry:
// Flags + DeclaringType + MdHandle or Name + Cookie or Ordinal or Offset
Vertex vertex = writer.GetUnsignedConstant((uint)flags);
uint declaringTypeId = _externalReferences.GetIndex(factory.NecessaryTypeSymbol(field.OwningType));
vertex = writer.GetTuple(vertex,
writer.GetUnsignedConstant(declaringTypeId));
if ((flags & FieldTableFlags.HasMetadataHandle) != 0)
{
// Only store the offset portion of the metadata handle to get better integer compression
vertex = writer.GetTuple(vertex,
writer.GetUnsignedConstant((uint)(fieldMapping.MetadataHandle & MetadataGeneration.MetadataOffsetMask)));
}
else
{
throw new NotImplementedException();
}
if ((flags & FieldTableFlags.IsUniversalCanonicalEntry) != 0)
{
throw new NotImplementedException();
}
else
{
switch (flags & FieldTableFlags.StorageClass)
{
case FieldTableFlags.ThreadStatic:
case FieldTableFlags.Static:
// TODO: statics and thread statics
continue;
case FieldTableFlags.Instance:
vertex = writer.GetTuple(vertex,
writer.GetUnsignedConstant((uint)field.Offset));
break;
}
}
int hashCode = field.OwningType.ConvertToCanonForm(CanonicalFormKind.Specific).GetHashCode();
fieldMapHashTable.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 });
}
示例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 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)
{
Vertex vertex = writer.GetTuple(
writer.GetUnsignedConstant(_externalReferences.GetIndex(node)),
writer.GetUnsignedConstant((uint)mappingEntry.MetadataHandle)
);
int hashCode = node.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 });
}