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 @@ -63,7 +63,7 @@ namespace ICSharpCode.Decompiler.IL
} else {
bool 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,
// so we can't inline them.
FlushInstructionStack();

5
ICSharpCode.Decompiler/IL/ILReader.cs

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

24
ICSharpCode.Decompiler/IL/Instructions.cs

@ -584,6 +584,12 @@ namespace ICSharpCode.Decompiler.IL @@ -584,6 +584,12 @@ namespace ICSharpCode.Decompiler.IL
this.Value = 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 T AcceptVisitor<T>(ILVisitor<T> visitor)
{
@ -599,6 +605,12 @@ namespace ICSharpCode.Decompiler.IL @@ -599,6 +605,12 @@ namespace ICSharpCode.Decompiler.IL
this.Value = 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 T AcceptVisitor<T>(ILVisitor<T> visitor)
{
@ -614,6 +626,12 @@ namespace ICSharpCode.Decompiler.IL @@ -614,6 +626,12 @@ namespace ICSharpCode.Decompiler.IL
this.Value = 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 T AcceptVisitor<T>(ILVisitor<T> visitor)
{
@ -629,6 +647,12 @@ namespace ICSharpCode.Decompiler.IL @@ -629,6 +647,12 @@ namespace ICSharpCode.Decompiler.IL
this.Value = 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 T AcceptVisitor<T>(ILVisitor<T> visitor)
{

6
ICSharpCode.Decompiler/IL/Instructions.tt

@ -392,6 +392,12 @@ namespace ICSharpCode.Decompiler.IL @@ -392,6 +392,12 @@ namespace ICSharpCode.Decompiler.IL
opCode.ConstructorParameters.Add(operandType + " value");
opCode.Members.Add("public readonly " + operandType + " 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 @@ -16,19 +16,6 @@ namespace ICSharpCode.Decompiler.IL
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 {
get {
return StackType.Void;

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

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

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

@ -62,7 +62,10 @@ namespace ICSharpCode.Decompiler.IL @@ -62,7 +62,10 @@ namespace ICSharpCode.Decompiler.IL
public override StackType ResultType {
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 @@ -100,6 +100,13 @@ namespace ICSharpCode.Decompiler.IL
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);
/// <summary>

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

@ -59,18 +59,7 @@ namespace ICSharpCode.Decompiler.IL @@ -59,18 +59,7 @@ namespace ICSharpCode.Decompiler.IL
}
}
/*
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)
partial class Pop
{
internal override ILInstruction Inline(InstructionFlags flagsBefore, Stack<ILInstruction> instructionStack, out bool finished)
{
@ -81,119 +70,14 @@ namespace ICSharpCode.Decompiler.IL @@ -81,119 +70,14 @@ namespace ICSharpCode.Decompiler.IL
finished = false;
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)
{
finished = false;
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