diff --git a/ICSharpCode.Decompiler.sln b/ICSharpCode.Decompiler.sln index c004b1285..1e00f2b4c 100644 --- a/ICSharpCode.Decompiler.sln +++ b/ICSharpCode.Decompiler.sln @@ -1,21 +1,14 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2012 -# SharpDevelop 5.1 -VisualStudioVersion = 12.0.31101.0 +# Visual Studio 15 +VisualStudioVersion = 15.0.25914.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mono.Cecil", "cecil\Mono.Cecil.csproj", "{D68133BD-1E63-496E-9EDE-4FBDBF77B486}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.Decompiler", "ICSharpCode.Decompiler\ICSharpCode.Decompiler.csproj", "{984CC812-9470-4A13-AFF9-CC44068D666C}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.NRefactory", "NRefactory\ICSharpCode.NRefactory\ICSharpCode.NRefactory.csproj", "{3B2A5653-EC97-4001-BB9B-D90F1AF2C371}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.Decompiler.Tests", "ICSharpCode.Decompiler\Tests\ICSharpCode.Decompiler.Tests.csproj", "{FEC0DA52-C4A6-4710-BE36-B484A20C5E22}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.NRefactory.CSharp", "NRefactory\ICSharpCode.NRefactory.CSharp\ICSharpCode.NRefactory.CSharp.csproj", "{53DCA265-3C3C-42F9-B647-F72BA678122B}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.NRefactory.Cecil", "NRefactory\ICSharpCode.NRefactory.Cecil\ICSharpCode.NRefactory.Cecil.csproj", "{2B8F4F83-C2B3-4E84-A27B-8DEE1BE0E006}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -40,14 +33,6 @@ Global {984CC812-9470-4A13-AFF9-CC44068D666C}.Release|Any CPU.Build.0 = Release|Any CPU {984CC812-9470-4A13-AFF9-CC44068D666C}.Release|x86.ActiveCfg = Release|Any CPU {984CC812-9470-4A13-AFF9-CC44068D666C}.Release|x86.Build.0 = Release|Any CPU - {3B2A5653-EC97-4001-BB9B-D90F1AF2C371}.Debug|Any CPU.ActiveCfg = net_4_5_Debug|Any CPU - {3B2A5653-EC97-4001-BB9B-D90F1AF2C371}.Debug|Any CPU.Build.0 = net_4_5_Debug|Any CPU - {3B2A5653-EC97-4001-BB9B-D90F1AF2C371}.Debug|x86.ActiveCfg = net_4_5_Debug|Any CPU - {3B2A5653-EC97-4001-BB9B-D90F1AF2C371}.Debug|x86.Build.0 = net_4_5_Debug|Any CPU - {3B2A5653-EC97-4001-BB9B-D90F1AF2C371}.Release|Any CPU.ActiveCfg = net_4_5_Release|Any CPU - {3B2A5653-EC97-4001-BB9B-D90F1AF2C371}.Release|Any CPU.Build.0 = net_4_5_Release|Any CPU - {3B2A5653-EC97-4001-BB9B-D90F1AF2C371}.Release|x86.ActiveCfg = net_4_5_Release|Any CPU - {3B2A5653-EC97-4001-BB9B-D90F1AF2C371}.Release|x86.Build.0 = net_4_5_Release|Any CPU {FEC0DA52-C4A6-4710-BE36-B484A20C5E22}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {FEC0DA52-C4A6-4710-BE36-B484A20C5E22}.Debug|Any CPU.Build.0 = Debug|Any CPU {FEC0DA52-C4A6-4710-BE36-B484A20C5E22}.Debug|x86.ActiveCfg = Debug|x86 @@ -56,20 +41,6 @@ Global {FEC0DA52-C4A6-4710-BE36-B484A20C5E22}.Release|Any CPU.Build.0 = Release|Any CPU {FEC0DA52-C4A6-4710-BE36-B484A20C5E22}.Release|x86.ActiveCfg = Release|x86 {FEC0DA52-C4A6-4710-BE36-B484A20C5E22}.Release|x86.Build.0 = Release|x86 - {53DCA265-3C3C-42F9-B647-F72BA678122B}.Debug|Any CPU.ActiveCfg = net_4_5_Debug|Any CPU - {53DCA265-3C3C-42F9-B647-F72BA678122B}.Debug|Any CPU.Build.0 = net_4_5_Debug|Any CPU - {53DCA265-3C3C-42F9-B647-F72BA678122B}.Debug|x86.ActiveCfg = net_4_5_Debug|Any CPU - {53DCA265-3C3C-42F9-B647-F72BA678122B}.Debug|x86.Build.0 = net_4_5_Debug|Any CPU - {53DCA265-3C3C-42F9-B647-F72BA678122B}.Release|Any CPU.ActiveCfg = net_4_5_Release|Any CPU - {53DCA265-3C3C-42F9-B647-F72BA678122B}.Release|Any CPU.Build.0 = net_4_5_Release|Any CPU - {53DCA265-3C3C-42F9-B647-F72BA678122B}.Release|x86.ActiveCfg = net_4_5_Release|Any CPU - {53DCA265-3C3C-42F9-B647-F72BA678122B}.Release|x86.Build.0 = net_4_5_Release|Any CPU - {2B8F4F83-C2B3-4E84-A27B-8DEE1BE0E006}.Debug|Any CPU.ActiveCfg = net_4_5_Debug|Any CPU - {2B8F4F83-C2B3-4E84-A27B-8DEE1BE0E006}.Debug|Any CPU.Build.0 = net_4_5_Debug|Any CPU - {2B8F4F83-C2B3-4E84-A27B-8DEE1BE0E006}.Debug|x86.ActiveCfg = net_4_5_Debug|Any CPU - {2B8F4F83-C2B3-4E84-A27B-8DEE1BE0E006}.Release|Any CPU.ActiveCfg = net_4_5_Release|Any CPU - {2B8F4F83-C2B3-4E84-A27B-8DEE1BE0E006}.Release|Any CPU.Build.0 = net_4_5_Release|Any CPU - {2B8F4F83-C2B3-4E84-A27B-8DEE1BE0E006}.Release|x86.ActiveCfg = net_4_5_Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs b/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs index d5ec86981..19033ee21 100644 --- a/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs +++ b/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs @@ -57,26 +57,35 @@ namespace ICSharpCode.Decompiler.CSharp new SplitVariables(), new ILInlining(), new DetectPinnedRegions(), // must run after inlining but before non-critical control flow transforms - new BlockILTransform(new ExpressionTransforms()), // for RemoveDeadVariableInit - new RemoveDeadVariableInit(), // must run after ExpressionTransforms because it does not handle stobj(ldloca V, ...) + new BlockILTransform { + PostOrderTransforms = { + new ExpressionTransforms() // for RemoveDeadVariableInit// for RemoveDeadVariableInit + } + }, + // RemoveDeadVariableInit must run after ExpressionTransforms so that stobj(ldloca V, ...) + // is already collapsed into stloc(V, ...). + new RemoveDeadVariableInit(), new SwitchDetection(), new LoopDetection(), new IntroduceExitPoints(), - new BlockILTransform( // per-block transforms - new ConditionDetection(), - new CachedDelegateInitialization(), // must run after ConditionDetection and before/in LoopingBlockTransform. - new ILInlining(), - new TransformAssignment(), - new CopyPropagation(), - new LoopingBlockTransform( - // per-block transforms that depend on each other, and thus need to loop. - // Pretty much all transforms that open up new expression inlining - // opportunities belong in this category. - new ExpressionTransforms(), - new TransformArrayInitializers(), - new ILInlining() - ) - ), + new BlockILTransform { // per-block transforms + PostOrderTransforms = { + new ConditionDetection(), + // CachedDelegateInitialization must run after ConditionDetection and before/in LoopingBlockTransform. + new CachedDelegateInitialization(), + new ILInlining(), + new TransformAssignment(), + new CopyPropagation(), + new LoopingBlockTransform( + // per-block transforms that depend on each other, and thus need to loop. + // Pretty much all transforms that open up new expression inlining + // opportunities belong in this category. + new ExpressionTransforms(), + new TransformArrayInitializers(), + new ILInlining() + ) + } + }, new DelegateConstruction(), }; } diff --git a/ICSharpCode.Decompiler/ICSharpCode.Decompiler.ruleset b/ICSharpCode.Decompiler/ICSharpCode.Decompiler.ruleset index a875fb71f..66b1288eb 100644 --- a/ICSharpCode.Decompiler/ICSharpCode.Decompiler.ruleset +++ b/ICSharpCode.Decompiler/ICSharpCode.Decompiler.ruleset @@ -1,5 +1,5 @@  - + @@ -64,6 +64,9 @@ + + + @@ -75,7 +78,5 @@ - - \ No newline at end of file diff --git a/ICSharpCode.Decompiler/IL/Transforms/BlockTransform.cs b/ICSharpCode.Decompiler/IL/Transforms/BlockTransform.cs index 28eb829d2..3ecbf5ff9 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/BlockTransform.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/BlockTransform.cs @@ -64,12 +64,8 @@ namespace ICSharpCode.Decompiler.IL.Transforms /// public class BlockILTransform : IILTransform { - readonly IBlockTransform[] blockTransforms; - - public BlockILTransform(params IBlockTransform[] blockTransforms) - { - this.blockTransforms = blockTransforms; - } + public IList PreOrderTransforms { get; } = new List(); + public IList PostOrderTransforms { get; } = new List(); public void Run(ILFunction function, ILTransformContext context) { @@ -94,6 +90,11 @@ namespace ICSharpCode.Decompiler.IL.Transforms { Block block = (Block)cfgNode.UserData; context.Stepper.StartGroup(block.Label, block); + + context.ControlFlowNode = cfgNode; + context.Block = block; + block.RunTransforms(PreOrderTransforms, context); + // First, process the children in the dominator tree. // The ConditionDetection transform requires dominated blocks to // be already processed. @@ -103,7 +104,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms context.ControlFlowNode = cfgNode; context.Block = block; - block.RunTransforms(blockTransforms, context); + block.RunTransforms(PostOrderTransforms, context); context.Stepper.EndGroup(); } }