Browse Source

Distinguish between PreOrderTransforms and PostOrderTransforms in BlockILTransform.

pull/728/merge
Daniel Grunwald 9 years ago
parent
commit
5530f7ec2e
  1. 33
      ICSharpCode.Decompiler.sln
  2. 43
      ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs
  3. 7
      ICSharpCode.Decompiler/ICSharpCode.Decompiler.ruleset
  4. 15
      ICSharpCode.Decompiler/IL/Transforms/BlockTransform.cs

33
ICSharpCode.Decompiler.sln

@ -1,21 +1,14 @@ @@ -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 @@ -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 @@ -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

43
ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs

@ -57,26 +57,35 @@ namespace ICSharpCode.Decompiler.CSharp @@ -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(),
};
}

7
ICSharpCode.Decompiler/ICSharpCode.Decompiler.ruleset

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<RuleSet Name="Rules for ICSharpCode.Decompiler" Description="Code analysis rules for ICSharpCode.Decompiler.csproj." ToolsVersion="14.0">
<RuleSet Name="Rules for ICSharpCode.Decompiler" Description="Code analysis rules for ICSharpCode.Decompiler.csproj." ToolsVersion="15.0">
<Rules AnalyzerId="Microsoft.Analyzers.ManagedCodeAnalysis" RuleNamespace="Microsoft.Rules.Managed">
<Rule Id="CA1001" Action="Warning" />
<Rule Id="CA1009" Action="Warning" />
@ -64,6 +64,9 @@ @@ -64,6 +64,9 @@
<Rule Id="CA2241" Action="Warning" />
<Rule Id="CA2242" Action="Warning" />
</Rules>
<Rules AnalyzerId="Microsoft.CodeAnalysis.CSharp.Features" RuleNamespace="Microsoft.CodeAnalysis.CSharp.Features">
<Rule Id="IDE0017" Action="None" />
</Rules>
<Rules AnalyzerId="RefactoringEssentials" RuleNamespace="RefactoringEssentials">
<Rule Id="CS0126ReturnMustBeFollowedByAnyExpression" Action="None" />
<Rule Id="CS0169FieldIsNeverUsedAnalyzer" Action="None" />
@ -75,7 +78,5 @@ @@ -75,7 +78,5 @@
<Rule Id="InconsistentNaming" Action="None" />
<Rule Id="ProhibitedModifiersAnalyzer" Action="None" />
<Rule Id="RECS0001" Action="Info" />
<Rule Id="RECS0091" Action="Hidden" />
<Rule Id="RECS0113" Action="Hidden" />
</Rules>
</RuleSet>

15
ICSharpCode.Decompiler/IL/Transforms/BlockTransform.cs

@ -64,12 +64,8 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -64,12 +64,8 @@ namespace ICSharpCode.Decompiler.IL.Transforms
/// </summary>
public class BlockILTransform : IILTransform
{
readonly IBlockTransform[] blockTransforms;
public BlockILTransform(params IBlockTransform[] blockTransforms)
{
this.blockTransforms = blockTransforms;
}
public IList<IBlockTransform> PreOrderTransforms { get; } = new List<IBlockTransform>();
public IList<IBlockTransform> PostOrderTransforms { get; } = new List<IBlockTransform>();
public void Run(ILFunction function, ILTransformContext context)
{
@ -94,6 +90,11 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -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 @@ -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();
}
}

Loading…
Cancel
Save