Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] .net 8 update #208

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from
22 changes: 20 additions & 2 deletions source/Cosmos.IL2CPU/AppAssembler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,15 @@ public unsafe void GenerateVMTCode(HashSet<Type> aTypesSet, HashSet<MethodBase>
XS.Push((uint)(xType.IsValueType && !xType.IsByRef && !xType.IsPointer && !xType.IsPrimitive ? 1 : 0));

LdStr.PushString(Assembler, xType.Name);
LdStr.PushString(Assembler, xType.AssemblyQualifiedName);

if (xType.AssemblyQualifiedName != null)
{
LdStr.PushString(Assembler, xType.AssemblyQualifiedName);
}
else {
// AssemblyQualifiedName is null for generic types
LdStr.PushString(Assembler, "");
}

Call(VTablesImplRefs.SetTypeInfoRef);

Expand Down Expand Up @@ -1192,7 +1200,17 @@ public void ProcessField(FieldInfo aField)
/// <param name="aTo">The plug</param>
internal void GenerateMethodForward(Il2cpuMethodInfo aFrom, Il2cpuMethodInfo aTo)
{
var xMethodLabel = ILOp.GetLabel(aFrom);
string xMethodLabel;

try
{
xMethodLabel = ILOp.GetLabel(aFrom);
}
catch
{
throw new Exception("Unable to generate method forwarding stub for method: " + aFrom.MethodLabel + ", to " + aTo.MethodLabel);
}

var xEndOfMethodLabel = xMethodLabel + EndOfMethodLabelNameNormal;

// todo: completely get rid of this kind of trampoline code
Expand Down
8 changes: 4 additions & 4 deletions source/Cosmos.IL2CPU/CompilerEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ internal class CompilerEngine
public static TypeResolver TypeResolver { get; private set; }

public static string KernelPkg { get; set; }

private ICompilerEngineSettings mSettings;

private AssemblyLoadContext _assemblyLoadContext;
Expand Down Expand Up @@ -67,22 +67,22 @@ public CompilerEngine(ICompilerEngineSettings aSettings)

if (!File.Exists(mSettings.TargetAssembly))
{
throw new FileNotFoundException("The target assembly path is invalid!", mSettings.TargetAssembly);
throw new FileNotFoundException($@"The target assembly path is invalid! {mSettings.TargetAssembly}", mSettings.TargetAssembly);
}

foreach (var xReference in mSettings.References)
{
if (!File.Exists(xReference))
{
throw new FileNotFoundException("A reference assembly path is invalid!", xReference);
throw new FileNotFoundException($@"A reference assembly path is invalid! {xReference}", xReference);
}
}

foreach (var xPlugsReference in mSettings.PlugsReferences)
{
if (!File.Exists(xPlugsReference))
{
throw new FileNotFoundException("A plugs reference assembly path is invalid!", xPlugsReference);
throw new FileNotFoundException($@"A plugs reference assembly path is invalid! {xPlugsReference}", xPlugsReference);
}
}

Expand Down
4 changes: 2 additions & 2 deletions source/Cosmos.IL2CPU/Cosmos.IL2CPU.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<!--<IsPackable>True</IsPackable>-->
<NoWarn>CA1707;CA1716;$(NoWarn)</NoWarn>
Expand All @@ -18,7 +18,7 @@
<PackageReference Include="System.Reflection.TypeExtensions" Version="4.7.0" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="5.0.0" />
<PackageReference Include="System.Runtime.Loader" Version="4.3.0" />
<PackageReference Include="XSharp" />
<PackageReference Include="XSharp" />
</ItemGroup>

<ItemGroup>
Expand Down
39 changes: 6 additions & 33 deletions source/Cosmos.IL2CPU/IL/Ldvirtftn.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;

using XSharp;
using Cosmos.IL2CPU.ILOpCodes;
using IL2CPU.API;

namespace Cosmos.IL2CPU.X86.IL
{
Expand All @@ -10,37 +12,8 @@ public Ldvirtftn(XSharp.Assembler.Assembler aAsmblr):base(aAsmblr)
{
}

public override void Execute(Il2cpuMethodInfo aMethod, ILOpCode aOpCode) {
DoNullReferenceCheck(Assembler, DebugEnabled, 0);
throw new NotImplementedException();
}


// using System;
// using System.IO;
//
//
// using CPU = XSharp.Assembler.x86;
//
// namespace Cosmos.IL2CPU.IL.X86 {
// [XSharp.Assembler.OpCode(OpCodeEnum.Ldvirtftn)]
// public class Ldvirtftn: Op {
// private string mNextLabel;
// private string mCurLabel;
// private uint mCurOffset;
// private MethodInformation mMethodInformation;
// public Ldvirtftn(ILReader aReader, MethodInformation aMethodInfo)
// : base(aReader, aMethodInfo) {
// mMethodInformation = aMethodInfo;
// mCurOffset = aReader.Position;
// mCurLabel = IL.Op.GetInstructionLabel(aReader);
// mNextLabel = IL.Op.GetInstructionLabel(aReader.NextPosition);
// }
// public override void DoAssemble() {
// EmitNotImplementedException(Assembler, GetServiceProvider(), "Ldvirtftn: This has not been implemented at all yet!", mCurLabel, mMethodInformation, mCurOffset, mNextLabel);
// }
// }
// }

public override void Execute(Il2cpuMethodInfo aMethod, ILOpCode aOpCode) {
XS.Push(LabelName.Get(((OpMethod)aOpCode).Value));
}
}
}
10 changes: 8 additions & 2 deletions source/Cosmos.IL2CPU/ILOpCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,14 @@ public void DoStackAnalysis(Stack<Type> aStack, ref uint aStackOffset)

foreach (var xPushItem in StackPushTypes)
{
aStack.Push(xPushItem);
aStackOffset += ILOp.Align(ILOp.SizeOfType(xPushItem), 4);
if (xPushItem != null)
{
aStack.Push(xPushItem);
aStackOffset += ILOp.Align(ILOp.SizeOfType(xPushItem), 4);
}
else {
throw new Exception("Tried pushing null item to stack while processing " + OpCode + " opcode.");
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions source/Cosmos.IL2CPU/ILOpCodes/OpMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ protected override void DoInitStackAnalysis(MethodBase aMethod)
case Code.Ldftn:
StackPushTypes[0] = typeof(IntPtr);
return;
case Code.Ldvirtftn:
StackPushTypes[0] = typeof(IntPtr);
return;

default:
break;
Expand Down
4 changes: 2 additions & 2 deletions source/Cosmos.IL2CPU/ILOpCodes/OpNone.cs
Original file line number Diff line number Diff line change
Expand Up @@ -856,11 +856,11 @@ public override void DoInterpretStackTypes()
{
return;
}
if (!StackPopTypes[0].IsByRef && !StackPopTypes[0].IsPointer)
if (!StackPopTypes[0].IsByRef && !StackPopTypes[0].IsPointer && StackPopTypes[0] != typeof(IntPtr))
{
throw new Exception("Invalid ref type: " + StackPopTypes[0].FullName);
}
if (StackPopTypes[0].IsPointer)
if (StackPopTypes[0].IsPointer || StackPopTypes[0] == typeof(IntPtr))
{
StackPushTypes[0] = typeof(object);
}
Expand Down
7 changes: 6 additions & 1 deletion source/Cosmos.IL2CPU/ILScanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,12 @@ protected void ScanType(Type aType)
if (aType.IsGenericType && new string[] { "IList", "ICollection", "IEnumerable", "IReadOnlyList", "IReadOnlyCollection" }
.Any(i => aType.Name.Contains(i)))
{
Queue(aType.GenericTypeArguments[0].MakeArrayType(), aType, "CallVirt of Generic Interface for Array");
// i dont know if i should throw or skip
// if (aType.GenericTypeArguments.Length == 0) throw new Exception($@"{aType}: aType.GenericTypeArguments.Length == 0", new IndexOutOfRangeException());
if (aType.GenericTypeArguments.Length == 1)
{
Queue(aType.GenericTypeArguments[0].MakeArrayType(), aType, "CallVirt of Generic Interface for Array");
}
}

// Add immediate ancestor type
Expand Down
2 changes: 1 addition & 1 deletion source/Cosmos.IL2CPU/PlugManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void FindPlugImpls(IEnumerable<Assembly> assemblies)
{
if (!xAttrib.IsOptional)
{
throw new Exception("Error", ex);
throw new Exception($@"Error [{xAttrib.TargetName}]", ex);
}
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion source/IL2CPU.Debug.Symbols/IL2CPU.Debug.Symbols.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<PackageDescription>IL2CPU debug symbols APIs.</PackageDescription>
<IsPackable>True</IsPackable>
Expand Down
2 changes: 1 addition & 1 deletion source/IL2CPU/IL2CPU.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<OutputType>Exe</OutputType>
<PackageDescription>IL2CPU compiler.</PackageDescription>
<DevelopmentDependency>True</DevelopmentDependency>
Expand Down
2 changes: 1 addition & 1 deletion tests/IL2CPU.Compiler.Tests/IL2CPU.Compiler.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>

Expand Down