Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
kekyo committed Feb 8, 2024
1 parent efa7308 commit 211bd0e
Show file tree
Hide file tree
Showing 6 changed files with 196 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@

// .NET IL Disassembler. Version 8.0.0



// Metadata version: v4.0.30319
.assembly extern System.Private.CoreLib
{
.publickey = (00 24 00 00 04 80 00 00 94 00 00 00 06 02 00 00 // .$..............
00 24 00 00 52 53 41 31 00 04 00 00 01 00 01 00 // .$..RSA1........
8D 56 C7 6F 9E 86 49 38 30 49 F3 83 C4 4B E0 EC // .V.o..I80I...K..
20 41 81 82 2A 6C 31 CF 5E B7 EF 48 69 44 D0 32 // A..*l1.^..HiD.2
18 8E A1 D3 92 07 63 71 2C CB 12 D7 5F B7 7E 98 // ......cq,..._.~.
11 14 9E 61 48 E5 D3 2F BA AB 37 61 1C 18 78 DD // ...aH../..7a..x.
C1 9E 20 EF 13 5D 0C B2 CF F2 BF EC 3D 11 58 10 // .. ..]......=.X.
C3 D9 06 96 38 FE 4B E2 15 DB F7 95 86 19 20 E5 // ....8.K....... .
AB 6F 7D B2 E2 CE EF 13 6A C2 3D 5D D2 BF 03 17 // .o}.....j.=]....
00 AE C2 32 F6 C6 B1 C7 85 B4 30 5C 12 3B 37 AB ) // ...2......0\.;7.
.ver 6:0:0:0
}
.assembly extern mscorlib
{
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4..
.ver 4:0:0:0
}
.assembly output
{
.custom instance void [mscorlib]System.Runtime.Versioning.TargetFrameworkAttribute::.ctor(string) = ( 01 00 18 2E 4E 45 54 43 6F 72 65 41 70 70 2C 56 // ....NETCoreApp,V
65 72 73 69 6F 6E 3D 76 37 2E 30 00 00 ) // ersion=v7.0..
.ver 1:0:0:0
}
.module output.dll
.imagebase 0x00400000
.file alignment 0x00000200
.stackreserve 0x00100000
.subsystem 0x0003 // WINDOWS_CUI
.corflags 0x00000001 // ILONLY


// ================== GLOBAL METHODS =========================

.method assembly static int32 _start() cil managed
{
.entrypoint
// Code size 6 (0x6)
.maxstack 8
IL_0000: call int32 C.text::main()
IL_0005: ret
} // end of global method _start


// =============================================================


// =============== CLASS MEMBERS DECLARATION ===================

.class public abstract auto ansi sealed C.text
extends [System.Private.CoreLib]System.Object
{
.method public static int32 main() cil managed
{
// Code size 2 (0x2)
.maxstack 8
IL_0000: ldc.i4.1
IL_0001: ret
} // end of method text::main

} // end of class C.text


// =============================================================

// *********** DISASSEMBLY COMPLETE ***********************
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@

// .NET IL Disassembler. Version 8.0.0



// Metadata version: v4.0.30319
.assembly extern System.Private.CoreLib
{
.publickey = (00 24 00 00 04 80 00 00 94 00 00 00 06 02 00 00 // .$..............
00 24 00 00 52 53 41 31 00 04 00 00 01 00 01 00 // .$..RSA1........
8D 56 C7 6F 9E 86 49 38 30 49 F3 83 C4 4B E0 EC // .V.o..I80I...K..
20 41 81 82 2A 6C 31 CF 5E B7 EF 48 69 44 D0 32 // A..*l1.^..HiD.2
18 8E A1 D3 92 07 63 71 2C CB 12 D7 5F B7 7E 98 // ......cq,..._.~.
11 14 9E 61 48 E5 D3 2F BA AB 37 61 1C 18 78 DD // ...aH../..7a..x.
C1 9E 20 EF 13 5D 0C B2 CF F2 BF EC 3D 11 58 10 // .. ..]......=.X.
C3 D9 06 96 38 FE 4B E2 15 DB F7 95 86 19 20 E5 // ....8.K....... .
AB 6F 7D B2 E2 CE EF 13 6A C2 3D 5D D2 BF 03 17 // .o}.....j.=]....
00 AE C2 32 F6 C6 B1 C7 85 B4 30 5C 12 3B 37 AB ) // ...2......0\.;7.
.ver 6:0:0:0
}
.assembly extern mscorlib
{
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4..
.ver 4:0:0:0
}
.assembly output
{
.custom instance void [mscorlib]System.Runtime.Versioning.TargetFrameworkAttribute::.ctor(string) = ( 01 00 18 2E 4E 45 54 43 6F 72 65 41 70 70 2C 56 // ....NETCoreApp,V
65 72 73 69 6F 6E 3D 76 37 2E 30 00 00 ) // ersion=v7.0..
.ver 1:0:0:0
}
.module output.dll
.imagebase 0x00400000
.file alignment 0x00000200
.stackreserve 0x00100000
.subsystem 0x0002 // WINDOWS_GUI
.corflags 0x00000001 // ILONLY


// ================== GLOBAL METHODS =========================

.method assembly static int32 _start() cil managed
{
.entrypoint
// Code size 6 (0x6)
.maxstack 8
IL_0000: call int32 C.text::main()
IL_0005: ret
} // end of global method _start


