| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System.Diagnostics; |
| | | 5 | | |
| | | 6 | | namespace System.Reflection.Metadata.Ecma335 |
| | | 7 | | { |
| | | 8 | | /// <summary> |
| | | 9 | | /// Encodes the branches of an IL <c>switch</c> instruction. |
| | | 10 | | /// </summary> |
| | | 11 | | /// <remarks> |
| | | 12 | | /// See <see cref="InstructionEncoder.Switch(int)"/> for usage guidelines. |
| | | 13 | | /// </remarks> |
| | | 14 | | public readonly struct SwitchInstructionEncoder |
| | | 15 | | { |
| | | 16 | | private readonly InstructionEncoder _encoder; |
| | | 17 | | |
| | | 18 | | private readonly int _ilOffset, _instructionEnd; |
| | | 19 | | |
| | | 20 | | internal SwitchInstructionEncoder(InstructionEncoder encoder, int ilOffset, int instructionEnd) |
| | 0 | 21 | | { |
| | 0 | 22 | | Debug.Assert(encoder.ControlFlowBuilder is not null); |
| | 0 | 23 | | _encoder = encoder; |
| | 0 | 24 | | _ilOffset = ilOffset; |
| | 0 | 25 | | _instructionEnd = instructionEnd; |
| | 0 | 26 | | } |
| | | 27 | | |
| | | 28 | | /// <summary> |
| | | 29 | | /// Encodes a branch that is part of a switch instruction. |
| | | 30 | | /// </summary> |
| | | 31 | | /// <remarks> |
| | | 32 | | /// See <see cref="InstructionEncoder.Switch(int)"/> for usage guidelines. |
| | | 33 | | /// </remarks> |
| | | 34 | | public void Branch(LabelHandle label) |
| | 0 | 35 | | { |
| | 0 | 36 | | _encoder.ControlFlowBuilder!.SwitchBranchAdded(); |
| | 0 | 37 | | _encoder.LabelOperand(ILOpCode.Switch, label, _instructionEnd - _encoder.Offset, _ilOffset); |
| | 0 | 38 | | } |
| | | 39 | | } |
| | | 40 | | } |
| | | 41 | | |