Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
ControlFlowBuilder.cs
Go to the documentation of this file.
3
5
6public sealed class ControlFlowBuilder
7{
8 internal readonly struct BranchInfo
9 {
10 internal readonly int ILOffset;
11
12 internal readonly LabelHandle Label;
13
14 private readonly byte _opCode;
15
17
19 {
21 Label = label;
22 _opCode = (byte)opCode;
23 }
24
26 {
27 int num = labels[Label.Id - 1];
28 if (num < 0)
29 {
31 }
32 int num2 = 1 + (isShortBranch ? 1 : 4);
33 int num3 = num - (ILOffset + num2);
34 if (isShortBranch && (sbyte)num3 != num3)
35 {
37 }
38 return num3;
39 }
40 }
41
69
70 private readonly ImmutableArray<BranchInfo>.Builder _branches;
71
72 private readonly ImmutableArray<int>.Builder _labels;
73
75
77
79
80 internal int BranchCount => _branches.Count;
81
83
85 {
86 _branches = ImmutableArray.CreateBuilder<BranchInfo>();
87 _labels = ImmutableArray.CreateBuilder<int>();
88 }
89
90 internal void Clear()
91 {
93 _labels.Clear();
95 }
96
98 {
99 _labels.Add(-1);
100 return new LabelHandle(_labels.Count);
101 }
102
104 {
105 ValidateLabel(label, "label");
107 }
108
110 {
111 ValidateLabel(label, "label");
112 _labels[label.Id - 1] = ilOffset;
113 }
114
116 {
117 int num = _labels[label.Id - 1];
118 if (num < 0)
119 {
121 }
122 return num;
123 }
124
126 {
127 if (label.IsNil)
128 {
130 }
131 if (label.Id > _labels.Count)
132 {
134 }
135 }
136
141
146
155
161
174
176 {
178 int num = 0;
179 int num2 = 0;
180 int num3 = 0;
181 foreach (Blob blob in srcBuilder.GetBlobs())
182 {
183 while (true)
184 {
185 int num4 = Math.Min(branchInfo.ILOffset - num2, blob.Length - num3);
186 dstBuilder.WriteBytes(blob.Buffer, num3, num4);
187 num2 += num4;
188 num3 += num4;
189 if (num3 == blob.Length)
190 {
191 num3 = 0;
192 break;
193 }
194 int branchOperandSize = branchInfo.OpCode.GetBranchOperandSize();
195 bool flag = branchOperandSize == 1;
196 dstBuilder.WriteByte(blob.Buffer[num3]);
197 int branchDistance = branchInfo.GetBranchDistance(_labels, branchInfo.OpCode, num2, flag);
198 if (flag)
199 {
200 dstBuilder.WriteSByte((sbyte)branchDistance);
201 }
202 else
203 {
204 dstBuilder.WriteInt32(branchDistance);
205 }
206 num2 += 1 + branchOperandSize;
207 num++;
208 branchInfo = ((num != _branches.Count) ? _branches[num] : new BranchInfo(int.MaxValue, default(LabelHandle), ILOpCode.Nop));
209 if (num3 == blob.Length - 1)
210 {
212 break;
213 }
214 num3 += 1 + branchOperandSize;
215 }
216 }
217 }
218
220 {
222 {
223 return;
224 }
227 {
233 {
235 }
237 {
239 }
240 int catchTokenOrOffset = lazyExceptionHandler.Kind switch
241 {
242 ExceptionRegionKind.Catch => MetadataTokens.GetToken(lazyExceptionHandler.CatchType),
243 ExceptionRegionKind.Filter => GetLabelOffsetChecked(lazyExceptionHandler.FilterStart),
244 _ => 0,
245 };
247 }
248 }
249
265}
void Add(TKey key, TValue value)
static byte Min(byte val1, byte val2)
Definition Math.cs:912
void ValidateLabel(LabelHandle label, string parameterName)
void AddFilterRegion(LabelHandle tryStart, LabelHandle tryEnd, LabelHandle handlerStart, LabelHandle handlerEnd, LabelHandle filterStart)
readonly ImmutableArray< BranchInfo >.Builder _branches
void AddCatchRegion(LabelHandle tryStart, LabelHandle tryEnd, LabelHandle handlerStart, LabelHandle handlerEnd, EntityHandle catchType)
void CopyCodeAndFixupBranches(BlobBuilder srcBuilder, BlobBuilder dstBuilder)
void AddExceptionRegion(ExceptionRegionKind kind, LabelHandle tryStart, LabelHandle tryEnd, LabelHandle handlerStart, LabelHandle handlerEnd, LabelHandle filterStart=default(LabelHandle), EntityHandle catchType=default(EntityHandle))
ImmutableArray< ExceptionHandlerInfo >.Builder _lazyExceptionHandlers
readonly ImmutableArray< int >.Builder _labels
void AddFaultRegion(LabelHandle tryStart, LabelHandle tryEnd, LabelHandle handlerStart, LabelHandle handlerEnd)
void AddBranch(int ilOffset, LabelHandle label, ILOpCode opCode)
void AddFinallyRegion(LabelHandle tryStart, LabelHandle tryEnd, LabelHandle handlerStart, LabelHandle handlerEnd)
static int GetToken(this MetadataReader reader, EntityHandle handle)
static void ArgumentNull(string parameterName)
Definition Throw.cs:110
static void LabelDoesntBelongToBuilder(string parameterName)
Definition Throw.cs:82
static void InvalidOperation_LabelNotMarked(int id)
Definition Throw.cs:75
static void InvalidOperation(string message)
Definition Throw.cs:68
static Exception InvalidArgument_Handle(string parameterName)
Definition Throw.cs:40
static string InvalidExceptionRegionBounds
Definition SR.cs:240
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string DistanceBetweenInstructionAndLabelTooBig
Definition SR.cs:234
Definition SR.cs:7
readonly byte[] Buffer
Definition Blob.cs:5
int GetBranchDistance(ImmutableArray< int >.Builder labels, ILOpCode branchOpCode, int branchILOffset, bool isShortBranch)
BranchInfo(int ilOffset, LabelHandle label, ILOpCode opCode)
ExceptionHandlerInfo(ExceptionRegionKind kind, LabelHandle tryStart, LabelHandle tryEnd, LabelHandle handlerStart, LabelHandle handlerEnd, LabelHandle filterStart, EntityHandle catchType)
static bool IsSmallExceptionRegionFromBounds(int startOffset, int endOffset)
static ExceptionRegionEncoder SerializeTableHeader(BlobBuilder builder, int exceptionRegionCount, bool hasSmallRegions)