Browse Source

Add RemoveDeadCode option

pull/925/merge
Siegfried Pammer 8 years ago
parent
commit
d2f2a13982
  1. 14
      ICSharpCode.Decompiler/DecompilerSettings.cs
  2. 2
      ICSharpCode.Decompiler/IL/Transforms/RemoveDeadVariableInit.cs
  3. 1
      ILSpy/Options/DecompilerSettingsPanel.xaml

14
ICSharpCode.Decompiler/DecompilerSettings.cs

@ -390,6 +390,20 @@ namespace ICSharpCode.Decompiler @@ -390,6 +390,20 @@ namespace ICSharpCode.Decompiler
#endregion
#region Options to aid F# decompilation
bool removeDeadCode = false;
public bool RemoveDeadCode {
get { return removeDeadCode; }
set {
if (removeDeadCode != value) {
removeDeadCode = value;
OnPropertyChanged();
}
}
}
#endregion
#region Assembly Load and Resolve options
bool loadInMemory = false;

2
ICSharpCode.Decompiler/IL/Transforms/RemoveDeadVariableInit.cs

@ -44,6 +44,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -44,6 +44,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
// This is necessary to remove useless stores generated by some compilers, e.g., the F# compiler.
// In yield return + async, the C# compiler tends to store null/default(T) to variables
// when the variable goes out of scope.
if (function.IsAsync || function.IsIterator || context.Settings.RemoveDeadCode) {
var variableQueue = new Queue<ILVariable>(function.Variables);
while (variableQueue.Count > 0) {
var v = variableQueue.Dequeue();
@ -67,3 +68,4 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -67,3 +68,4 @@ namespace ICSharpCode.Decompiler.IL.Transforms
}
}
}
}

1
ILSpy/Options/DecompilerSettingsPanel.xaml

@ -14,5 +14,6 @@ @@ -14,5 +14,6 @@
<CheckBox IsChecked="{Binding ShowDebugInfo}">Show info from debug symbols, if available</CheckBox>
<CheckBox IsChecked="{Binding ShowXmlDocumentation}">Show XML documentation in decompiled code</CheckBox>
<CheckBox IsChecked="{Binding FoldBraces}">Enable folding on all blocks in braces</CheckBox>
<CheckBox IsChecked="{Binding RemoveDeadCode}">Remove dead and side effect free code.</CheckBox>
</StackPanel>
</UserControl>
Loading…
Cancel
Save