Browse Source

Upgrade ilasm.exe version. This allows us to write tests for the new function pointer calling conventions.

pull/2179/head
Daniel Grunwald 5 years ago
parent
commit
836bc37050
  1. 21
      ICSharpCode.Decompiler.Tests/Helpers/Tester.cs
  2. 3
      ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj
  3. 7
      ICSharpCode.Decompiler.Tests/ILPrettyTestRunner.cs
  4. 16
      ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Unsafe.il
  5. 3
      packages.props

21
ICSharpCode.Decompiler.Tests/Helpers/Tester.cs

@ -22,7 +22,6 @@ using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Reflection.Metadata;
using System.Reflection.PortableExecutable; using System.Reflection.PortableExecutable;
using System.Text; using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
@ -41,7 +40,6 @@ using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Emit; using Microsoft.CodeAnalysis.Emit;
using Microsoft.CodeAnalysis.Text; using Microsoft.CodeAnalysis.Text;
using Microsoft.CSharp; using Microsoft.CSharp;
using Microsoft.DiaSymReader.Tools;
using NUnit.Framework; using NUnit.Framework;
@ -70,18 +68,31 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
UseDebug = 0x1, UseDebug = 0x1,
Force32Bit = 0x2, Force32Bit = 0x2,
Library = 0x4, Library = 0x4,
/// Testing our own disassembler, or working around a bug in ildasm.
UseOwnDisassembler = 0x8, UseOwnDisassembler = 0x8,
/// Work around bug in .NET 5 ilasm (https://github.com/dotnet/runtime/issues/32400)
UseLegacyAssembler = 0x10,
} }
public static partial class Tester public static partial class Tester
{ {
public static readonly string TestCasePath = Path.Combine( public static readonly string TestCasePath = Path.Combine(
Path.GetDirectoryName(typeof(Tester).Assembly.Location), Path.GetDirectoryName(typeof(Tester).Assembly.Location),
"../../../TestCases"); "../../../TestCases");
public static string AssembleIL(string sourceFileName, AssemblerOptions options = AssemblerOptions.UseDebug) public static string AssembleIL(string sourceFileName, AssemblerOptions options = AssemblerOptions.UseDebug)
{ {
string ilasmPath = Path.Combine(Environment.GetEnvironmentVariable("windir"), @"Microsoft.NET\Framework\v4.0.30319\ilasm.exe"); string ilasmPath;
if (options.HasFlag(AssemblerOptions.UseLegacyAssembler))
{
ilasmPath = Path.Combine(Environment.GetEnvironmentVariable("windir"), @"Microsoft.NET\Framework\v4.0.30319\ilasm.exe");
}
else
{
ilasmPath = Path.Combine(
Path.GetDirectoryName(typeof(Tester).Assembly.Location),
"ilasm.exe");
}
string outputFile = Path.Combine(Path.GetDirectoryName(sourceFileName), Path.GetFileNameWithoutExtension(sourceFileName)); string outputFile = Path.Combine(Path.GetDirectoryName(sourceFileName), Path.GetFileNameWithoutExtension(sourceFileName));
string otherOptions = " "; string otherOptions = " ";
if (options.HasFlag(AssemblerOptions.Force32Bit)) if (options.HasFlag(AssemblerOptions.Force32Bit))

3
ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj

@ -53,6 +53,7 @@
<PackageReference Include="NUnit" Version="$(NUnitVersion)" /> <PackageReference Include="NUnit" Version="$(NUnitVersion)" />
<PackageReference Include="System.Memory" Version="4.5.4" /> <PackageReference Include="System.Memory" Version="4.5.4" />
<PackageReference Include="Mono.Cecil" Version="$(MonoCecilVersion)" /> <PackageReference Include="Mono.Cecil" Version="$(MonoCecilVersion)" />
<PackageReference Include="Microsoft.NETCore.ILAsm" Version="$(ILAsmVersion)" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
@ -305,4 +306,4 @@
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" /> <Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup> </ItemGroup>
</Project> </Project>

7
ICSharpCode.Decompiler.Tests/ILPrettyTestRunner.cs

@ -203,7 +203,7 @@ namespace ICSharpCode.Decompiler.Tests
[Test] [Test]
public void Unsafe() public void Unsafe()
{ {
Run(); Run(assemblerOptions: AssemblerOptions.Library | AssemblerOptions.UseLegacyAssembler);
} }
[Test] [Test]
@ -232,12 +232,13 @@ namespace ICSharpCode.Decompiler.Tests
Run(); Run();
} }
void Run([CallerMemberName] string testName = null, DecompilerSettings settings = null) void Run([CallerMemberName] string testName = null, DecompilerSettings settings = null,
AssemblerOptions assemblerOptions = AssemblerOptions.Library)
{ {
var ilFile = Path.Combine(TestCasePath, testName + ".il"); var ilFile = Path.Combine(TestCasePath, testName + ".il");
var csFile = Path.Combine(TestCasePath, testName + ".cs"); var csFile = Path.Combine(TestCasePath, testName + ".cs");
var executable = Tester.AssembleIL(ilFile, AssemblerOptions.Library); var executable = Tester.AssembleIL(ilFile, assemblerOptions);
var decompiled = Tester.DecompileCSharp(executable, settings); var decompiled = Tester.DecompileCSharp(executable, settings);
CodeAssert.FilesAreEqual(csFile, decompiled); CodeAssert.FilesAreEqual(csFile, decompiled);

16
ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Unsafe.il

@ -6,6 +6,12 @@
.ver 4:0:0:0 .ver 4:0:0:0
} }
.assembly extern System.Console
{
.publickeytoken = (B0 3F 5F 7F 11 D5 0A 3A )
.ver 4:0:0:0
}
.assembly System.Runtime.CompilerServices.Unsafe .assembly System.Runtime.CompilerServices.Unsafe
{ {
.custom instance void [CORE_ASSEMBLY]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 ) .custom instance void [CORE_ASSEMBLY]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 )
@ -495,7 +501,7 @@
lbl: lbl:
ldloc.0 ldloc.0
ldind.i2 ldind.i2
call void [mscorlib]System.Console::WriteLine(uint16) call void [System.Console]System.Console::WriteLine(uint16)
ldloc.0 ldloc.0
ret ret
@ -528,7 +534,7 @@ lbl:
IL_000c: ldloc.1 IL_000c: ldloc.1
IL_000d: ldc.i4.0 IL_000d: ldc.i4.0
IL_000e: ldelema [mscorlib]System.Byte IL_000e: ldelema [System.Runtime]System.Byte
IL_0013: stloc.2 IL_0013: stloc.2
IL_0014: br.s IL_0019 IL_0014: br.s IL_0019
@ -566,12 +572,12 @@ lbl:
*/ */
.maxstack 3 .maxstack 3
.locals /* 11000004 */ ( .locals /* 11000004 */ (
[0] int32& pinned modopt([mscorlib]System.Runtime.CompilerServices.IsExplicitlyDereferenced) p [0] int32& pinned modopt([System.Runtime]System.Runtime.CompilerServices.IsExplicitlyDereferenced) p
) )
IL_0000: ldarg.1 IL_0000: ldarg.1
IL_0001: ldc.i4.0 IL_0001: ldc.i4.0
IL_0002: ldelema [mscorlib]System.Int32 /* 01000016 */ IL_0002: ldelema [System.Runtime]System.Int32 /* 01000016 */
IL_0007: stloc.0 IL_0007: stloc.0
IL_0008: ldloc.0 IL_0008: ldloc.0
IL_0009: ldind.i4 IL_0009: ldind.i4
@ -581,7 +587,7 @@ lbl:
IL_000d: ldarg.2 IL_000d: ldarg.2
IL_000e: ldloc.0 IL_000e: ldloc.0
IL_000f: ldind.i4 IL_000f: ldind.i4
IL_0010: ldelema [mscorlib]System.Int32 /* 01000016 */ IL_0010: ldelema [System.Runtime]System.Int32 /* 01000016 */
IL_0015: stloc.0 IL_0015: stloc.0
IL_0016: ldloc.0 IL_0016: ldloc.0

3
packages.props

@ -5,7 +5,8 @@
<HumanizerVersion>2.2.0</HumanizerVersion> <HumanizerVersion>2.2.0</HumanizerVersion>
<SystemCollectionsImmutableVersion>5.0.0-preview.8.20407.11</SystemCollectionsImmutableVersion> <SystemCollectionsImmutableVersion>5.0.0-preview.8.20407.11</SystemCollectionsImmutableVersion>
<SystemReflectionMetadataVersion>5.0.0-preview.8.20407.11</SystemReflectionMetadataVersion> <SystemReflectionMetadataVersion>5.0.0-preview.8.20407.11</SystemReflectionMetadataVersion>
<RoslynVersion>3.8.0-3.final</RoslynVersion> <ILAsmVersion>5.0.0-rc.1.20451.14</ILAsmVersion> <!-- Microsoft.NETCore.ILAsm -->
<RoslynVersion>3.8.0-3.final</RoslynVersion> <!-- Microsoft.CodeAnalysis.* -->
<MonoCecilVersion>0.10.3</MonoCecilVersion> <MonoCecilVersion>0.10.3</MonoCecilVersion>
<AvalonEditVersion>6.1.0-preview1</AvalonEditVersion> <AvalonEditVersion>6.1.0-preview1</AvalonEditVersion>
<NUnitVersion>3.12.0</NUnitVersion> <NUnitVersion>3.12.0</NUnitVersion>

Loading…
Cancel
Save