// =============================================================


// =============== CLASS MEMBERS DECLARATION ===================

.class public abstract auto ansi sealed C.text
extends [System.Private.CoreLib]System.Object
{
.method public static int32 main() cil managed
{
// Code size 2 (0x2)
.maxstack 8
IL_0000: ldc.i4.1
IL_0001: ret
} // end of method text::main

} // end of class C.text


// =============================================================

// *********** DISASSEMBLY COMPLETE ***********************
24 changes: 24 additions & 0 deletions chibias.core.Tests/AssemblerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2689,4 +2689,28 @@ .function public int32() main
targetFrameworkMoniker: "net7.0");
return Verify(actual);
}

[Test]
public Task TfmSpecificCoreApp70InExe()
{
var actual = Run(@"
.function public int32() main
ldc.i4.1
ret",
AssemblyTypes.Exe,
targetFrameworkMoniker: "net7.0");
return Verify(actual);
}

[Test]
public Task TfmSpecificCoreApp70InWinExe()
{
var actual = Run(@"
.function public int32() main
ldc.i4.1
ret",
AssemblyTypes.WinExe,
targetFrameworkMoniker: "net7.0");
return Verify(actual);
}
}
7 changes: 2 additions & 5 deletions chibias.core.Tests/Runner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ namespace chibias;

partial class AssemblerTests
{
private static readonly bool isWindows =
Environment.OSVersion.Platform == PlatformID.Win32NT;

private readonly string id =
$"{DateTime.Now:yyyyMMdd_HHmmss_fff}_{new Random().Next()}";

Expand Down Expand Up @@ -55,7 +52,7 @@ private string Run(
var coreLibPath = Path.GetFullPath("mscorlib.dll");
var tmp2Path = Path.GetFullPath("tmp2.dll");
var appHostTemplatePath = Path.GetFullPath(
isWindows ? "apphost.exe" : "apphost.linux-x64");
Utilities.IsInWindows ? "apphost.exe" : "apphost.linux-x64");

var referenceAssemblyBasePaths = new[]
{
Expand Down Expand Up @@ -101,7 +98,7 @@ private string Run(
var psi = new ProcessStartInfo()
{
FileName = Path.GetFullPath(
isWindows ? "ildasm.exe" : "ildasm.linux-x64"),
Utilities.IsInWindows ? "ildasm.exe" : "ildasm.linux-x64"),
Arguments = $"-utf8 -out={disassembledPath} {outputAssemblyPath}"
};

Expand Down
35 changes: 21 additions & 14 deletions chibias.core/Assembler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -308,17 +308,24 @@ private bool Run(
{
var produceExecutable =
options.AssemblyType != AssemblyTypes.Dll;

var outputFullPath = Path.GetFullPath(outputAssemblyPath);
var outputAssemblyCandidateFullPath =
(produceExecutable &&
options.TargetFramework.Identifier == TargetFrameworkIdentifiers.NETCoreApp &&
options.AppHostTemplatePath is { } appHostTemplatePath1 &&
!string.IsNullOrWhiteSpace(appHostTemplatePath1)) ?
Path.Combine(
Utilities.GetDirectoryPath(outputFullPath),
Path.GetFileNameWithoutExtension(outputFullPath) + ".dll") :
outputFullPath;

var requireAppHost =
produceExecutable &&
options.TargetFramework.Identifier == TargetFrameworkIdentifiers.NETCoreApp &&
options.AppHostTemplatePath is { } appHostTemplatePath &&
!string.IsNullOrWhiteSpace(appHostTemplatePath);

var outputAssemblyFullPath = Path.GetFullPath(outputAssemblyPath);
var outputAssemblyCandidateFullPath = requireAppHost?
Path.Combine(
Utilities.GetDirectoryPath(outputAssemblyFullPath),
Path.GetFileNameWithoutExtension(outputAssemblyFullPath) + ".dll") :
outputAssemblyFullPath;
var outputFullPath = requireAppHost ?
Path.Combine(
Utilities.GetDirectoryPath(outputAssemblyFullPath),
Path.GetFileNameWithoutExtension(outputAssemblyFullPath) + (Utilities.IsInWindows ? ".exe" : "")) :
outputAssemblyFullPath;

//////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -454,13 +461,13 @@ options.AppHostTemplatePath is { } appHostTemplatePath1 &&
options);
}

if (options.AppHostTemplatePath is { } appHostTemplatePath2 &&
!string.IsNullOrWhiteSpace(appHostTemplatePath2))
if (options.AppHostTemplatePath is { } appHostTemplatePath3 &&
!string.IsNullOrWhiteSpace(appHostTemplatePath3))
{
this.WriteAppHost(
outputFullPath,
outputAssemblyCandidateFullPath,
Path.GetFullPath(appHostTemplatePath2),
Path.GetFullPath(appHostTemplatePath3),
options);
}
}
Expand Down
3 changes: 3 additions & 0 deletions chibias.core/Internal/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ namespace chibias.Internal;

internal static class Utilities
{
public static readonly bool IsInWindows =
Environment.OSVersion.Platform == PlatformID.Win32NT;

#if NET40 || NET45
private static class ArrayEmpty<T>
{
Expand Down

0 comments on commit 211bd0e

Please sign in to comment.