-
Notifications
You must be signed in to change notification settings - Fork 1
/
CompareAndBranch.cs
121 lines (109 loc) · 6.77 KB
/
CompareAndBranch.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
using System.Reflection.Emit;
using JetBrains.Annotations;
namespace ILGeneratorExtensions
{
/// <summary>
/// Contains extension methods for comparing objects on the stack
/// </summary>
public static partial class CompareAndBranch
{
/// <summary>
/// Pops a reference from the evaluation stack and branches to the given label if it is the null reference
/// </summary>
/// <param name="generator">The <see cref="T:System.Reflection.Emit.ILGenerator" /> to emit instructions from</param>
/// <param name="label">The label to branch to</param>
[PublicAPI]
public static ILGenerator BranchIfNull(this ILGenerator generator, Label label)
{
return generator.LoadNull()
.BranchIfEqual(label);
}
/// <summary>
/// Pops a reference from the evaluation stack and branches to the given label if it is the null reference
/// </summary>
/// <param name="generator">The <see cref="T:System.Reflection.Emit.ILGenerator" /> to emit instructions from</param>
/// <param name="labelName">The name of the fluently-specified label</param>
[PublicAPI]
public static ILGenerator BranchIfNull(this ILGenerator generator, string labelName)
=> generator.BranchIfNull(generator.GetOrCreateLabel(labelName));
/// <summary>
/// Pops a reference from the evaluation stack and branches to the given label if it is the null reference
/// </summary>
/// <param name="generator">The <see cref="T:System.Reflection.Emit.ILGenerator" /> to emit instructions from</param>
/// <param name="label">The label to branch to</param>
[PublicAPI]
public static ILGenerator BranchIfNullShortForm(this ILGenerator generator, Label label)
{
return generator.LoadNull()
.BranchIfEqualShortForm(label);
}
/// <summary>
/// Pops a reference from the evaluation stack and branches to the given label if it is the null reference
/// </summary>
/// <param name="generator">The <see cref="T:System.Reflection.Emit.ILGenerator" /> to emit instructions from</param>
/// <param name="labelName">The name of the fluently-specified label</param>
[PublicAPI]
public static ILGenerator BranchIfNullShortForm(this ILGenerator generator, string labelName)
=> generator.BranchIfNullShortForm(generator.GetOrCreateLabel(labelName));
/// <summary>
/// Pops an integer value from the evaluation stack and branches to the given label if it interprets as true
/// </summary>
/// <param name="generator">The <see cref="T:System.Reflection.Emit.ILGenerator" /> to emit instructions from</param>
/// <param name="label">The label to branch to</param>
[PublicAPI]
public static ILGenerator BranchIfTrue(this ILGenerator generator, Label label) => generator.FluentEmit(OpCodes.Brtrue, label);
/// <summary>
/// Pops an integer value from the evaluation stack and branches to the given label if it interprets as true
/// </summary>
/// <param name="generator">The <see cref="T:System.Reflection.Emit.ILGenerator" /> to emit instructions from</param>
/// <param name="labelName">The name of the fluently-specified label</param>
[PublicAPI]
public static ILGenerator BranchIfTrue(this ILGenerator generator, string labelName)
=> generator.BranchIfTrue(generator.GetOrCreateLabel(labelName));
/// <summary>
/// Pops an integer value from the evaluation stack and branches to the given label if it interprets as true
/// </summary>
/// <param name="generator">The <see cref="T:System.Reflection.Emit.ILGenerator" /> to emit instructions from</param>
/// <param name="label">The label to branch to</param>
[PublicAPI]
public static ILGenerator BranchIfTrueShortForm(this ILGenerator generator, Label label) => generator.FluentEmit(OpCodes.Brtrue_S, label);
/// <summary>
/// Pops an integer value from the evaluation stack and branches to the given label if it interprets as true
/// </summary>
/// <param name="generator">The <see cref="T:System.Reflection.Emit.ILGenerator" /> to emit instructions from</param>
/// <param name="labelName">The name of the fluently-specified label</param>
[PublicAPI]
public static ILGenerator BranchIfTrueShortForm(this ILGenerator generator, string labelName)
=> generator.BranchIfTrueShortForm(generator.GetOrCreateLabel(labelName));
/// <summary>
/// Pops an integer value from the evaluation stack and branches to the given label if it interprets as false
/// </summary>
/// <param name="generator">The <see cref="T:System.Reflection.Emit.ILGenerator" /> to emit instructions from</param>
/// <param name="label">The label to branch to</param>
[PublicAPI]
public static ILGenerator BranchIfFalse(this ILGenerator generator, Label label) => generator.FluentEmit(OpCodes.Brfalse, label);
/// <summary>
/// Pops an integer value from the evaluation stack and branches to the given label if it interprets as false
/// </summary>
/// <param name="generator">The <see cref="T:System.Reflection.Emit.ILGenerator" /> to emit instructions from</param>
/// <param name="labelName">The name of the fluently-specified label</param>
[PublicAPI]
public static ILGenerator BranchIfFalse(this ILGenerator generator, string labelName)
=> generator.BranchIfFalse(generator.GetOrCreateLabel(labelName));
/// <summary>
/// Pops an integer value from the evaluation stack and branches to the given label if it interprets as false
/// </summary>
/// <param name="generator">The <see cref="T:System.Reflection.Emit.ILGenerator" /> to emit instructions from</param>
/// <param name="label">The label to branch to</param>
[PublicAPI]
public static ILGenerator BranchIfFalseShortForm(this ILGenerator generator, Label label) => generator.FluentEmit(OpCodes.Brfalse_S, label);
/// <summary>
/// Pops an integer value from the evaluation stack and branches to the given label if it interprets as false
/// </summary>
/// <param name="generator">The <see cref="T:System.Reflection.Emit.ILGenerator" /> to emit instructions from</param>
/// <param name="labelName">The name of the fluently-specified label</param>
[PublicAPI]
public static ILGenerator BranchIfFalseShortForm(this ILGenerator generator, string labelName)
=> generator.BranchIfFalseShortForm(generator.GetOrCreateLabel(labelName));
}
}