Browse Source

Add WriteInstruction to MethodBodyDisassembler

pull/923/head
Siegfried Pammer 8 years ago
parent
commit
d871960bec
  1. 38
      ICSharpCode.Decompiler/Disassembler/MethodBodyDisassembler.cs
  2. 7
      ICSharpCode.Decompiler/Disassembler/ReflectionDisassembler.cs
  3. 4
      ICSharpCode.Decompiler/IL/SequencePoint.cs

38
ICSharpCode.Decompiler/Disassembler/MethodBodyDisassembler.cs

@ -27,7 +27,7 @@ namespace ICSharpCode.Decompiler.Disassembler
/// <summary> /// <summary>
/// Disassembles a method body. /// Disassembles a method body.
/// </summary> /// </summary>
public sealed class MethodBodyDisassembler public class MethodBodyDisassembler
{ {
readonly ITextOutput output; readonly ITextOutput output;
readonly bool detectControlStructure; readonly bool detectControlStructure;
@ -42,7 +42,7 @@ namespace ICSharpCode.Decompiler.Disassembler
this.cancellationToken = cancellationToken; this.cancellationToken = cancellationToken;
} }
public void Disassemble(MethodBody body/*, MemberMapping methodMapping*/) public void Disassemble(MethodBody body)
{ {
// start writing IL code // start writing IL code
MethodDefinition method = body.Method; MethodDefinition method = body.Method;
@ -61,20 +61,7 @@ namespace ICSharpCode.Decompiler.Disassembler
WriteStructureBody(new ILStructure(body), branchTargets, ref inst, method.Body.CodeSize); WriteStructureBody(new ILStructure(body), branchTargets, ref inst, method.Body.CodeSize);
} else { } else {
foreach (var inst in method.Body.Instructions) { foreach (var inst in method.Body.Instructions) {
//var startLocation = output.Location; WriteInstruction(output, inst);
inst.WriteTo(output);
/*
if (debugSymbols != null) {
// add IL code mappings - used in debugger
debugSymbols.SequencePoints.Add(
new SequencePoint() {
StartLocation = output.Location,
EndLocation = output.Location,
ILRanges = new ILRange[] { new ILRange(inst.Offset, inst.Next == null ? method.Body.CodeSize : inst.Next.Offset) }
});
}*/
output.WriteLine(); output.WriteLine();
} }
WriteExceptionHandlers(body); WriteExceptionHandlers(body);
@ -191,19 +178,7 @@ namespace ICSharpCode.Decompiler.Disassembler
if (!isFirstInstructionInStructure && (prevInstructionWasBranch || branchTargets.Contains(offset))) { if (!isFirstInstructionInStructure && (prevInstructionWasBranch || branchTargets.Contains(offset))) {
output.WriteLine(); // put an empty line after branches, and in front of branch targets output.WriteLine(); // put an empty line after branches, and in front of branch targets
} }
//var startLocation = output.Location; WriteInstruction(output, inst);
inst.WriteTo(output);
/*// add IL code mappings - used in debugger
if (debugSymbols != null) {
debugSymbols.SequencePoints.Add(
new SequencePoint() {
StartLocation = startLocation,
EndLocation = output.Location,
ILRanges = new ILRange[] { new ILRange(inst.Offset, inst.Next == null ? codeSize : inst.Next.Offset) }
});
}*/
output.WriteLine(); output.WriteLine();
prevInstructionWasBranch = inst.OpCode.FlowControl == FlowControl.Branch prevInstructionWasBranch = inst.OpCode.FlowControl == FlowControl.Branch
@ -237,5 +212,10 @@ namespace ICSharpCode.Decompiler.Disassembler
throw new NotSupportedException(); throw new NotSupportedException();
} }
} }
protected virtual void WriteInstruction(ITextOutput output, Instruction instruction)
{
instruction.WriteTo(output);
}
} }
} }

7
ICSharpCode.Decompiler/Disassembler/ReflectionDisassembler.cs

@ -36,12 +36,17 @@ namespace ICSharpCode.Decompiler.Disassembler
MemberReference currentMember; MemberReference currentMember;
public ReflectionDisassembler(ITextOutput output, bool detectControlStructure, CancellationToken cancellationToken) public ReflectionDisassembler(ITextOutput output, bool detectControlStructure, CancellationToken cancellationToken)
: this(output, new MethodBodyDisassembler(output, detectControlStructure, cancellationToken), cancellationToken)
{
}
public ReflectionDisassembler(ITextOutput output, MethodBodyDisassembler methodBodyDisassembler, CancellationToken cancellationToken)
{ {
if (output == null) if (output == null)
throw new ArgumentNullException(nameof(output)); throw new ArgumentNullException(nameof(output));
this.output = output; this.output = output;
this.cancellationToken = cancellationToken; this.cancellationToken = cancellationToken;
this.methodBodyDisassembler = new MethodBodyDisassembler(output, detectControlStructure, cancellationToken); this.methodBodyDisassembler = methodBodyDisassembler;
} }
#region Disassemble Method #region Disassemble Method

4
ICSharpCode.Decompiler/IL/SequencePoint.cs

@ -7,8 +7,8 @@ namespace ICSharpCode.Decompiler.IL
/// <summary> /// <summary>
/// A sequence point produced by the decompiler. /// A sequence point produced by the decompiler.
/// </summary> /// </summary>
public struct SequencePoint public struct SequencePoint
{ {
/// <summary> /// <summary>
/// IL offset. /// IL offset.
/// </summary> /// </summary>

Loading…
Cancel
Save