Browse Source

Fix bugs.

pull/728/head
Daniel Grunwald 11 years ago
parent
commit
0c72367579
  1. 2
      ICSharpCode.Decompiler/IL/BlockBuilder.cs
  2. 5
      ICSharpCode.Decompiler/IL/ILReader.cs
  3. 24
      ICSharpCode.Decompiler/IL/Instructions.cs
  4. 6
      ICSharpCode.Decompiler/IL/Instructions.tt
  5. 13
      ICSharpCode.Decompiler/IL/Instructions/Block.cs
  6. 2
      ICSharpCode.Decompiler/IL/Instructions/BranchInstruction.cs
  7. 5
      ICSharpCode.Decompiler/IL/Instructions/CallInstruction.cs
  8. 7
      ICSharpCode.Decompiler/IL/Instructions/ILInstruction.cs
  9. 120
      ICSharpCode.Decompiler/IL/Instructions/SimpleInstruction.cs

2
ICSharpCode.Decompiler/IL/BlockBuilder.cs

@ -63,7 +63,7 @@ namespace ICSharpCode.Decompiler.IL
} else { } else {
bool finished; bool finished;
var inlinedInst = inst.Inline(InstructionFlags.None, instructionStack, out finished); var inlinedInst = inst.Inline(InstructionFlags.None, instructionStack, out finished);
if (inlinedInst is Branch) { if (inlinedInst.HasFlag(InstructionFlags.MayBranch)) {
// Values currently on the stack might be used on both sides of the branch, // Values currently on the stack might be used on both sides of the branch,
// so we can't inline them. // so we can't inline them.
FlushInstructionStack(); FlushInstructionStack();

5
ICSharpCode.Decompiler/IL/ILReader.cs

@ -106,9 +106,11 @@ namespace ICSharpCode.Decompiler.IL
if (outputStacks != null) if (outputStacks != null)
outputStacks.Add(start, stack.ToImmutableArray()); outputStacks.Add(start, stack.ToImmutableArray());
ILInstruction decodedInstruction = DecodeInstruction(); ILInstruction decodedInstruction = DecodeInstruction();
if (decodedInstruction.ResultType != StackType.Void)
stack.Push(decodedInstruction.ResultType);
decodedInstruction.ILRange = new Interval(start, reader.Position); decodedInstruction.ILRange = new Interval(start, reader.Position);
instructionBuilder.Add(decodedInstruction); instructionBuilder.Add(decodedInstruction);
Branch branch = decodedInstruction as Branch; BranchInstruction branch = decodedInstruction as BranchInstruction;
if (branch != null) { if (branch != null) {
isBranchTarget[branch.TargetILOffset] = true; isBranchTarget[branch.TargetILOffset] = true;
if (branch.TargetILOffset >= reader.Position) { if (branch.TargetILOffset >= reader.Position) {
@ -396,7 +398,6 @@ namespace ICSharpCode.Decompiler.IL
case ILOpCode.Ldc_I4_S: case ILOpCode.Ldc_I4_S:
return new LdcI4(reader.ReadSByte()); return new LdcI4(reader.ReadSByte());
case ILOpCode.Ldnull: case ILOpCode.Ldnull:
stack.Push(StackType.O);
return new LdNull(); return new LdNull();
case ILOpCode.Ldstr: case ILOpCode.Ldstr:
return DecodeLdstr(); return DecodeLdstr();

24
ICSharpCode.Decompiler/IL/Instructions.cs

@ -584,6 +584,12 @@ namespace ICSharpCode.Decompiler.IL
this.Value = value; this.Value = value;
} }
public readonly string Value; public readonly string Value;
public override void WriteTo(ITextOutput output)
{
output.Write(OpCode);
output.Write(' ');
Disassembler.DisassemblerHelpers.WriteOperand(output, Value);
}
public override StackType ResultType { get { return StackType.O; } } public override StackType ResultType { get { return StackType.O; } }
public override T AcceptVisitor<T>(ILVisitor<T> visitor) public override T AcceptVisitor<T>(ILVisitor<T> visitor)
{ {
@ -599,6 +605,12 @@ namespace ICSharpCode.Decompiler.IL
this.Value = value; this.Value = value;
} }
public readonly int Value; public readonly int Value;
public override void WriteTo(ITextOutput output)
{
output.Write(OpCode);
output.Write(' ');
Disassembler.DisassemblerHelpers.WriteOperand(output, Value);
}
public override StackType ResultType { get { return StackType.I4; } } public override StackType ResultType { get { return StackType.I4; } }
public override T AcceptVisitor<T>(ILVisitor<T> visitor) public override T AcceptVisitor<T>(ILVisitor<T> visitor)
{ {
@ -614,6 +626,12 @@ namespace ICSharpCode.Decompiler.IL
this.Value = value; this.Value = value;
} }
public readonly long Value; public readonly long Value;
public override void WriteTo(ITextOutput output)
{
output.Write(OpCode);
output.Write(' ');
Disassembler.DisassemblerHelpers.WriteOperand(output, Value);
}
public override StackType ResultType { get { return StackType.I8; } } public override StackType ResultType { get { return StackType.I8; } }
public override T AcceptVisitor<T>(ILVisitor<T> visitor) public override T AcceptVisitor<T>(ILVisitor<T> visitor)
{ {
@ -629,6 +647,12 @@ namespace ICSharpCode.Decompiler.IL
this.Value = value; this.Value = value;
} }
public readonly double Value; public readonly double Value;
public override void WriteTo(ITextOutput output)
{
output.Write(OpCode);
output.Write(' ');
Disassembler.DisassemblerHelpers.WriteOperand(output, Value);
}
public override StackType ResultType { get { return StackType.F; } } public override StackType ResultType { get { return StackType.F; } }
public override T AcceptVisitor<T>(ILVisitor<T> visitor) public override T AcceptVisitor<T>(ILVisitor<T> visitor)
{ {

6
ICSharpCode.Decompiler/IL/Instructions.tt

@ -392,6 +392,12 @@ namespace ICSharpCode.Decompiler.IL
opCode.ConstructorParameters.Add(operandType + " value"); opCode.ConstructorParameters.Add(operandType + " value");
opCode.Members.Add("public readonly " + operandType + " Value;"); opCode.Members.Add("public readonly " + operandType + " Value;");
opCode.ConstructorBody.Add("this.Value = value;"); opCode.ConstructorBody.Add("this.Value = value;");
opCode.Members.Add("public override void WriteTo(ITextOutput output)" + Environment.NewLine
+ "{" + Environment.NewLine
+ "\toutput.Write(OpCode);" + Environment.NewLine
+ "\toutput.Write(' ');" + Environment.NewLine
+ "\tDisassembler.DisassemblerHelpers.WriteOperand(output, Value);" + Environment.NewLine
+ "}");
}; };
} }

13
ICSharpCode.Decompiler/IL/Instructions/Block.cs

@ -16,19 +16,6 @@ namespace ICSharpCode.Decompiler.IL
this.Instructions = new InstructionCollection<ILInstruction>(this); this.Instructions = new InstructionCollection<ILInstruction>(this);
} }
/*
public override bool IsPeeking { get { return Instructions.Count > 0 && Instructions[0].IsPeeking; } }
public override bool NoResult { get { return true; } }
public override void TransformChildren(Func<ILInstruction, ILInstruction> transformFunc)
{
for (int i = 0; i < Instructions.Count; i++) {
Instructions[i] = transformFunc(Instructions[i]);
}
}
*/
public override StackType ResultType { public override StackType ResultType {
get { get {
return StackType.Void; return StackType.Void;

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

@ -63,7 +63,7 @@ namespace ICSharpCode.Decompiler.IL
return condition; return condition;
} }
set { set {
ValidateArgument(condition); ValidateArgument(value);
SetChildInstruction(ref condition, value); SetChildInstruction(ref condition, value);
} }
} }

5
ICSharpCode.Decompiler/IL/Instructions/CallInstruction.cs

@ -62,7 +62,10 @@ namespace ICSharpCode.Decompiler.IL
public override StackType ResultType { public override StackType ResultType {
get { get {
throw new NotImplementedException(); if (OpCode == OpCode.NewObj)
return Method.DeclaringType.GetStackType();
else
return Method.ReturnType.GetStackType();
} }
} }

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

@ -100,6 +100,13 @@ namespace ICSharpCode.Decompiler.IL
public abstract void WriteTo(ITextOutput output); public abstract void WriteTo(ITextOutput output);
public override string ToString()
{
var output = new PlainTextOutput();
WriteTo(output);
return output.ToString();
}
public abstract T AcceptVisitor<T>(ILVisitor<T> visitor); public abstract T AcceptVisitor<T>(ILVisitor<T> visitor);
/// <summary> /// <summary>

120
ICSharpCode.Decompiler/IL/Instructions/SimpleInstruction.cs

@ -59,18 +59,7 @@ namespace ICSharpCode.Decompiler.IL
} }
} }
/* partial class Pop
class Nop() : SimpleInstruction(OpCode.Nop)
{
public override bool NoResult { get { return true; } }
public override InstructionFlags Flags
{
get { return InstructionFlags.None; }
}
}
class Pop() : SimpleInstruction(OpCode.Pop)
{ {
internal override ILInstruction Inline(InstructionFlags flagsBefore, Stack<ILInstruction> instructionStack, out bool finished) internal override ILInstruction Inline(InstructionFlags flagsBefore, Stack<ILInstruction> instructionStack, out bool finished)
{ {
@ -81,119 +70,14 @@ namespace ICSharpCode.Decompiler.IL
finished = false; finished = false;
return this; return this;
} }
public override InstructionFlags Flags
{
get { return InstructionFlags.MayPop; }
}
} }
class Peek() : SimpleInstruction(OpCode.Peek) partial class Peek
{ {
public override bool IsPeeking { get { return true; } }
internal override ILInstruction Inline(InstructionFlags flagsBefore, Stack<ILInstruction> instructionStack, out bool finished) internal override ILInstruction Inline(InstructionFlags flagsBefore, Stack<ILInstruction> instructionStack, out bool finished)
{ {
finished = false; finished = false;
return this; return this;
} }
public override InstructionFlags Flags
{
get { return InstructionFlags.MayPeek; }
}
}
class Ckfinite() : SimpleInstruction(OpCode.Ckfinite)
{
public override bool IsPeeking { get { return true; } }
public override bool NoResult { get { return true; } }
public override InstructionFlags Flags
{
get { return InstructionFlags.MayPeek | InstructionFlags.MayThrow; }
}
}
class Arglist() : SimpleInstruction(OpCode.Arglist)
{
public override InstructionFlags Flags
{
get { return InstructionFlags.None; }
}
}
class DebugBreak() : SimpleInstruction(OpCode.DebugBreak)
{
public override bool NoResult { get { return true; } }
public override InstructionFlags Flags
{
get { return InstructionFlags.SideEffects; }
}
}
class ConstantString(public readonly string Value) : SimpleInstruction(OpCode.LdStr)
{
public override InstructionFlags Flags
{
get { return InstructionFlags.None; }
}
public override void WriteTo(ITextOutput output)
{
output.Write("ldstr ");
Disassembler.DisassemblerHelpers.WriteOperand(output, Value);
}
}
class ConstantI4(public readonly int Value) : SimpleInstruction(OpCode.LdcI4)
{
public override InstructionFlags Flags
{
get { return InstructionFlags.None; }
}
public override void WriteTo(ITextOutput output)
{
output.Write("ldc.i4 ");
Disassembler.DisassemblerHelpers.WriteOperand(output, Value);
}
} }
class ConstantI8(public readonly long Value) : SimpleInstruction(OpCode.LdcI8)
{
public override InstructionFlags Flags
{
get { return InstructionFlags.None; }
}
public override void WriteTo(ITextOutput output)
{
output.Write("ldc.i8 ");
Disassembler.DisassemblerHelpers.WriteOperand(output, Value);
}
}
class ConstantFloat(public readonly double Value) : SimpleInstruction(OpCode.LdcF)
{
public override InstructionFlags Flags
{
get { return InstructionFlags.None; }
}
public override void WriteTo(ITextOutput output)
{
output.Write("ldc.f ");
Disassembler.DisassemblerHelpers.WriteOperand(output, Value);
}
}
class ConstantNull() : SimpleInstruction(OpCode.LdNull)
{
public override InstructionFlags Flags
{
get { return InstructionFlags.None; }
}
}*/
} }

Loading…
Cancel
Save