本文整理汇总了C#中System.Reflection.MethodInfo.Decompile方法的典型用法代码示例。如果您正苦于以下问题:C# MethodInfo.Decompile方法的具体用法?C# MethodInfo.Decompile怎么用?C# MethodInfo.Decompile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.MethodInfo
的用法示例。
在下文中一共展示了MethodInfo.Decompile方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: JitCompiler
private JitCompiler(CpuConfig config, Type t_kernel, TypeBuilder t_xformed)
{
_config = config;
_t_kernel = t_kernel;
_m_kernel = _t_kernel.GetMethod("RunKernel", BF.All);
ValidateInputParameters();
// todo. think how to support multiple methods: *Dims, *Idxes, synchronization points
// todo. I'd even say that we should embed constants instead of Dims and cache such bodies between calls
// todo. if some dimension is equal to 1, then strip off corresponding loop
var lam = _m_kernel.Decompile();
_hir = lam.Body;
_params = lam.Sig.Syms;
_locals = lam.Body.LocalsRecursive();
_xhir = new Block();
_tids.Add("x", new Local("tid_x", typeof(int)));
_tids.Add("y", new Local("tid_y", typeof(int)));
_tids.Add("z", new Local("tid_z", typeof(int)));
_xhir.Locals.AddElements(_tids.Values);
InferLocalAllocationHints();
ReplicatePrivatelyAllocatedLocals();
LiftLocallyAllocatedLocals();
HoistGloballyAllocatedLocals();
_callsToSyncThreads = _hir.Family().OfType<Eval>().Where(eval =>
{
var m1 = eval.InvokedMethod();
var syncapi_syncThreads = typeof(ISyncApi).GetMethod("SyncThreads");
return m1.Api() == syncapi_syncThreads;
}).ToReadOnly();
TransformBlock(_hir, _xhir, false);
// todo. currently we don't support debuggable IL
// the latter implies correct PDB-mappings and working watch for replicated vars
_config.EmitDebuggableIL.AssertFalse();
_t_xformed = t_xformed;
_t_xformed.AddInterfaceImplementation(typeof(IBlockRunner));
_m_xformed = _t_xformed.DefineMethod("RunBlock", MA.Public, typeof(void), typeof(int3).MkArray());
_m_xformed.DefineParameter(1, ParmA.None, "blockIdx");
CompileTransformedHir();
}
示例2: Decompile
Expression Decompile(MethodInfo method, Expression instance, IList<Expression> arguments)
{
var expression = method.Decompile();
var expressions = new Dictionary<Expression, Expression>();
var argIndex = 0;
for (var index = 0; index < expression.Parameters.Count; index++)
{
var parameter = expression.Parameters[index];
if (index == 0 && method.IsStatic == false)
{
expressions.Add(parameter, instance);
}
else
{
expressions.Add(parameter, arguments[argIndex++]);
}
}
return Visit(new ReplaceExpressionVisitor(expressions).Visit(expression.Body));
}
示例3: EmitFunction
private static Function EmitFunction(Context context, Module module, MethodInfo method)
{
var funcType = new FunctionType(ConvertType(context, method.ReturnType), AnalyzeArguments(context, method.GetParameters()));
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(method.Name, funcType);
var block = new Block("entry", context, function);
var writer = new InstructionBuilder(context, block);
var opcodes = method.Decompile().ToList();
FindBranchTargets(opcodes, context, function);
var body = method.GetMethodBody();
var efo = new EmitFuncObj(context, module, function, writer, null, new Stack<Value>(),
body == null ? null : new Value[body.LocalVariables.Count], new Value[method.GetParameters().Length]);
foreach (var opcode in opcodes)
{
if (EmitFunctions.ContainsKey(opcode.Opcode) == false)
throw new Exception("Unsupported CIL instruction " + opcode.Opcode);
var func = EmitFunctions[opcode.Opcode];
efo.Argument = opcode.Parameter;
func(efo);
}
return function;
}