Browse Source

Add TS method to ILReader

pull/1165/head
Siegfried Pammer 7 years ago
parent
commit
6888b405b7
  1. 14
      ICSharpCode.Decompiler/IL/ILReader.cs
  2. 2
      ILSpy/Languages/ILAstLanguage.cs

14
ICSharpCode.Decompiler/IL/ILReader.cs

@ -48,6 +48,7 @@ namespace ICSharpCode.Decompiler.IL @@ -48,6 +48,7 @@ namespace ICSharpCode.Decompiler.IL
this.compilation = typeSystem.Compilation;
}
IMethod method;
Cil.MethodBody body;
Cil.MethodDebugInformation debugInfo;
StackType methodReturnStackType;
@ -67,11 +68,12 @@ namespace ICSharpCode.Decompiler.IL @@ -67,11 +68,12 @@ namespace ICSharpCode.Decompiler.IL
List<(ILVariable, ILVariable)> stackMismatchPairs;
IEnumerable<ILVariable> stackVariables;
void Init(Cil.MethodBody body)
void Init(Cil.MethodBody body, IMethod method)
{
if (body == null)
throw new ArgumentNullException(nameof(body));
this.body = body;
this.method = method;
this.debugInfo = body.Method.DebugInformation;
this.currentInstruction = null;
this.nextInstructionIndex = 0;
@ -167,7 +169,7 @@ namespace ICSharpCode.Decompiler.IL @@ -167,7 +169,7 @@ namespace ICSharpCode.Decompiler.IL
parameterType = typeSystem.Resolve(p.ParameterType, isFromSignature: true);
}
} else {
parameterType = typeSystem.Resolve(p.ParameterType, isFromSignature: true);
parameterType = method.Parameters[p.Index].Type;
}
Debug.Assert(!parameterType.IsUnbound());
if (parameterType.IsUnbound()) {
@ -379,9 +381,9 @@ namespace ICSharpCode.Decompiler.IL @@ -379,9 +381,9 @@ namespace ICSharpCode.Decompiler.IL
/// <summary>
/// Debugging helper: writes the decoded instruction stream interleaved with the inferred evaluation stack layout.
/// </summary>
public void WriteTypedIL(Cil.MethodBody body, ITextOutput output, CancellationToken cancellationToken = default(CancellationToken))
public void WriteTypedIL(Cil.MethodBody body, IMethod method, ITextOutput output, CancellationToken cancellationToken = default(CancellationToken))
{
Init(body);
Init(body, method);
ReadInstructions(cancellationToken);
foreach (var inst in instructionBuilder) {
if (inst is StLoc stloc && stloc.IsStackAdjustment) {
@ -422,11 +424,11 @@ namespace ICSharpCode.Decompiler.IL @@ -422,11 +424,11 @@ namespace ICSharpCode.Decompiler.IL
public ILFunction ReadIL(Cil.MethodBody body, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
Init(body);
var method = typeSystem.Resolve(body.Method);
Init(body, method);
ReadInstructions(cancellationToken);
var blockBuilder = new BlockBuilder(body, typeSystem, variableByExceptionHandler);
blockBuilder.CreateBlocks(mainContainer, instructionBuilder, isBranchTarget, cancellationToken);
var method = typeSystem.Resolve(body.Method);
var function = new ILFunction(method, body.Method, mainContainer);
CollectionExtensions.AddRange(function.Variables, parameterVariables);
CollectionExtensions.AddRange(function.Variables, localVariables);

2
ILSpy/Languages/ILAstLanguage.cs

@ -94,7 +94,7 @@ namespace ICSharpCode.ILSpy @@ -94,7 +94,7 @@ namespace ICSharpCode.ILSpy
return;
var typeSystem = new DecompilerTypeSystem(method.Module);
ILReader reader = new ILReader(typeSystem);
reader.WriteTypedIL(method.Body, output, options.CancellationToken);
reader.WriteTypedIL(method.Body, typeSystem.Resolve(method), output, options.CancellationToken);
}
}

Loading…
Cancel
Save