Browse Source

ILAst: make 'Return' less of a special case

(don't let the slot contents have an effect on the number of slots)
pull/728/head
Daniel Grunwald 10 years ago
parent
commit
e2c0f40f71
  1. 2
      ICSharpCode.Decompiler/IL/Instructions/ILInstruction.cs
  2. 19
      ICSharpCode.Decompiler/IL/Instructions/Return.cs

2
ICSharpCode.Decompiler/IL/Instructions/ILInstruction.cs

@ -407,7 +407,7 @@ namespace ICSharpCode.Decompiler.IL @@ -407,7 +407,7 @@ namespace ICSharpCode.Decompiler.IL
protected internal void SetChildInstruction(ref ILInstruction childPointer, ILInstruction newValue, int index)
{
ILInstruction oldValue = childPointer;
Debug.Assert(this is Return || oldValue == GetChild(index));
Debug.Assert(oldValue == GetChild(index));
if (oldValue == newValue)
return;
childPointer = newValue;

19
ICSharpCode.Decompiler/IL/Instructions/Return.cs

@ -26,6 +26,7 @@ namespace ICSharpCode.Decompiler.IL @@ -26,6 +26,7 @@ namespace ICSharpCode.Decompiler.IL
{
public static readonly SlotInfo ReturnValueSlot = new SlotInfo("ReturnValue", canInlineInto: true);
readonly bool hasArgument;
ILInstruction returnValue;
/// <summary>
@ -34,9 +35,12 @@ namespace ICSharpCode.Decompiler.IL @@ -34,9 +35,12 @@ namespace ICSharpCode.Decompiler.IL
public ILInstruction ReturnValue {
get { return returnValue; }
set {
if (value != null)
if (hasArgument) {
ValidateChild(value);
SetChildInstruction(ref returnValue, value, 0);
SetChildInstruction(ref returnValue, value, 0);
} else {
Debug.Assert(value == null);
}
}
}
@ -46,13 +50,14 @@ namespace ICSharpCode.Decompiler.IL @@ -46,13 +50,14 @@ namespace ICSharpCode.Decompiler.IL
public Return(ILInstruction argument) : base(OpCode.Return)
{
this.hasArgument = true;
this.ReturnValue = argument;
}
public override ILInstruction Clone()
{
Return clone = (Return)ShallowClone();
if (returnValue != null)
if (hasArgument)
clone.ReturnValue = returnValue.Clone();
return clone;
}
@ -60,7 +65,7 @@ namespace ICSharpCode.Decompiler.IL @@ -60,7 +65,7 @@ namespace ICSharpCode.Decompiler.IL
protected override InstructionFlags ComputeFlags()
{
InstructionFlags flags = InstructionFlags.MayBranch | InstructionFlags.EndPointUnreachable;
if (returnValue != null) {
if (hasArgument) {
flags |= returnValue.Flags;
}
return flags;
@ -78,12 +83,12 @@ namespace ICSharpCode.Decompiler.IL @@ -78,12 +83,12 @@ namespace ICSharpCode.Decompiler.IL
protected override int GetChildCount()
{
return returnValue != null ? 1 : 0;
return hasArgument ? 1 : 0;
}
protected override ILInstruction GetChild(int index)
{
if (index == 0 && returnValue != null)
if (index == 0 && hasArgument)
return returnValue;
else
throw new IndexOutOfRangeException();
@ -91,7 +96,7 @@ namespace ICSharpCode.Decompiler.IL @@ -91,7 +96,7 @@ namespace ICSharpCode.Decompiler.IL
protected override void SetChild(int index, ILInstruction value)
{
if (index == 0 && returnValue != null)
if (index == 0 && hasArgument)
ReturnValue = value;
else
throw new IndexOutOfRangeException();

Loading…
Cancel
Save