< Summary

Line coverage
0%
Covered lines: 0
Uncovered lines: 49
Coverable lines: 49
Total lines: 240
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 76
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
IsBranch(...)0%440%
GetBranchOperandSize(...)0%10100%
GetShortBranch(...)0%31310%
GetLongBranch(...)0%31310%

File(s)

https://raw.githubusercontent.com/dotnet/runtime/811a7eabb75c42db53440e8ba3f60c07511cfd1f/src/libraries/System.Reflection.Metadata/src/System/Reflection/Metadata/IL/ILOpCodeExtensions.cs

#LineLine coverage
 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
 4namespace System.Reflection.Metadata
 5{
 6    public static partial class ILOpCodeExtensions
 7    {
 8        /// <summary>
 9        /// Returns true of the specified op-code is a branch to a label.
 10        /// </summary>
 11        public static bool IsBranch(this ILOpCode opCode)
 012        {
 013            switch (opCode)
 14            {
 15                case ILOpCode.Br:
 16                case ILOpCode.Br_s:
 17                case ILOpCode.Brtrue:
 18                case ILOpCode.Brtrue_s:
 19                case ILOpCode.Brfalse:
 20                case ILOpCode.Brfalse_s:
 21                case ILOpCode.Beq:
 22                case ILOpCode.Beq_s:
 23                case ILOpCode.Bne_un:
 24                case ILOpCode.Bne_un_s:
 25                case ILOpCode.Bge:
 26                case ILOpCode.Bge_s:
 27                case ILOpCode.Bge_un:
 28                case ILOpCode.Bge_un_s:
 29                case ILOpCode.Bgt:
 30                case ILOpCode.Bgt_s:
 31                case ILOpCode.Bgt_un:
 32                case ILOpCode.Bgt_un_s:
 33                case ILOpCode.Ble:
 34                case ILOpCode.Ble_s:
 35                case ILOpCode.Ble_un:
 36                case ILOpCode.Ble_un_s:
 37                case ILOpCode.Blt:
 38                case ILOpCode.Blt_s:
 39                case ILOpCode.Blt_un:
 40                case ILOpCode.Blt_un_s:
 41                case ILOpCode.Leave:
 42                case ILOpCode.Leave_s:
 043                    return true;
 44            }
 45
 046            return false;
 047        }
 48
 49        /// <summary>
 50        /// Calculate the size of the specified branch instruction operand.
 51        /// </summary>
 52        /// <param name="opCode">Branch op-code.</param>
 53        /// <returns>1 if <paramref name="opCode"/> is a short branch or 4 if it is a long branch.</returns>
 54        /// <exception cref="ArgumentException">Specified <paramref name="opCode"/> is not a branch op-code.</exception>
 55        public static int GetBranchOperandSize(this ILOpCode opCode)
 056        {
 057            switch (opCode)
 58            {
 59                case ILOpCode.Br_s:
 60                case ILOpCode.Brfalse_s:
 61                case ILOpCode.Brtrue_s:
 62                case ILOpCode.Beq_s:
 63                case ILOpCode.Bge_s:
 64                case ILOpCode.Bgt_s:
 65                case ILOpCode.Ble_s:
 66                case ILOpCode.Blt_s:
 67                case ILOpCode.Bne_un_s:
 68                case ILOpCode.Bge_un_s:
 69                case ILOpCode.Bgt_un_s:
 70                case ILOpCode.Ble_un_s:
 71                case ILOpCode.Blt_un_s:
 72                case ILOpCode.Leave_s:
 073                    return 1;
 74
 75                case ILOpCode.Br:
 76                case ILOpCode.Brfalse:
 77                case ILOpCode.Brtrue:
 78                case ILOpCode.Beq:
 79                case ILOpCode.Bge:
 80                case ILOpCode.Bgt:
 81                case ILOpCode.Ble:
 82                case ILOpCode.Blt:
 83                case ILOpCode.Bne_un:
 84                case ILOpCode.Bge_un:
 85                case ILOpCode.Bgt_un:
 86                case ILOpCode.Ble_un:
 87                case ILOpCode.Blt_un:
 88                case ILOpCode.Leave:
 089                    return 4;
 90            }
 91
 092            throw new ArgumentException(SR.Format(SR.UnexpectedOpCode, opCode), nameof(opCode));
 093        }
 94
 95        /// <summary>
 96        /// Get a short form of the specified branch op-code.
 97        /// </summary>
 98        /// <param name="opCode">Branch op-code.</param>
 99        /// <returns>Short form of the branch op-code.</returns>
 100        /// <exception cref="ArgumentException">Specified <paramref name="opCode"/> is not a branch op-code.</exception>
 101        public static ILOpCode GetShortBranch(this ILOpCode opCode)
 0102        {
 0103            switch (opCode)
 104            {
 105                case ILOpCode.Br_s:
 106                case ILOpCode.Brfalse_s:
 107                case ILOpCode.Brtrue_s:
 108                case ILOpCode.Beq_s:
 109                case ILOpCode.Bge_s:
 110                case ILOpCode.Bgt_s:
 111                case ILOpCode.Ble_s:
 112                case ILOpCode.Blt_s:
 113                case ILOpCode.Bne_un_s:
 114                case ILOpCode.Bge_un_s:
 115                case ILOpCode.Bgt_un_s:
 116                case ILOpCode.Ble_un_s:
 117                case ILOpCode.Blt_un_s:
 118                case ILOpCode.Leave_s:
 0119                    return opCode;
 120
 121                case ILOpCode.Br:
 0122                    return ILOpCode.Br_s;
 123
 124                case ILOpCode.Brfalse:
 0125                    return ILOpCode.Brfalse_s;
 126
 127                case ILOpCode.Brtrue:
 0128                    return ILOpCode.Brtrue_s;
 129
 130                case ILOpCode.Beq:
 0131                    return ILOpCode.Beq_s;
 132
 133                case ILOpCode.Bge:
 0134                    return ILOpCode.Bge_s;
 135
 136                case ILOpCode.Bgt:
 0137                    return ILOpCode.Bgt_s;
 138
 139                case ILOpCode.Ble:
 0140                    return ILOpCode.Ble_s;
 141
 142                case ILOpCode.Blt:
 0143                    return ILOpCode.Blt_s;
 144
 145                case ILOpCode.Bne_un:
 0146                    return ILOpCode.Bne_un_s;
 147
 148                case ILOpCode.Bge_un:
 0149                    return ILOpCode.Bge_un_s;
 150
 151                case ILOpCode.Bgt_un:
 0152                    return ILOpCode.Bgt_un_s;
 153
 154                case ILOpCode.Ble_un:
 0155                    return ILOpCode.Ble_un_s;
 156
 157                case ILOpCode.Blt_un:
 0158                    return ILOpCode.Blt_un_s;
 159
 160                case ILOpCode.Leave:
 0161                    return ILOpCode.Leave_s;
 162            }
 163
 0164            throw new ArgumentException(SR.Format(SR.UnexpectedOpCode, opCode), nameof(opCode));
 0165        }
 166
 167        /// <summary>
 168        /// Get a long form of the specified branch op-code.
 169        /// </summary>
 170        /// <param name="opCode">Branch op-code.</param>
 171        /// <returns>Long form of the branch op-code.</returns>
 172        /// <exception cref="ArgumentException">Specified <paramref name="opCode"/> is not a branch op-code.</exception>
 173        public static ILOpCode GetLongBranch(this ILOpCode opCode)
 0174        {
 0175            switch (opCode)
 176            {
 177                case ILOpCode.Br:
 178                case ILOpCode.Brfalse:
 179                case ILOpCode.Brtrue:
 180                case ILOpCode.Beq:
 181                case ILOpCode.Bge:
 182                case ILOpCode.Bgt:
 183                case ILOpCode.Ble:
 184                case ILOpCode.Blt:
 185                case ILOpCode.Bne_un:
 186                case ILOpCode.Bge_un:
 187                case ILOpCode.Bgt_un:
 188                case ILOpCode.Ble_un:
 189                case ILOpCode.Blt_un:
 190                case ILOpCode.Leave:
 0191                    return opCode;
 192
 193                case ILOpCode.Br_s:
 0194                    return ILOpCode.Br;
 195
 196                case ILOpCode.Brfalse_s:
 0197                    return ILOpCode.Brfalse;
 198
 199                case ILOpCode.Brtrue_s:
 0200                    return ILOpCode.Brtrue;
 201
 202                case ILOpCode.Beq_s:
 0203                    return ILOpCode.Beq;
 204
 205                case ILOpCode.Bge_s:
 0206                    return ILOpCode.Bge;
 207
 208                case ILOpCode.Bgt_s:
 0209                    return ILOpCode.Bgt;
 210
 211                case ILOpCode.Ble_s:
 0212                    return ILOpCode.Ble;
 213
 214                case ILOpCode.Blt_s:
 0215                    return ILOpCode.Blt;
 216
 217                case ILOpCode.Bne_un_s:
 0218                    return ILOpCode.Bne_un;
 219
 220                case ILOpCode.Bge_un_s:
 0221                    return ILOpCode.Bge_un;
 222
 223                case ILOpCode.Bgt_un_s:
 0224                    return ILOpCode.Bgt_un;
 225
 226                case ILOpCode.Ble_un_s:
 0227                    return ILOpCode.Ble_un;
 228
 229                case ILOpCode.Blt_un_s:
 0230                    return ILOpCode.Blt_un;
 231
 232                case ILOpCode.Leave_s:
 0233                    return ILOpCode.Leave;
 234            }
 235
 0236            throw new ArgumentException(SR.Format(SR.UnexpectedOpCode, opCode), nameof(opCode));
 0237        }
 238    }
 239}
 240