Closed
Description
Background and motivation
OpCodes represents MS IL instructions that used for emitting IL with ILGenerator. An OpCode
instruction may pop value(s) from stack as an operand of the instruction and also may push value(s) into the stack as a result. This stack change is needed for calculating MaxStack value that is essential for populating method body. I could use the StackBehaviourPop
and StackBehaviourPush
properties of OpCode
to calculate this, but there is an internal method that gives this info directly:
Making this public will be useful for calculating
MaxStack
fasterRelated to https://github.com/dotnet/runtime/pull/93244/files#r1353013060
API Proposal
namespace System.Reflection.Emit
public readonly partial struct OpCode : System.IEquatable<System.Reflection.Emit.OpCode>
{
...
public StackBehaviour StackBehaviourPop { get }
public StackBehaviour StackBehaviourPush { get }
...
+ public int EvaluationStackDelta { get }
}
Alternative Designs
Other naming options: EvaluationStackDelta
, StackSizeDelta
, StackTransitionDelta
or StackDepthDelta
as it is showing the difference of evaluation stack transition.
API Usage
private void UpdateStackSize(OpCode opCode)
{
_currentStack += opCode.EvaluationStackDelta;
_maxStackSize = Math.Max(_maxStackSize, _currentStack);
}