From 04cafa1326adc1f8ca4b51f26c8e64ecf7cae405 Mon Sep 17 00:00:00 2001 From: zarlo <5899@zarlo.dev> Date: Sat, 21 Oct 2023 18:14:38 +1100 Subject: [PATCH 1/7] start work o .net 8 update --- source/Cosmos.IL2CPU/Cosmos.IL2CPU.csproj | 2 +- source/IL2CPU.Debug.Symbols/IL2CPU.Debug.Symbols.csproj | 2 +- source/IL2CPU/IL2CPU.csproj | 2 +- tests/IL2CPU.Compiler.Tests/IL2CPU.Compiler.Tests.csproj | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/source/Cosmos.IL2CPU/Cosmos.IL2CPU.csproj b/source/Cosmos.IL2CPU/Cosmos.IL2CPU.csproj index de66c4cc4..b35e593c3 100644 --- a/source/Cosmos.IL2CPU/Cosmos.IL2CPU.csproj +++ b/source/Cosmos.IL2CPU/Cosmos.IL2CPU.csproj @@ -1,7 +1,7 @@  - net6.0 + net8.0 True CA1707;CA1716;$(NoWarn) diff --git a/source/IL2CPU.Debug.Symbols/IL2CPU.Debug.Symbols.csproj b/source/IL2CPU.Debug.Symbols/IL2CPU.Debug.Symbols.csproj index f7e16b6d6..2f67d9c16 100644 --- a/source/IL2CPU.Debug.Symbols/IL2CPU.Debug.Symbols.csproj +++ b/source/IL2CPU.Debug.Symbols/IL2CPU.Debug.Symbols.csproj @@ -1,7 +1,7 @@  - net6.0 + net8.0 True IL2CPU debug symbols APIs. True diff --git a/source/IL2CPU/IL2CPU.csproj b/source/IL2CPU/IL2CPU.csproj index 5c8d0bb4c..6a5577a0d 100644 --- a/source/IL2CPU/IL2CPU.csproj +++ b/source/IL2CPU/IL2CPU.csproj @@ -1,7 +1,7 @@  - net6.0 + net8.0 Exe IL2CPU compiler. True diff --git a/tests/IL2CPU.Compiler.Tests/IL2CPU.Compiler.Tests.csproj b/tests/IL2CPU.Compiler.Tests/IL2CPU.Compiler.Tests.csproj index 93b3076d4..d465e0f90 100644 --- a/tests/IL2CPU.Compiler.Tests/IL2CPU.Compiler.Tests.csproj +++ b/tests/IL2CPU.Compiler.Tests/IL2CPU.Compiler.Tests.csproj @@ -1,7 +1,7 @@  - net6.0 + net8.0 false From 7c5fc4661732bc39564f78043476b4be60344c8c Mon Sep 17 00:00:00 2001 From: zarlo <5899@zarlo.dev> Date: Mon, 23 Oct 2023 08:14:01 +1100 Subject: [PATCH 2/7] some plugs made --- source/Cosmos.IL2CPU/Cosmos.IL2CPU.csproj | 2 +- source/Cosmos.IL2CPU/PlugManager.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/source/Cosmos.IL2CPU/Cosmos.IL2CPU.csproj b/source/Cosmos.IL2CPU/Cosmos.IL2CPU.csproj index b35e593c3..3aef98837 100644 --- a/source/Cosmos.IL2CPU/Cosmos.IL2CPU.csproj +++ b/source/Cosmos.IL2CPU/Cosmos.IL2CPU.csproj @@ -18,7 +18,7 @@ - + diff --git a/source/Cosmos.IL2CPU/PlugManager.cs b/source/Cosmos.IL2CPU/PlugManager.cs index a8a20e08d..9b695a52e 100644 --- a/source/Cosmos.IL2CPU/PlugManager.cs +++ b/source/Cosmos.IL2CPU/PlugManager.cs @@ -97,7 +97,7 @@ public void FindPlugImpls(IEnumerable assemblies) { if (!xAttrib.IsOptional) { - throw new Exception("Error", ex); + throw new Exception($@"Error [{xAttrib.TargetName}]", ex); } continue; } From 1c339f2c118025b2a721d399667467bbacd917e9 Mon Sep 17 00:00:00 2001 From: zarlo Date: Tue, 23 Apr 2024 18:45:04 +1000 Subject: [PATCH 3/7] work on .net 8 update --- source/Cosmos.IL2CPU/CompilerEngine.cs | 8 ++++---- source/Cosmos.IL2CPU/Cosmos.IL2CPU.csproj | 2 +- source/Cosmos.IL2CPU/ILScanner.cs | 7 ++++++- source/IL2CPU.Debug.Symbols/IL2CPU.Debug.Symbols.csproj | 2 +- source/IL2CPU/IL2CPU.csproj | 2 +- tests/IL2CPU.Compiler.Tests/IL2CPU.Compiler.Tests.csproj | 2 +- 6 files changed, 14 insertions(+), 9 deletions(-) diff --git a/source/Cosmos.IL2CPU/CompilerEngine.cs b/source/Cosmos.IL2CPU/CompilerEngine.cs index 523584d76..0fd9d7984 100644 --- a/source/Cosmos.IL2CPU/CompilerEngine.cs +++ b/source/Cosmos.IL2CPU/CompilerEngine.cs @@ -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; @@ -67,14 +67,14 @@ 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); } } @@ -82,7 +82,7 @@ public CompilerEngine(ICompilerEngineSettings aSettings) { 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); } } diff --git a/source/Cosmos.IL2CPU/Cosmos.IL2CPU.csproj b/source/Cosmos.IL2CPU/Cosmos.IL2CPU.csproj index de66c4cc4..b35e593c3 100644 --- a/source/Cosmos.IL2CPU/Cosmos.IL2CPU.csproj +++ b/source/Cosmos.IL2CPU/Cosmos.IL2CPU.csproj @@ -1,7 +1,7 @@  - net6.0 + net8.0 True CA1707;CA1716;$(NoWarn) diff --git a/source/Cosmos.IL2CPU/ILScanner.cs b/source/Cosmos.IL2CPU/ILScanner.cs index ad9d15dc5..f4ace1bb2 100644 --- a/source/Cosmos.IL2CPU/ILScanner.cs +++ b/source/Cosmos.IL2CPU/ILScanner.cs @@ -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 diff --git a/source/IL2CPU.Debug.Symbols/IL2CPU.Debug.Symbols.csproj b/source/IL2CPU.Debug.Symbols/IL2CPU.Debug.Symbols.csproj index 72214a1f6..aef440180 100644 --- a/source/IL2CPU.Debug.Symbols/IL2CPU.Debug.Symbols.csproj +++ b/source/IL2CPU.Debug.Symbols/IL2CPU.Debug.Symbols.csproj @@ -1,12 +1,12 @@  - net6.0 True IL2CPU debug symbols APIs. True Debug;Release;TEST false + net8.0 diff --git a/source/IL2CPU/IL2CPU.csproj b/source/IL2CPU/IL2CPU.csproj index 5c8d0bb4c..6a5577a0d 100644 --- a/source/IL2CPU/IL2CPU.csproj +++ b/source/IL2CPU/IL2CPU.csproj @@ -1,7 +1,7 @@  - net6.0 + net8.0 Exe IL2CPU compiler. True diff --git a/tests/IL2CPU.Compiler.Tests/IL2CPU.Compiler.Tests.csproj b/tests/IL2CPU.Compiler.Tests/IL2CPU.Compiler.Tests.csproj index 93b3076d4..d465e0f90 100644 --- a/tests/IL2CPU.Compiler.Tests/IL2CPU.Compiler.Tests.csproj +++ b/tests/IL2CPU.Compiler.Tests/IL2CPU.Compiler.Tests.csproj @@ -1,7 +1,7 @@  - net6.0 + net8.0 false From e09fa54d177a00241694e5ccd4f33456fedc7f27 Mon Sep 17 00:00:00 2001 From: Mikhail Date: Wed, 10 Jul 2024 16:13:54 -0400 Subject: [PATCH 4/7] Allow *(object*)IntPtr, improve error handling when missing parameter in plug Allow *(object*)IntPtr, improve error handling when missing parameter in plug --- source/Cosmos.IL2CPU/AppAssembler.cs | 12 +++++++++++- source/Cosmos.IL2CPU/ILOpCodes/OpNone.cs | 4 ++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/source/Cosmos.IL2CPU/AppAssembler.cs b/source/Cosmos.IL2CPU/AppAssembler.cs index e4c69b303..fee44b0e0 100644 --- a/source/Cosmos.IL2CPU/AppAssembler.cs +++ b/source/Cosmos.IL2CPU/AppAssembler.cs @@ -1192,7 +1192,17 @@ public void ProcessField(FieldInfo aField) /// The plug 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 diff --git a/source/Cosmos.IL2CPU/ILOpCodes/OpNone.cs b/source/Cosmos.IL2CPU/ILOpCodes/OpNone.cs index f96ec8920..83db0764d 100644 --- a/source/Cosmos.IL2CPU/ILOpCodes/OpNone.cs +++ b/source/Cosmos.IL2CPU/ILOpCodes/OpNone.cs @@ -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); } From d1a57779ed1f64f2db6580779ca221e3cb4442be Mon Sep 17 00:00:00 2001 From: Mikhail Date: Sat, 17 Aug 2024 10:31:55 -0400 Subject: [PATCH 5/7] Fix Ldvirtftn --- source/Cosmos.IL2CPU/ILOpCode.cs | 10 ++++++++-- source/Cosmos.IL2CPU/ILOpCodes/OpMethod.cs | 3 +++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/source/Cosmos.IL2CPU/ILOpCode.cs b/source/Cosmos.IL2CPU/ILOpCode.cs index 5b1592bed..919d7b73a 100644 --- a/source/Cosmos.IL2CPU/ILOpCode.cs +++ b/source/Cosmos.IL2CPU/ILOpCode.cs @@ -345,8 +345,14 @@ public void DoStackAnalysis(Stack 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."); + } } } diff --git a/source/Cosmos.IL2CPU/ILOpCodes/OpMethod.cs b/source/Cosmos.IL2CPU/ILOpCodes/OpMethod.cs index 740e3546b..09f9c6513 100644 --- a/source/Cosmos.IL2CPU/ILOpCodes/OpMethod.cs +++ b/source/Cosmos.IL2CPU/ILOpCodes/OpMethod.cs @@ -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; From f206a2d9f4b2bc4e5eccfeef09c501d90067cd10 Mon Sep 17 00:00:00 2001 From: Mikhail Date: Sat, 17 Aug 2024 11:24:20 -0400 Subject: [PATCH 6/7] Try implementing Ldvirtftn --- source/Cosmos.IL2CPU/IL/Ldvirtftn.cs | 39 +++++----------------------- 1 file changed, 6 insertions(+), 33 deletions(-) diff --git a/source/Cosmos.IL2CPU/IL/Ldvirtftn.cs b/source/Cosmos.IL2CPU/IL/Ldvirtftn.cs index 0cd436de9..8b62d3faf 100644 --- a/source/Cosmos.IL2CPU/IL/Ldvirtftn.cs +++ b/source/Cosmos.IL2CPU/IL/Ldvirtftn.cs @@ -1,5 +1,7 @@ using System; - +using XSharp; +using Cosmos.IL2CPU.ILOpCodes; +using IL2CPU.API; namespace Cosmos.IL2CPU.X86.IL { @@ -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)); + } } } From cd3d10279a53d90843762ca9fc693684215ce847 Mon Sep 17 00:00:00 2001 From: Mikhail Date: Sat, 17 Aug 2024 11:36:41 -0400 Subject: [PATCH 7/7] Update AppAssembler.cs --- source/Cosmos.IL2CPU/AppAssembler.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/source/Cosmos.IL2CPU/AppAssembler.cs b/source/Cosmos.IL2CPU/AppAssembler.cs index fee44b0e0..e8e38971c 100644 --- a/source/Cosmos.IL2CPU/AppAssembler.cs +++ b/source/Cosmos.IL2CPU/AppAssembler.cs @@ -935,7 +935,15 @@ public unsafe void GenerateVMTCode(HashSet aTypesSet, HashSet 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);