本文介绍了我们可以构造的'欧普code`的实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在.NET Framework 4.0中引入了几个项目的反射API,范围从非常有用的生命对我的工作。在这些被保护的构造函数组装模块 MethodBody LocalVariableInfo 及新一个CustomAttributeData 类。有几个项目我还需要一个相当麻烦的解决。我相信他们很容易地适用于同一[小]一群人需要延长我刚刚上市的类型。

The .NET Framework 4.0 introduces several items to the Reflection API that range from extremely useful to vital for my work. Among these are protected constructors for Assembly, Module, MethodBody, and LocalVariableInfo and the new CustomAttributeData class. There are a couple items I still need that are quite troublesome to work around. I believe they easily apply to the same [small] group of people would need to extend the types I just listed.

这个时候:我正在寻找一种方式来构建的结构用我自己的参数。目前,我调用内部的构造函数来创建实例。这不是有损于性能,因为我揭露建造的项目,如公共静态只读 A级重用的成员,但你能想象这是一个极其次优的方案。

This time: I'm looking for a way to construct an instance of the System.Reflection.Emit.OpCode struct with my own parameters. I currently invoke the internal constructor to create the instances. It's not detrimental to performance because I expose the constructed items as public static readonly members of a class for reuse, but as you can imagine this is an extremely sub-optimal scenario.

是否有任何理由,不可能使目前的内部欧普code 构造公众提供文件,指出用户构建欧普code S不能使用的ILGenerator

Is there any reason it is not possible to make the current internal OpCode constructor public with documentation that states user-constructed OpCodes cannot be used with ILGenerator.

编辑:下面是一个例子。通过创建以下的自定义操作code,我可以使用它在说明一些中间表之间的字节code的转换,而不诉诸创建临时局部变量。如果我是发射IL,我会转换其余交换的说明为有效IL重presentation,但对我来说,下一步是JIT的理解自交换指令。我使用了 prefix2 preFIX 是0xFD ,这是保留的,未使用任何有效的IL运codeS。

Here's an example. By creating the following custom opcode, I'm able to use it in byte code transformations between some intermediate lists of instructions without resorting to creating temporary local variables. If I were emitting IL, I'd convert the remaining swap instructions to a valid IL representation, but in my case the next step is a JIT that understands the custom swap instruction. I'm using the Prefix2 prefix 0xFD, which is reserved and unused by any valid IL opcodes.

/// <summary>
/// Swaps adjacent elements on the evaluation stack. The supplied inline int32 argument gives the
/// index of the topmost item in the pair.
/// </summary>
public static readonly OpCode Swap;

我也可以用这个为JIT内部函数没有一个简单的/公共管理code再presentation,但有一个简单的平台依赖性重presentation在不同的本土$可用C $Ç发电机。其中之一是 ldthread (加载一个参考目前管理线程的 RuntimeThread 重presentation)。

I'll also be using this for JIT intrinsics that don't have a simple/common managed code representation but have a simple platform-dependent representation available in the various native code generators. One of these is ldthread (loads a reference to the current managed thread's RuntimeThread representation).

推荐答案

你为什么不使用我们自己的IL-运算codeS的中间结果,然后将其转化为实际的运算codeS在最后一步。

Why don't you use our own IL-Opcodes for the intermediate results and then convert them to real opcodes in the last step.

这篇关于我们可以构造的'欧普code`的实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 15:13