.NET Decompiler with support for PDB generation, ReadyToRun, Metadata (&more) - cross-platform!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

32 lines
1.1 KiB

using System;
using System.Collections.Generic;
using System.Text;
namespace ICSharpCode.Decompiler.IL.Transforms
{
class CombineExitsTransform : IILTransform
{
public void Run(ILFunction function, ILTransformContext context)
{
if (!(function.Body is BlockContainer container && container.Blocks.Count == 1))
return;
var block = container.EntryPoint;
if (block.Kind != BlockKind.ControlFlow)
return;
if (!(block.Instructions.SecondToLastOrDefault() is IfInstruction ifInst && block.Instructions.LastOrDefault() is Leave leave2))
return;
if (!ifInst.FalseInst.MatchNop())
return;
if (!(Block.Unwrap(ifInst.TrueInst) is Leave leave))
return;
if (!(leave.IsLeavingFunction && leave2.IsLeavingFunction))
return;
if (leave.Value.MatchNop() || leave2.Value.MatchNop())
return;
IfInstruction value = new IfInstruction(ifInst.Condition, leave.Value, leave2.Value);
Leave combinedLeave = new Leave(leave.TargetContainer, value);
ifInst.ReplaceWith(combinedLeave);
block.Instructions.RemoveAt(combinedLeave.ChildIndex + 1);
}
}
}