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 @@ -27,7 +27,7 @@ namespace ICSharpCode.Decompiler.Disassembler
/// <summary>
/// Disassembles a method body.
/// </summary>
public sealed class MethodBodyDisassembler
public class MethodBodyDisassembler
{
readonly ITextOutput output;
readonly bool detectControlStructure;
@ -42,7 +42,7 @@ namespace ICSharpCode.Decompiler.Disassembler @@ -42,7 +42,7 @@ namespace ICSharpCode.Decompiler.Disassembler
this.cancellationToken = cancellationToken;
}
public void Disassemble(MethodBody body/*, MemberMapping methodMapping*/)
public void Disassemble(MethodBody body)
{
// start writing IL code
MethodDefinition method = body.Method;
@ -61,20 +61,7 @@ namespace ICSharpCode.Decompiler.Disassembler @@ -61,20 +61,7 @@ namespace ICSharpCode.Decompiler.Disassembler
WriteStructureBody(new ILStructure(body), branchTargets, ref inst, method.Body.CodeSize);
} else {
foreach (var inst in method.Body.Instructions) {
//var startLocation = output.Location;
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) }
});
}*/
WriteInstruction(output, inst);
output.WriteLine();
}
WriteExceptionHandlers(body);
@ -191,19 +178,7 @@ namespace ICSharpCode.Decompiler.Disassembler @@ -191,19 +178,7 @@ namespace ICSharpCode.Decompiler.Disassembler
if (!isFirstInstructionInStructure && (prevInstructionWasBranch || branchTargets.Contains(offset))) {
output.WriteLine(); // put an empty line after branches, and in front of branch targets
}
//var startLocation = output.Location;
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) }
});
}*/
WriteInstruction(output, inst);
output.WriteLine();
prevInstructionWasBranch = inst.OpCode.FlowControl == FlowControl.Branch
@ -237,5 +212,10 @@ namespace ICSharpCode.Decompiler.Disassembler @@ -237,5 +212,10 @@ namespace ICSharpCode.Decompiler.Disassembler
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 @@ -36,12 +36,17 @@ namespace ICSharpCode.Decompiler.Disassembler
MemberReference currentMember;
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)
throw new ArgumentNullException(nameof(output));
this.output = output;
this.cancellationToken = cancellationToken;
this.methodBodyDisassembler = new MethodBodyDisassembler(output, detectControlStructure, cancellationToken);
this.methodBodyDisassembler = methodBodyDisassembler;
}
#region Disassemble Method

4
ICSharpCode.Decompiler/IL/SequencePoint.cs

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

Loading…
Cancel
Save