mirror of https://github.com/icsharpcode/ILSpy.git
10 changed files with 203 additions and 4 deletions
@ -0,0 +1,55 @@
@@ -0,0 +1,55 @@
|
||||
// Copyright (c) 2015 Siegfried Pammer
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
||||
// software and associated documentation files (the "Software"), to deal in the Software
|
||||
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
||||
// to whom the Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all copies or
|
||||
// substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
||||
// 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.Linq; |
||||
using ICSharpCode.NRefactory.TypeSystem; |
||||
using ICSharpCode.NRefactory.TypeSystem.Implementation; |
||||
|
||||
namespace ICSharpCode.Decompiler.IL.Transforms |
||||
{ |
||||
/// <summary>
|
||||
/// Description of TransformInlineAssignment.
|
||||
/// </summary>
|
||||
public class TransformInlineAssignment : IILTransform |
||||
{ |
||||
ILTransformContext context; |
||||
|
||||
void IILTransform.Run(ILFunction function, ILTransformContext context) |
||||
{ |
||||
this.context = context; |
||||
foreach (var block in function.Descendants.OfType<Block>()) { |
||||
for (int i = block.Instructions.Count - 1; i >= 0; i--) { |
||||
var inst = block.Instructions[i] as StLoc; |
||||
var nextInst = block.Instructions.ElementAtOrDefault(i + 1) as StLoc; |
||||
ILVariable localVariable; |
||||
// stloc s(value)
|
||||
// stloc l(ldloc s)
|
||||
// -->
|
||||
// stloc s(stloc l(value))
|
||||
if (inst != null && nextInst != null && nextInst.Variable.Kind != VariableKind.StackSlot && nextInst.Value.MatchLdLoc(inst.Variable)) { |
||||
block.Instructions.RemoveAt(i + 1); |
||||
var value = inst.Value.Clone(); |
||||
inst.Value.ReplaceWith(new StLoc(nextInst.Variable, value)); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,40 @@
@@ -0,0 +1,40 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
||||
// software and associated documentation files (the "Software"), to deal in the Software
|
||||
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
||||
// to whom the Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all copies or
|
||||
// substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
||||
// 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; |
||||
|
||||
namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty |
||||
{ |
||||
public class InlineAssignmentTest |
||||
{ |
||||
public static void Main() |
||||
{ |
||||
|
||||
} |
||||
|
||||
public void SimpleInlineWithLocals() |
||||
{ |
||||
int V_0; |
||||
Console.WriteLine(V_0 = 5); |
||||
Console.WriteLine(V_0); |
||||
InlineAssignmentTest V_1; |
||||
Console.WriteLine((object)(V_1 = new InlineAssignmentTest())); |
||||
Console.WriteLine((object)V_1); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,91 @@
@@ -0,0 +1,91 @@
|
||||
|
||||
// Microsoft (R) .NET Framework IL Disassembler. Version 4.0.30319.17929 |
||||
// Copyright (c) Microsoft Corporation. All rights reserved. |
||||
|
||||
|
||||
|
||||
// Metadata version: v4.0.30319 |
||||
.assembly extern mscorlib |
||||
{ |
||||
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. |
||||
.ver 4:0:0:0 |
||||
} |
||||
.assembly '3cbicayo' |
||||
{ |
||||
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 ) |
||||
.custom instance void [mscorlib]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::.ctor() = ( 01 00 01 00 54 02 16 57 72 61 70 4E 6F 6E 45 78 // ....T..WrapNonEx |
||||
63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows. |
||||
.permissionset reqmin |
||||
= {[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {property bool 'SkipVerification' = bool(true)}} |
||||
.hash algorithm 0x00008004 |
||||
.ver 0:0:0:0 |
||||
} |
||||
.module '3cbicayo.exe' |
||||
// MVID: {3A96AD80-B3A9-47A7-82A9-A9BE249D0492} |
||||
.custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 ) |
||||
.imagebase 0x00400000 |
||||
.file alignment 0x00000200 |
||||
.stackreserve 0x00100000 |
||||
.subsystem 0x0003 // WINDOWS_CUI |
||||
.corflags 0x00000001 // ILONLY |
||||
// Image base: 0x01100000 |
||||
|
||||
|
||||
// =============== CLASS MEMBERS DECLARATION =================== |
||||
|
||||
.class public auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Pretty.InlineAssignmentTest |
||||
extends [mscorlib]System.Object |
||||
{ |
||||
.method public hidebysig static void Main() cil managed |
||||
{ |
||||
.entrypoint |
||||
// Code size 2 (0x2) |
||||
.maxstack 8 |
||||
IL_0000: nop |
||||
IL_0001: ret |
||||
} // end of method InlineAssignmentTest::Main |
||||
|
||||
.method public hidebysig instance void |
||||
SimpleInlineWithLocals() cil managed |
||||
{ |
||||
// Code size 38 (0x26) |
||||
.maxstack 2 |
||||
.locals init (int32 V_0, |
||||
class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InlineAssignmentTest V_1) |
||||
IL_0000: nop |
||||
IL_0001: ldc.i4.5 |
||||
IL_0002: dup |
||||
IL_0003: stloc.0 |
||||
IL_0004: call void [mscorlib]System.Console::WriteLine(int32) |
||||
IL_0009: nop |
||||
IL_000a: ldloc.0 |
||||
IL_000b: call void [mscorlib]System.Console::WriteLine(int32) |
||||
IL_0010: nop |
||||
IL_0011: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InlineAssignmentTest::.ctor() |
||||
IL_0016: dup |
||||
IL_0017: stloc.1 |
||||
IL_0018: call void [mscorlib]System.Console::WriteLine(object) |
||||
IL_001d: nop |
||||
IL_001e: ldloc.1 |
||||
IL_001f: call void [mscorlib]System.Console::WriteLine(object) |
||||
IL_0024: nop |
||||
IL_0025: ret |
||||
} // end of method InlineAssignmentTest::SimpleInlineWithLocals |
||||
|
||||
.method public hidebysig specialname rtspecialname |
||||
instance void .ctor() cil managed |
||||
{ |
||||
// Code size 7 (0x7) |
||||
.maxstack 8 |
||||
IL_0000: ldarg.0 |
||||
IL_0001: call instance void [mscorlib]System.Object::.ctor() |
||||
IL_0006: ret |
||||
} // end of method InlineAssignmentTest::.ctor |
||||
|
||||
} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InlineAssignmentTest |
||||
|
||||
|
||||
// ============================================================= |
||||
|
||||
// *********** DISASSEMBLY COMPLETE *********************** |
||||
// WARNING: Created Win32 resource file ../../Tests/TestCases/Pretty\InlineAssignmentTest.res |
Loading…
Reference in new issue