From 2509f272235f9773e50a0cbf507b0825e0d8bb75 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sun, 14 Jun 2015 20:35:29 +0200 Subject: [PATCH] * Rename ControlFlowSimplification to ConditionDetection * Rename OptimizingTransform to ControlFlowSimplification * Move control flow transforms to separate namespace. --- ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs | 10 +++------- .../FlowAnalysis/ControlFlowNode.cs | 6 ------ ICSharpCode.Decompiler/FlowAnalysis/Dominance.cs | 1 + .../ICSharpCode.Decompiler.csproj | 9 +++++---- .../ConditionDetection.cs} | 4 ++-- .../ControlFlowSimplification.cs} | 13 ++++++------- .../IntroduceExitPoints.cs | 5 +++-- .../IL/{Transforms => ControlFlow}/LoopDetection.cs | 4 ++-- 8 files changed, 22 insertions(+), 30 deletions(-) rename ICSharpCode.Decompiler/IL/{Transforms/ControlFlowSimplification.cs => ControlFlow/ConditionDetection.cs} (98%) rename ICSharpCode.Decompiler/IL/{Transforms/OptimizingTransform.cs => ControlFlow/ControlFlowSimplification.cs} (93%) rename ICSharpCode.Decompiler/IL/{Transforms => ControlFlow}/IntroduceExitPoints.cs (96%) rename ICSharpCode.Decompiler/IL/{Transforms => ControlFlow}/LoopDetection.cs (99%) diff --git a/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs b/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs index d2ea0aec9..8abb4b94c 100644 --- a/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs +++ b/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs @@ -20,18 +20,14 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; -using System.Text; using System.Threading; -using System.Threading.Tasks; -using ICSharpCode.NRefactory; using ICSharpCode.NRefactory.CSharp; using ICSharpCode.NRefactory.CSharp.Refactoring; using ICSharpCode.NRefactory.TypeSystem; -using ICSharpCode.NRefactory.TypeSystem.Implementation; -using ICSharpCode.NRefactory.Utils; using Mono.Cecil; using ICSharpCode.Decompiler.CSharp.Transforms; using ICSharpCode.Decompiler.IL; +using ICSharpCode.Decompiler.IL.ControlFlow; using ICSharpCode.Decompiler.IL.Transforms; namespace ICSharpCode.Decompiler.CSharp @@ -48,10 +44,10 @@ namespace ICSharpCode.Decompiler.CSharp readonly DecompilerSettings settings; List ilTransforms = new List { - new OptimizingTransform(), + new ControlFlowSimplification(), new LoopDetection(), new IntroduceExitPoints(), - new ControlFlowSimplification(), + new ConditionDetection(), new ILInlining(), new TransformingVisitor(), new ExpressionTransforms(), diff --git a/ICSharpCode.Decompiler/FlowAnalysis/ControlFlowNode.cs b/ICSharpCode.Decompiler/FlowAnalysis/ControlFlowNode.cs index 5a9dac0ed..e48feaf12 100644 --- a/ICSharpCode.Decompiler/FlowAnalysis/ControlFlowNode.cs +++ b/ICSharpCode.Decompiler/FlowAnalysis/ControlFlowNode.cs @@ -18,14 +18,8 @@ using System; using System.Collections.Generic; -using System.Diagnostics; -using System.IO; using System.Linq; -using ICSharpCode.NRefactory.Utils; -using ICSharpCode.Decompiler.Disassembler; -using Mono.Cecil.Cil; - namespace ICSharpCode.Decompiler.FlowAnalysis { /// diff --git a/ICSharpCode.Decompiler/FlowAnalysis/Dominance.cs b/ICSharpCode.Decompiler/FlowAnalysis/Dominance.cs index d9165e2af..04d51d957 100644 --- a/ICSharpCode.Decompiler/FlowAnalysis/Dominance.cs +++ b/ICSharpCode.Decompiler/FlowAnalysis/Dominance.cs @@ -15,6 +15,7 @@ // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. + using System; using System.Collections.Generic; using System.Diagnostics; diff --git a/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj b/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj index 0ad496409..84fbb28db 100644 --- a/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj +++ b/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj @@ -81,6 +81,10 @@ + + + + True True @@ -109,12 +113,8 @@ - - - - @@ -185,6 +185,7 @@ + diff --git a/ICSharpCode.Decompiler/IL/Transforms/ControlFlowSimplification.cs b/ICSharpCode.Decompiler/IL/ControlFlow/ConditionDetection.cs similarity index 98% rename from ICSharpCode.Decompiler/IL/Transforms/ControlFlowSimplification.cs rename to ICSharpCode.Decompiler/IL/ControlFlow/ConditionDetection.cs index 00b55f581..a3c26c701 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/ControlFlowSimplification.cs +++ b/ICSharpCode.Decompiler/IL/ControlFlow/ConditionDetection.cs @@ -21,7 +21,7 @@ using System.Diagnostics; using System.Linq; using ICSharpCode.Decompiler.FlowAnalysis; -namespace ICSharpCode.Decompiler.IL.Transforms +namespace ICSharpCode.Decompiler.IL.ControlFlow { /// /// Detects 'if' structure and other non-loop aspects of control flow. @@ -31,7 +31,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms /// Blocks should be basic blocks prior to this transform. /// After this transform, they will be extended basic blocks. /// - public class ControlFlowSimplification : IILTransform + public class ConditionDetection : IILTransform { public void Run(ILFunction function, ILTransformContext context) { diff --git a/ICSharpCode.Decompiler/IL/Transforms/OptimizingTransform.cs b/ICSharpCode.Decompiler/IL/ControlFlow/ControlFlowSimplification.cs similarity index 93% rename from ICSharpCode.Decompiler/IL/Transforms/OptimizingTransform.cs rename to ICSharpCode.Decompiler/IL/ControlFlow/ControlFlowSimplification.cs index bd9664f48..5b5e3f5e9 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/OptimizingTransform.cs +++ b/ICSharpCode.Decompiler/IL/ControlFlow/ControlFlowSimplification.cs @@ -20,21 +20,21 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; -namespace ICSharpCode.Decompiler.IL.Transforms +namespace ICSharpCode.Decompiler.IL.ControlFlow { /// - /// This transform 'optimizes' the IL code: it replaces constructs that - /// are generated by the C# compiler in debug mode with shorter constructs - /// that are more straightforward to analyze. + /// This transform 'optimizes' the control flow logic in the IL code: + /// it replaces constructs that are generated by the C# compiler in debug mode + /// with shorter constructs that are more straightforward to analyze. /// /// - /// The optimizations performed are: + /// The transformations performed are: /// * 'nop' instructions are removed /// * branches that lead to other branches are replaced with branches that directly jump to the destination /// * branches that lead to a 'return block' are replaced with a return instruction /// * basic blocks are combined where possible /// - public class OptimizingTransform : IILTransform + public class ControlFlowSimplification : IILTransform { public void Run(ILFunction function, ILTransformContext context) { @@ -109,7 +109,6 @@ namespace ICSharpCode.Decompiler.IL.Transforms { Debug.Assert(container == block.Parent); // Ensure the block will stay a basic block -- we don't want extended basic blocks prior to LoopDetection. - // TODO: when LoopDetection is complete, check that it really can't handle EBBs if (block.Instructions.Count > 1 && block.Instructions[block.Instructions.Count - 2].HasFlag(InstructionFlags.MayBranch)) return false; Branch br = block.Instructions.Last() as Branch; diff --git a/ICSharpCode.Decompiler/IL/Transforms/IntroduceExitPoints.cs b/ICSharpCode.Decompiler/IL/ControlFlow/IntroduceExitPoints.cs similarity index 96% rename from ICSharpCode.Decompiler/IL/Transforms/IntroduceExitPoints.cs rename to ICSharpCode.Decompiler/IL/ControlFlow/IntroduceExitPoints.cs index 6c183e0ff..8a1dcb73a 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/IntroduceExitPoints.cs +++ b/ICSharpCode.Decompiler/IL/ControlFlow/IntroduceExitPoints.cs @@ -15,10 +15,11 @@ // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. + using System; using System.Diagnostics; -namespace ICSharpCode.Decompiler.IL.Transforms +namespace ICSharpCode.Decompiler.IL.ControlFlow { /// /// Control flow transform: use 'leave' instructions instead of 'br' where possible. @@ -97,7 +98,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms if (currentExit == null) { currentExit = inst; inst.ReplaceWith(new Leave(currentContainer)); - } else if (ControlFlowSimplification.CompatibleExitInstruction(inst, currentExit)) { + } else if (ConditionDetection.CompatibleExitInstruction(inst, currentExit)) { inst.ReplaceWith(new Leave(currentContainer)); } } diff --git a/ICSharpCode.Decompiler/IL/Transforms/LoopDetection.cs b/ICSharpCode.Decompiler/IL/ControlFlow/LoopDetection.cs similarity index 99% rename from ICSharpCode.Decompiler/IL/Transforms/LoopDetection.cs rename to ICSharpCode.Decompiler/IL/ControlFlow/LoopDetection.cs index efa4b2f71..d2834a384 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/LoopDetection.cs +++ b/ICSharpCode.Decompiler/IL/ControlFlow/LoopDetection.cs @@ -15,14 +15,14 @@ // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. + using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; -using ICSharpCode.NRefactory.Utils; using ICSharpCode.Decompiler.FlowAnalysis; -namespace ICSharpCode.Decompiler.IL.Transforms +namespace ICSharpCode.Decompiler.IL.ControlFlow { /// /// Detect loops in IL AST.