本文整理汇总了C#中System.Reflection.MethodBase.Disassemble方法的典型用法代码示例。如果您正苦于以下问题:C# MethodBase.Disassemble方法的具体用法?C# MethodBase.Disassemble怎么用?C# MethodBase.Disassemble使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.MethodBase
的用法示例。
在下文中一共展示了MethodBase.Disassemble方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EmitFunction
private static Function EmitFunction(Module module, MethodBase method)
{
var methodInfo = method as MethodInfo;
var methodConstructor = method as ConstructorInfo;
var declaringType = method.DeclaringType;
if (methodInfo == null && methodConstructor == null)
throw new CudaSharpException("Unknown MethodBase type " + method.GetType().FullName);
if (declaringType == null)
throw new CudaSharpException("Could not find the declaring type of " + method.Name.StripNameToValidPtx());
var parameters = method.GetParameters().Select(p => p.ParameterType);
if (methodConstructor != null)
parameters = new[] { declaringType.MakeByRefType() }.Concat(parameters);
if (methodInfo != null && methodInfo.IsStatic == false)
{
if (declaringType.IsValueType == false)
throw new CudaSharpException("Cannot compile object instance methods (did you forget to mark the method as static?)");
parameters = new[] { declaringType.MakeByRefType() }.Concat(parameters);
}
var llvmParameters =
parameters.Select(t => ConvertType(module, t)).ToArray();
var funcType = new FunctionType(ConvertType(module, methodInfo == null ? typeof(void) : methodInfo.ReturnType), llvmParameters);
var intrinsic = method.GetCustomAttribute<Gpu.BuiltinAttribute>();
if (intrinsic != null)
{
var name = intrinsic.Intrinsic;
var preExisting = module.GetFunction(name);
if (preExisting != null)
return preExisting;
return module.CreateFunction(name, funcType);
}
var function = module.CreateFunction(methodConstructor == null ? method.Name.StripNameToValidPtx() : declaringType.Name.StripNameToValidPtx() + "_ctor", funcType);
var block = new Block("entry", module.Context, function);
var writer = new InstructionBuilder(module.Context, block);
var opcodes = method.Disassemble().ToList();
FindBranchTargets(opcodes, module.Context, function);
var body = method.GetMethodBody();
var efo = new EmitFuncObj(module, function, body, writer, null, new Stack<Value>(),
body == null ? null : new Value[body.LocalVariables.Count], new Value[llvmParameters.Length]);
PrintHeader(efo);
foreach (var opcode in opcodes)
{
if (EmitFunctions.ContainsKey(opcode.Opcode) == false)
throw new CudaSharpException("Unsupported CIL instruction " + opcode.Opcode);
var func = EmitFunctions[opcode.Opcode];
efo.Argument = opcode.Parameter;
func(efo);
}
return function;
}