|
|
|
@ -55,6 +55,7 @@ namespace ICSharpCode.Decompiler.ILAst
@@ -55,6 +55,7 @@ namespace ICSharpCode.Decompiler.ILAst
|
|
|
|
|
FindLoops, |
|
|
|
|
FindConditions, |
|
|
|
|
FlattenNestedMovableBlocks, |
|
|
|
|
RemoveEndFinally, |
|
|
|
|
RemoveRedundantCode2, |
|
|
|
|
GotoRemoval, |
|
|
|
|
DuplicateReturns, |
|
|
|
@ -182,6 +183,9 @@ namespace ICSharpCode.Decompiler.ILAst
@@ -182,6 +183,9 @@ namespace ICSharpCode.Decompiler.ILAst
|
|
|
|
|
if (abortBeforeStep == ILAstOptimizationStep.FlattenNestedMovableBlocks) return; |
|
|
|
|
FlattenBasicBlocks(method); |
|
|
|
|
|
|
|
|
|
if (abortBeforeStep == ILAstOptimizationStep.RemoveEndFinally) return; |
|
|
|
|
RemoveEndFinally(method); |
|
|
|
|
|
|
|
|
|
if (abortBeforeStep == ILAstOptimizationStep.RemoveRedundantCode2) return; |
|
|
|
|
RemoveRedundantCode(method); |
|
|
|
|
|
|
|
|
@ -538,6 +542,25 @@ namespace ICSharpCode.Decompiler.ILAst
@@ -538,6 +542,25 @@ namespace ICSharpCode.Decompiler.ILAst
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Replace endfinally with jump to the end of the finally block
|
|
|
|
|
/// </summary>
|
|
|
|
|
void RemoveEndFinally(ILBlock method) |
|
|
|
|
{ |
|
|
|
|
// Go thought the list in reverse so that we do the nested blocks first
|
|
|
|
|
foreach(var tryCatch in method.GetSelfAndChildrenRecursive<ILTryCatchBlock>(tc => tc.FinallyBlock != null).Reverse()) { |
|
|
|
|
ILLabel label = new ILLabel() { Name = "EndFinally_" + nextLabelIndex++ }; |
|
|
|
|
tryCatch.FinallyBlock.Body.Add(label); |
|
|
|
|
foreach(var block in tryCatch.FinallyBlock.GetSelfAndChildrenRecursive<ILBlock>()) { |
|
|
|
|
for (int i = 0; i < block.Body.Count; i++) { |
|
|
|
|
if (block.Body[i].Match(ILCode.Endfinally)) { |
|
|
|
|
block.Body[i] = new ILExpression(ILCode.Br, label).WithILRanges(((ILExpression)block.Body[i]).ILRanges); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Reduce the nesting of conditions.
|
|
|
|
|
/// It should be done on flat data that already had most gotos removed
|
|
|
|
@ -770,6 +793,12 @@ namespace ICSharpCode.Decompiler.ILAst
@@ -770,6 +793,12 @@ namespace ICSharpCode.Decompiler.ILAst
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static ILExpression WithILRanges(this ILExpression expr, IEnumerable<ILRange> ilranges) |
|
|
|
|
{ |
|
|
|
|
expr.ILRanges.AddRange(ilranges); |
|
|
|
|
return expr; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static void RemoveTail(this List<ILNode> body, params ILCode[] codes) |
|
|
|
|
{ |
|
|
|
|
for (int i = 0; i < codes.Length; i++) { |
|
|
|
|