本文整理汇总了C#中Mono.Cecil.TypeReference.MangledName方法的典型用法代码示例。如果您正苦于以下问题:C# TypeReference.MangledName方法的具体用法?C# TypeReference.MangledName怎么用?C# TypeReference.MangledName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono.Cecil.TypeReference
的用法示例。
在下文中一共展示了TypeReference.MangledName方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetDelegateWrapper
private static MethodDefinition GetDelegateWrapper(ModuleDefinition module, TypeReference multicastDelegateType)
{
// Find DelegateWrappers type in assembly
var delegateWrappersType = module.GetType("DelegateWrappers");
if (delegateWrappersType == null)
return null;
// Find if any method match the requested type
var multicastDelegateName = multicastDelegateType.MangledName();
return delegateWrappersType.Methods.FirstOrDefault(x => x.Name == multicastDelegateName);
}
示例2: BuildType
//.........这里部分代码省略.........
case MetadataType.Void:
dataType = LLVM.VoidTypeInContext(context);
stackType = StackValueType.Unknown;
break;
case MetadataType.Boolean:
dataType = LLVM.Int8TypeInContext(context);
stackType = StackValueType.Int32;
break;
case MetadataType.Single:
dataType = LLVM.FloatTypeInContext(context);
stackType = StackValueType.Float;
break;
case MetadataType.Double:
dataType = LLVM.DoubleTypeInContext(context);
stackType = StackValueType.Float;
break;
case MetadataType.Char:
dataType = CharUsesUTF8
? LLVM.Int8TypeInContext(context)
: LLVM.Int16TypeInContext(context);
stackType = StackValueType.Int32;
break;
case MetadataType.Byte:
case MetadataType.SByte:
dataType = LLVM.Int8TypeInContext(context);
stackType = StackValueType.Int32;
break;
case MetadataType.Int16:
case MetadataType.UInt16:
dataType = LLVM.Int16TypeInContext(context);
stackType = StackValueType.Int32;
break;
case MetadataType.Int32:
case MetadataType.UInt32:
dataType = int32LLVM;
stackType = StackValueType.Int32;
break;
case MetadataType.Int64:
case MetadataType.UInt64:
dataType = int64LLVM;
stackType = StackValueType.Int64;
break;
case MetadataType.UIntPtr:
case MetadataType.IntPtr:
dataType = intPtrLLVM;
stackType = StackValueType.NativeInt;
break;
case MetadataType.Array:
case MetadataType.String:
case MetadataType.TypedByReference:
case MetadataType.GenericInstance:
case MetadataType.ValueType:
case MetadataType.Class:
case MetadataType.Object:
{
// Open type?
if (typeDefinition.HasGenericParameters && !(typeReference is GenericInstanceType))
return null;
// When resolved, void becomes a real type
if (typeReference.FullName == typeof(void).FullName)
{
goto case MetadataType.Void;
}
if (typeDefinition.IsValueType && typeDefinition.IsEnum)
{
// Special case: enum
// Uses underlying type
var enumUnderlyingType = GetType(typeDefinition.GetEnumUnderlyingType(), TypeState.StackComplete);
dataType = enumUnderlyingType.DataTypeLLVM;
stackType = enumUnderlyingType.StackType;
}
else
{
stackType = typeDefinition.IsValueType ? StackValueType.Value : StackValueType.Object;
dataType = GenerateDataType(typeReference);
}
valueType = dataType;
break;
}
default:
throw new NotImplementedException();
}
// Create class version (boxed version with VTable)
var boxedType = LLVM.StructCreateNamed(context, typeReference.MangledName() + ".class");
if (valueType == TypeRef.Empty)
valueType = LLVM.StructCreateNamed(context, typeReference.MangledName() + ".value");
result = new Type(typeReference, typeDefinition, dataType, valueType, boxedType, stackType);
types.Add(typeReference, result);
// Enqueue class generation, if needed
EmitType(result);
return result;
}
示例3: GenerateDataType
private TypeRef GenerateDataType(TypeReference typeReference)
{
TypeRef dataType;
var typeDefinition = GetMethodTypeDefinition(typeReference);
// Struct / Class
// Auto layout or Sequential Layout with packing size 0 (auto) will result in normal LLVM struct (optimized for target)
// Otherwise (Explicit layout or Sequential layout with custom packing), make a i8 array and access field with GEP in it.
if (IsCustomLayout(typeDefinition))
{
var classSize = ComputeClassSize(typeDefinition, typeReference);
dataType = LLVM.ArrayType(LLVM.Int8TypeInContext(context), (uint)classSize);
}
else
{
dataType = LLVM.StructCreateNamed(context, typeReference.MangledName() + ".data");
}
return dataType;
}
示例4: BuildType
//.........这里部分代码省略.........
case MetadataType.Void:
dataType = LLVM.VoidTypeInContext(context);
stackType = StackValueType.Unknown;
break;
case MetadataType.Boolean:
dataType = LLVM.Int8TypeInContext(context);
stackType = StackValueType.Int32;
break;
case MetadataType.Single:
dataType = LLVM.FloatTypeInContext(context);
stackType = StackValueType.Float;
break;
case MetadataType.Double:
dataType = LLVM.DoubleTypeInContext(context);
stackType = StackValueType.Float;
break;
case MetadataType.Char:
dataType = CharUsesUTF8
? LLVM.Int8TypeInContext(context)
: LLVM.Int16TypeInContext(context);
stackType = StackValueType.Int32;
break;
case MetadataType.Byte:
case MetadataType.SByte:
dataType = LLVM.Int8TypeInContext(context);
stackType = StackValueType.Int32;
break;
case MetadataType.Int16:
case MetadataType.UInt16:
dataType = LLVM.Int16TypeInContext(context);
stackType = StackValueType.Int32;
break;
case MetadataType.Int32:
case MetadataType.UInt32:
dataType = int32Type;
stackType = StackValueType.Int32;
break;
case MetadataType.Int64:
case MetadataType.UInt64:
dataType = int64Type;
stackType = StackValueType.Int64;
break;
case MetadataType.UIntPtr:
case MetadataType.IntPtr:
dataType = intPtrType;
stackType = StackValueType.NativeInt;
break;
case MetadataType.Array:
case MetadataType.String:
case MetadataType.TypedByReference:
case MetadataType.GenericInstance:
case MetadataType.ValueType:
case MetadataType.Class:
case MetadataType.Object:
{
// When resolved, void becomes a real type
if (typeReference.FullName == typeof(void).FullName)
{
goto case MetadataType.Void;
}
var typeDefinition = GetMethodTypeDefinition(typeReference);
if (typeDefinition.IsValueType && typeDefinition.IsEnum)
{
// Special case: enum
var enumUnderlyingType = GetType(typeDefinition.GetEnumUnderlyingType());
dataType = enumUnderlyingType.DataType;
stackType = enumUnderlyingType.StackType;
}
else
{
dataType = LLVM.StructCreateNamed(context, typeReference.MangledName() + ".data");
stackType = typeDefinition.IsValueType ? StackValueType.Value : StackValueType.Object;
}
valueType = dataType;
break;
}
default:
throw new NotImplementedException();
}
// Create class version (boxed version with VTable)
var boxedType = LLVM.StructCreateNamed(context, typeReference.MangledName() + ".class");
if (valueType == TypeRef.Empty)
valueType = LLVM.StructCreateNamed(context, typeReference.MangledName() + ".value");
var result = new Type(typeReference, dataType, valueType, boxedType, stackType);
bool isLocal = typeReference.Resolve().Module.Assembly == assembly;
// Manually emit Array classes locally (until proper mscorlib + generic instantiation exists).
isLocal |= typeReference.MetadataType == MetadataType.Array;
if (isLocal)
EmitType(result);
return result;
}
示例5: GetOrCreateGenerateDelegateWrapper
// TODO: This method is quite incomplete. It would be good to synchronize it with MarshalCodeGenerator.Process() (with Native/Managed swapped)
public static MethodDefinition GetOrCreateGenerateDelegateWrapper(AssemblyDefinition currentAssembly, TypeReference multicastDelegateType)
{
var multicastDelegateTypeResolved = multicastDelegateType.Resolve();
// Try to find method in assembly where delegate is defined
var delegateWrapper = GetDelegateWrapper(multicastDelegateTypeResolved.Module, multicastDelegateType);
if (delegateWrapper != null)
return delegateWrapper;
// Try to find method in current assembly
delegateWrapper = GetDelegateWrapper(currentAssembly.MainModule, multicastDelegateType);
if (delegateWrapper != null)
return delegateWrapper;
// Not found, let's create it in current assembly
// First, get or create DelegateWrappers static class
var delegateWrappersType = currentAssembly.MainModule.GetType("DelegateWrappers");
if (delegateWrappersType == null)
{
delegateWrappersType = new TypeDefinition(string.Empty, "DelegateWrappers", TypeAttributes.Class | TypeAttributes.Sealed | TypeAttributes.Abstract);
currentAssembly.MainModule.Types.Add(delegateWrappersType);
}
var invokeMethod = multicastDelegateTypeResolved.Methods.First(x => x.Name == "Invoke");
//var returnMarshaller = FindMarshallerForType(context.SourceEmitters.Peek().Type, field.MarshalInfo);
delegateWrapper = new MethodDefinition(multicastDelegateType.MangledName(), MethodAttributes.Static, currentAssembly.MainModule.Import(ResolveGenericsVisitor.Process(multicastDelegateType, invokeMethod.ReturnType)));
// Determine calling convention
var callingConvention = CallingConvention.Winapi; // Set default
// If there is a UnmanagedFunctionPointerAttribute, get its value
var unmanagedFunctionPointerAttribute = multicastDelegateTypeResolved.HasCustomAttributes ? multicastDelegateTypeResolved.CustomAttributes.FirstOrDefault(x => x.AttributeType.FullName == typeof(UnmanagedFunctionPointerAttribute).FullName) : null;
if (unmanagedFunctionPointerAttribute != null)
callingConvention = (CallingConvention)unmanagedFunctionPointerAttribute.ConstructorArguments[0].Value;
// On Windows, Winapi (default) means StdCall; TODO: Other platforms
if (callingConvention == CallingConvention.Winapi)
callingConvention = CallingConvention.StdCall;
delegateWrapper.CallingConvention = callingConvention.ToCecil();
foreach (var parameter in invokeMethod.Parameters)
{
delegateWrapper.Parameters.Add(new ParameterDefinition(parameter.Name, parameter.Attributes, currentAssembly.MainModule.Import(parameter.ParameterType)));
}
// Extract delegate from thunk table
var corlib = currentAssembly.MainModule.Import(typeof(void)).Resolve().Module.Assembly;
var marshalHelper = corlib.MainModule.GetType("SharpLang.Marshalling.MarshalHelper");
var getDelegate = currentAssembly.MainModule.Import(marshalHelper.Methods.First(x => x.Name == "GetDelegate"));
// Get delegate
var ilProcessor = delegateWrapper.Body.GetILProcessor();
ilProcessor.Emit(OpCodes.Call, getDelegate);
// TODO: Convert parameters
foreach (var parameter in invokeMethod.Parameters)
{
ilProcessor.Emit(OpCodes.Ldarg, parameter);
}
// Delegate.Invoke
ilProcessor.Emit(OpCodes.Call, currentAssembly.MainModule.Import(invokeMethod));
ilProcessor.Emit(OpCodes.Ret);
delegateWrapper.Body.UpdateInstructionOffsets();
// TODO: Convert out parameters
// Add MarshalFunctionAttribute
var typeType = currentAssembly.MainModule.Import(typeof(System.Type));
var marshalFunctionAttribute = corlib.MainModule.GetType("SharpLang.Marshalling.MarshalFunctionAttribute");
var marshalFunctionAttributeCtor = currentAssembly.MainModule.Import(marshalFunctionAttribute.Methods.Single(x => x.IsConstructor));
delegateWrapper.CustomAttributes.Add(new CustomAttribute(marshalFunctionAttributeCtor) { ConstructorArguments = { new CustomAttributeArgument(typeType, multicastDelegateType) } });
delegateWrappersType.Methods.Add(delegateWrapper);
return delegateWrapper;
}