Browse Source

Add variable ResultType to Ldlen instruction

pull/728/head
Siegfried Pammer 9 years ago
parent
commit
61fe3b4412
  1. 1
      ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj
  2. 2
      ICSharpCode.Decompiler/IL/ILReader.cs
  3. 22
      ICSharpCode.Decompiler/IL/Instructions.cs
  4. 2
      ICSharpCode.Decompiler/IL/Instructions.tt
  5. 52
      ICSharpCode.Decompiler/IL/Instructions/LdLen.cs
  6. 11
      ICSharpCode.Decompiler/IL/Instructions/PatternMatching.cs

1
ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj

@ -107,6 +107,7 @@
<Compile Include="IL\Instructions\ILFunction.cs" /> <Compile Include="IL\Instructions\ILFunction.cs" />
<Compile Include="IL\Instructions\ILInstruction.cs" /> <Compile Include="IL\Instructions\ILInstruction.cs" />
<Compile Include="IL\Instructions\InstructionCollection.cs" /> <Compile Include="IL\Instructions\InstructionCollection.cs" />
<Compile Include="IL\Instructions\LdLen.cs" />
<Compile Include="IL\Instructions\Leave.cs" /> <Compile Include="IL\Instructions\Leave.cs" />
<Compile Include="IL\Instructions\LocalVarInstructions.cs" /> <Compile Include="IL\Instructions\LocalVarInstructions.cs" />
<Compile Include="IL\Instructions\MemoryInstructions.cs" /> <Compile Include="IL\Instructions\MemoryInstructions.cs" />

2
ICSharpCode.Decompiler/IL/ILReader.cs

@ -711,7 +711,7 @@ namespace ICSharpCode.Decompiler.IL
case ILOpCode.Stfld: case ILOpCode.Stfld:
return new StFld(value: Pop(), target: Pop(), field: ReadAndDecodeFieldReference()); return new StFld(value: Pop(), target: Pop(), field: ReadAndDecodeFieldReference());
case ILOpCode.Ldlen: case ILOpCode.Ldlen:
return Push(new LdLen(Pop())); return Push(new LdLen(StackType.I, Pop()));
case ILOpCode.Ldobj: case ILOpCode.Ldobj:
return Push(new LdObj(Pop(), ReadAndDecodeTypeReference())); return Push(new LdObj(Pop(), ReadAndDecodeTypeReference()));
case ILOpCode.Ldsfld: case ILOpCode.Ldsfld:

22
ICSharpCode.Decompiler/IL/Instructions.cs

@ -2896,10 +2896,6 @@ namespace ICSharpCode.Decompiler.IL
/// <summary>Returns the length of an array as 'native unsigned int'.</summary> /// <summary>Returns the length of an array as 'native unsigned int'.</summary>
public sealed partial class LdLen : ILInstruction public sealed partial class LdLen : ILInstruction
{ {
public LdLen(ILInstruction array) : base(OpCode.LdLen)
{
this.Array = array;
}
public static readonly SlotInfo ArraySlot = new SlotInfo("Array", canInlineInto: true); public static readonly SlotInfo ArraySlot = new SlotInfo("Array", canInlineInto: true);
ILInstruction array; ILInstruction array;
public ILInstruction Array { public ILInstruction Array {
@ -2947,7 +2943,6 @@ namespace ICSharpCode.Decompiler.IL
clone.Array = this.array.Clone(); clone.Array = this.array.Clone();
return clone; return clone;
} }
public override StackType ResultType { get { return StackType.I; } }
protected override InstructionFlags ComputeFlags() protected override InstructionFlags ComputeFlags()
{ {
return array.Flags | InstructionFlags.MayThrow; return array.Flags | InstructionFlags.MayThrow;
@ -2957,13 +2952,6 @@ namespace ICSharpCode.Decompiler.IL
return InstructionFlags.MayThrow; return InstructionFlags.MayThrow;
} }
} }
public override void WriteTo(ITextOutput output)
{
output.Write(OpCode);
output.Write('(');
this.array.WriteTo(output);
output.Write(')');
}
public override void AcceptVisitor(ILVisitor visitor) public override void AcceptVisitor(ILVisitor visitor)
{ {
visitor.VisitLdLen(this); visitor.VisitLdLen(this);
@ -4531,16 +4519,6 @@ namespace ICSharpCode.Decompiler.IL
type = default(IType); type = default(IType);
return false; return false;
} }
public bool MatchLdLen(out ILInstruction array)
{
var inst = this as LdLen;
if (inst != null) {
array = inst.Array;
return true;
}
array = default(ILInstruction);
return false;
}
public bool MatchLdElema(out IType type, out ILInstruction array) public bool MatchLdElema(out IType type, out ILInstruction array)
{ {
var inst = this as LdElema; var inst = this as LdElema;

2
ICSharpCode.Decompiler/IL/Instructions.tt

@ -192,7 +192,7 @@
CustomClassName("SizeOf"), NoArguments, HasTypeOperand, ResultType("I4")), CustomClassName("SizeOf"), NoArguments, HasTypeOperand, ResultType("I4")),
new OpCode("ldlen", "Returns the length of an array as 'native unsigned int'.", new OpCode("ldlen", "Returns the length of an array as 'native unsigned int'.",
CustomClassName("LdLen"), CustomArguments("array"), MayThrow, ResultType("I")), CustomClassName("LdLen"), CustomArguments("array"), CustomConstructor, CustomWriteTo, MayThrow),
new OpCode("ldelema", "Load address of array element.", new OpCode("ldelema", "Load address of array element.",
CustomClassName("LdElema"), HasTypeOperand, CustomChildren(new [] { new ArgumentInfo("array"), new ArgumentInfo("indices") { IsCollection = true } }, true), CustomClassName("LdElema"), HasTypeOperand, CustomChildren(new [] { new ArgumentInfo("array"), new ArgumentInfo("indices") { IsCollection = true } }, true),
MayThrow, ResultType("Ref"), SupportsReadonlyPrefix), MayThrow, ResultType("Ref"), SupportsReadonlyPrefix),

52
ICSharpCode.Decompiler/IL/Instructions/LdLen.cs

@ -0,0 +1,52 @@
// Copyright (c) 2014 Daniel Grunwald
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.Diagnostics;
namespace ICSharpCode.Decompiler.IL
{
/// <summary>
/// Description of LdLen.
/// </summary>
public sealed partial class LdLen
{
readonly StackType resultType;
public LdLen(StackType type, ILInstruction array) : base(OpCode.LdLen)
{
Debug.Assert(type == StackType.I || type == StackType.I4 || type == StackType.I8);
this.resultType = type;
this.Array = array;
}
public override StackType ResultType {
get { return resultType; }
}
public override void WriteTo(ITextOutput output)
{
output.Write(OpCode);
output.Write('.');
output.Write(resultType);
output.Write('(');
this.array.WriteTo(output);
output.Write(')');
}
}
}

11
ICSharpCode.Decompiler/IL/Instructions/PatternMatching.cs

@ -67,6 +67,17 @@ namespace ICSharpCode.Decompiler.IL
return false; return false;
} }
public bool MatchLdLen(StackType type, out ILInstruction array)
{
var inst = this as LdLen;
if (inst != null && inst.ResultType == type) {
array = inst.Array;
return true;
}
array = null;
return false;
}
public bool MatchBranch(out Block targetBlock) public bool MatchBranch(out Block targetBlock)
{ {
var inst = this as Branch; var inst = this as Branch;

Loading…
Cancel
Save