private void EmitLabel(ILLabel label, int startOfNextInstruction)
{
if (label as DynamicILLabel == null)
throw new ArgumentNullException("label");
var label2 = (DynamicILLabel)label;
if (label2.ILGenerator != this)
throw new ArgumentException("The label wasn't created by this generator.", "label");
// Enlarge the array if necessary.
if (this.offset + 4 >= this.bytes.Length)
EnlargeArray(4);
if (label2.ILOffset >= 0)
{
// The label is defined.
EmitInt32(label2.ILOffset - startOfNextInstruction);
}
else
{
// The label is not defined. Add a fix up.
EmitInt32(0);
this.fixups.Add(new Fixup() { Position = this.offset - 4, Length = 4, StartOfNextInstruction = startOfNextInstruction, Label = label2 });
}
#if DEBUG
if (label2.EvaluationStack == null)
{
// Copy the evaluation stack.
label2.EvaluationStack = this.operands.ToArray();
}
else
{
// Check the evaluation stack.
var previousStack = (VESType[])label2.EvaluationStack;
var currentStack = this.operands.ToArray();
if (previousStack.Length != currentStack.Length)
throw new InvalidOperationException(string.Format("Stack mismatch from a previous branch. Expected: '{0}' but was: '{1}'",
StringHelpers.Join(", ", previousStack), StringHelpers.Join(", ", currentStack)));
for (int i = 0; i < previousStack.Length; i++)
if (previousStack[i] != currentStack[i])
throw new InvalidOperationException(string.Format("Stack mismatch from a previous branch. Expected: '{0}' but was: '{1}'",
StringHelpers.Join(", ", previousStack), StringHelpers.Join(", ", currentStack)));
}
#else
if (label2.EvaluationStackSize < 0)
{
// Record the number of items on the evaluation stack.
label2.EvaluationStackSize = this.stackSize;
}
else
{
// Check the number of items matches.
if (label2.EvaluationStackSize != this.stackSize)
throw new InvalidOperationException(string.Format("Stack size mismatch from a previous branch. Expected {0} items but was {1} items.",
label2.EvaluationStackSize, this.stackSize));
}
#endif
}