编程语言
首页 > 编程语言> > C#/ CIL:本机int的类型

C#/ CIL:本机int的类型

作者:互联网

我正在编写一些工具来帮助验证运行时发出的IL.该验证的一部分涉及维护协议栈的Stack< Type>.因为会发出OpCode,因此可以验证使用这些堆栈元素的将来OpCode是否使用了正确的类型.但是,我对如何处理ldind.i操作码感到困惑.

Microsoft文档指出:

The ldind.i instruction indirectly loads a native int value from the
specified address (of type native int, &, or *) onto the stack as a
native int.

在C#中,未定义native int,对于哪种类型最准确地表示此数据,我感到困惑.我如何确定它的大小,以及应该使用哪种C#类型来表示它?我担心它会因系统硬件而异.

解决方法:

在我看来,最好还是看看VES是如何定义的,并使用专用的枚举为堆栈上的类型而不是C#可见类型建模.否则,当我们使用浮点数类型时,您会感到意外.

从MS Partition I.pdf1,第12.1节:

The CLI model uses an evaluation stack […] However, the CLI supports only a subset of these types in its operations upon values stored on its evaluation stack—int32, int64, and native int. In addition, the CLI supports an internal data type to represent floating-point values on the internal evaluation stack. The size of the internal data type is implementation-dependent.

因此,这些以及引用之类的东西都是您应该跟踪的东西,我建议您使用带有其术语的VES Stack显式模型进行此操作.

1ECMA C# and Common Language Infrastructure Standards

标签:cil,c
来源: https://codeday.me/bug/20191108/2006543.html