简体   繁体   English

C#/ CIL:native int的类型

[英]C#/CIL: type of native int

I am writing some tools to help validate IL that is emitted at runtime. 我正在编写一些工具来帮助验证在运行时发出的IL。 A part of this validation involves maintaining a Stack<Type> as OpCodes are emitted so that future OpCodes that utilize these stack elements can be validated as using the proper types. 此验证的一部分涉及在发出OpCode时维护Stack<Type> ,以便使用这些堆栈元素的未来OpCode可以使用适当的类型进行验证。 I am confused as to how to handle the ldind.i opcode, however. 然而,我对如何处理ldind.i操作码感到困惑。

The Microsoft documentation states: 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. ldind.i指令间接地将指定地址(类型为native int,&或*)的本机int值作为本机int加载到堆栈中。

In C#, native int is not defined, and I am confused as to what type most accurately represents this data. 在C#中,未定义native int,我对哪种类型最准确地表示此数据感到困惑。 How can I determine what its size is, and which C# type should be used to represent it? 如何确定其大小,以及应使用哪种C#类型来表示它? I am concerned it will vary by system hardware. 我担心它会因系统硬件而异。

To my mind, you'd be better off looking at how the VES is defined and using a dedicated enum to model the types on the stack rather than C# visible types. 在我看来,你最好看看如何定义VES并使用专用的枚举来模拟堆栈上的类型而不是C#可见类型。 Otherwise you're in for a rude surprise when we get to the floating point type. 否则,当我们进入浮点类型时,你会感到非常惊讶。

From MS Partition I.pdf 1 , Section 12.1: 来自MS Partition I.pdf 1 ,第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 . CLI模型使用评估堆栈[...]但是,CLI在其操作中仅支持存储在其评估堆栈int32int64native int上的值的这些类型的子集。 In addition, the CLI supports an internal data type to represent floating-point values on the internal evaluation stack. 此外,CLI支持内部数据类型以表示内部评估堆栈上的浮点值 The size of the internal data type is implementation-dependent. 内部数据类型的大小取决于实现。

So those, as well as things like references are the things you should track, and I'd recommend you do that with an explicit model of the VES Stack using its terms. 所以那些以及引用之类的东西都是你应该跟踪的东西,我建议你用VES Stack的显式模型使用它的术语。


1 ECMA C# and Common Language Infrastructure Standards 1 ECMA C#和通用语言基础设施标准

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM