You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add InstructionEncoder.Switch to enable emitting switch instructions with LabelHandles #40546
It doesn't look like there's a way to use InstructionEncoder.DefineLabel's LabelHandles with a switch instruction. I'm mainly asking if there is a way to do it that I'm missing, but if not here's a basic API proposal to enable it.
Proposed API
namespace System.Reflection.Metadata.Ecma335
{
public readonly struct InstructionEncoder
{
+ public void Switch(params LabelHandle[] label);
}
}
Originally this proposal was based on emitting the label by itself:
namespace System.Reflection.Metadata.Ecma335
{
public readonly struct InstructionEncoder
{
+ public void Label(LabelHandle label);
}
}
This won't work because the target offset is based on the end of the switch instruction, not the offset of the label.
Also for it to work with switch like intended, it would need to only emit int32 offsets. That's not super clear from the name and would generate bad IL if someone were to do OpCode(ILOpCode.Br_s); Label(label);, even if it were based on the label's offset.
changed the title [-]Add InstructionEncoder.Label to emit LabelHandle offset for switch instructions[/-][+]Add InstructionEncoder.Switch to enable emitting switch instructions with LabelHandles[/+]on Aug 9, 2020
The original proposal had a clear usage example but the approved API leaves the intended functionality implicit. Am I correct in understanding the approved proposal as supposed to work in such a way that the originally suggested method is equivalent to the following InstructionEncoder method?
Activity
[-]Add InstructionEncoder.Label to emit LabelHandle offset for switch instructions[/-][+]Add InstructionEncoder.Switch to enable emitting switch instructions with LabelHandles[/+]teo-tsirpanis commentedon Aug 5, 2021
I think it should also have an overload for
IReadOnlyCollection<LabelHandle>, to allow high-performance apps to reuse aList<LabelHandle>.19 remaining items
teo-tsirpanis commentedon Aug 9, 2022
I will do it in a couple of months in time for 8.0.0, if someone else wants to do it, feel free to.
August-Alm commentedon Aug 15, 2022
The original proposal had a clear usage example but the approved API leaves the intended functionality implicit. Am I correct in understanding the approved proposal as supposed to work in such a way that the originally suggested method is equivalent to the following
InstructionEncodermethod?teo-tsirpanis commentedon Aug 15, 2022
@August-Alm yes.