From e4b2cfaca3f9d11da94cb9b4e702ce219ed085b5 Mon Sep 17 00:00:00 2001 From: mterwoord_cp <7cd3fd84a0151ea055c2f79e4d2eef9576fe9afesxUZAwxD> Date: Fri, 23 Nov 2007 16:50:43 +0000 Subject: [PATCH] prelim work on generics --- .../CustomImplementations/System/ByteImpl.cs | 9 ----- .../System/ByteImplRefs.cs | 36 ------------------- .../System/ConsoleImpl.cs | 10 ------ .../Indy.IL2CPU.IL.X86.Native.csproj | 3 -- .../System/ConsoleImplRefs.cs | 36 ------------------- .../Indy.IL2CPU.IL.X86.Win32.csproj | 1 - .../CustomImplementations/System/ArrayImpl.cs | 15 ++++++++ .../Indy.IL2CPU.IL.X86.csproj | 1 + source/Indy.IL2CPU.IL.X86/Ldc_I4.cs | 6 +++- source/Indy.IL2CPU.IL.X86/Newarr.cs | 4 ++- .../CustomImplementation/System/ObjectImpl.cs | 1 + source/Indy.IL2CPU/Engine.cs | 4 +++ 12 files changed, 29 insertions(+), 97 deletions(-) delete mode 100644 source/Indy.IL2CPU.IL.X86.Native/CustomImplementations/System/ByteImpl.cs delete mode 100644 source/Indy.IL2CPU.IL.X86.Native/CustomImplementations/System/ByteImplRefs.cs delete mode 100644 source/Indy.IL2CPU.IL.X86.Native/CustomImplementations/System/ConsoleImpl.cs delete mode 100644 source/Indy.IL2CPU.IL.X86.Win32/CustomImplementations/System/ConsoleImplRefs.cs create mode 100644 source/Indy.IL2CPU.IL.X86/CustomImplementations/System/ArrayImpl.cs diff --git a/source/Indy.IL2CPU.IL.X86.Native/CustomImplementations/System/ByteImpl.cs b/source/Indy.IL2CPU.IL.X86.Native/CustomImplementations/System/ByteImpl.cs deleted file mode 100644 index 6c56af6ad..000000000 --- a/source/Indy.IL2CPU.IL.X86.Native/CustomImplementations/System/ByteImpl.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace Indy.IL2CPU.IL.X86.Native.CustomImplementations.System { - public static class ByteImpl { - } -} diff --git a/source/Indy.IL2CPU.IL.X86.Native/CustomImplementations/System/ByteImplRefs.cs b/source/Indy.IL2CPU.IL.X86.Native/CustomImplementations/System/ByteImplRefs.cs deleted file mode 100644 index 15fc8875f..000000000 --- a/source/Indy.IL2CPU.IL.X86.Native/CustomImplementations/System/ByteImplRefs.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; -using System.Text; -using Mono.Cecil; - -namespace Indy.IL2CPU.IL.X86.Native.CustomImplementations.System { - public static class ByteImplRefs { - public static readonly AssemblyDefinition RuntimeAssemblyDef; - public static readonly MethodDefinition ToStringRef; - - static ByteImplRefs() { - RuntimeAssemblyDef = AssemblyFactory.GetAssembly(typeof(ByteImpl).Assembly.Location); - TypeDefinition xType = null; - foreach (ModuleDefinition xMod in RuntimeAssemblyDef.Modules) { - if (xMod.Types.Contains(typeof(ByteImpl).FullName)) { - xType = xMod.Types[typeof(ByteImpl).FullName]; - break; - } - } - if (xType == null) { - throw new Exception("ByteImpl type not found!"); - } - foreach (FieldInfo xField in typeof(ByteImplRefs).GetFields()) { - if (xField.Name.EndsWith("Ref")) { - MethodDefinition xTempMethod = xType.Methods.GetMethod(xField.Name.Substring(0, xField.Name.Length - "Ref".Length)).FirstOrDefault(); - if (xTempMethod == null) { - throw new Exception("Method '" + xField.Name.Substring(0, xField.Name.Length - "Ref".Length) + "' not found on RuntimeEngine!"); - } - xField.SetValue(null, xTempMethod); - } - } - } - } -} \ No newline at end of file diff --git a/source/Indy.IL2CPU.IL.X86.Native/CustomImplementations/System/ConsoleImpl.cs b/source/Indy.IL2CPU.IL.X86.Native/CustomImplementations/System/ConsoleImpl.cs deleted file mode 100644 index 3dc240ad3..000000000 --- a/source/Indy.IL2CPU.IL.X86.Native/CustomImplementations/System/ConsoleImpl.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Indy.IL2CPU.IL.X86.CustomImplementations.System; -using Indy.IL2CPU.Plugs; - -namespace Indy.IL2CPU.IL.X86.Native.CustomImplementations.System { - -} \ No newline at end of file diff --git a/source/Indy.IL2CPU.IL.X86.Native/Indy.IL2CPU.IL.X86.Native.csproj b/source/Indy.IL2CPU.IL.X86.Native/Indy.IL2CPU.IL.X86.Native.csproj index 0962da1f0..e29a9139a 100644 --- a/source/Indy.IL2CPU.IL.X86.Native/Indy.IL2CPU.IL.X86.Native.csproj +++ b/source/Indy.IL2CPU.IL.X86.Native/Indy.IL2CPU.IL.X86.Native.csproj @@ -54,13 +54,10 @@ - - - diff --git a/source/Indy.IL2CPU.IL.X86.Win32/CustomImplementations/System/ConsoleImplRefs.cs b/source/Indy.IL2CPU.IL.X86.Win32/CustomImplementations/System/ConsoleImplRefs.cs deleted file mode 100644 index 0677052e6..000000000 --- a/source/Indy.IL2CPU.IL.X86.Win32/CustomImplementations/System/ConsoleImplRefs.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System; -using System.Linq; -using System.Reflection; -using Mono.Cecil; - -namespace Indy.IL2CPU.IL.X86.Win32.CustomImplementations.System { - public static class ConsoleImplRefs { - public static readonly MethodDefinition WriteRef; - public static readonly MethodDefinition WriteLine_string_Ref; - public static readonly MethodDefinition WriteLineRef; - public static readonly AssemblyDefinition RuntimeAssemblyDef; - - static ConsoleImplRefs() { - RuntimeAssemblyDef = AssemblyFactory.GetAssembly(typeof (ConsoleImpl).Assembly.Location); - TypeDefinition xType = null; - foreach (ModuleDefinition xMod in RuntimeAssemblyDef.Modules) { - if (xMod.Types.Contains(typeof (ConsoleImpl).FullName)) { - xType = xMod.Types[typeof (ConsoleImpl).FullName]; - break; - } - } - if (xType == null) { - throw new Exception("ConsoleImpl type not found!"); - } - foreach (FieldInfo xField in typeof (ConsoleImplRefs).GetFields()) { - if (xField.Name.EndsWith("Ref")) { - MethodDefinition xTempMethod = xType.Methods.GetMethod(xField.Name.Substring(0, xField.Name.Length - "Ref".Length)).FirstOrDefault(); - if (xTempMethod == null) { - throw new Exception("Method '" + xField.Name.Substring(0, xField.Name.Length - "Ref".Length) + "' not found on RuntimeEngine!"); - } - xField.SetValue(null, xTempMethod); - } - } - } - } -} \ No newline at end of file diff --git a/source/Indy.IL2CPU.IL.X86.Win32/Indy.IL2CPU.IL.X86.Win32.csproj b/source/Indy.IL2CPU.IL.X86.Win32/Indy.IL2CPU.IL.X86.Win32.csproj index 6c9f252ad..78ddd886c 100644 --- a/source/Indy.IL2CPU.IL.X86.Win32/Indy.IL2CPU.IL.X86.Win32.csproj +++ b/source/Indy.IL2CPU.IL.X86.Win32/Indy.IL2CPU.IL.X86.Win32.csproj @@ -49,7 +49,6 @@ - diff --git a/source/Indy.IL2CPU.IL.X86/CustomImplementations/System/ArrayImpl.cs b/source/Indy.IL2CPU.IL.X86/CustomImplementations/System/ArrayImpl.cs new file mode 100644 index 000000000..6fa109c6d --- /dev/null +++ b/source/Indy.IL2CPU.IL.X86/CustomImplementations/System/ArrayImpl.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Indy.IL2CPU.Plugs; + +namespace Indy.IL2CPU.IL.X86.CustomImplementations.System { + [Plug(Target=typeof(Array))] + public class ArrayImpl { + [PlugMethod(Signature="System_Void___System_Array_Clear___System_Array__System_Int32__System_Int32___")] + public static unsafe void Clear(uint* aArray, int aIndex, int aLength) { + + } + } +} \ No newline at end of file diff --git a/source/Indy.IL2CPU.IL.X86/Indy.IL2CPU.IL.X86.csproj b/source/Indy.IL2CPU.IL.X86/Indy.IL2CPU.IL.X86.csproj index d22b1e463..1c6b0f660 100644 --- a/source/Indy.IL2CPU.IL.X86/Indy.IL2CPU.IL.X86.csproj +++ b/source/Indy.IL2CPU.IL.X86/Indy.IL2CPU.IL.X86.csproj @@ -131,6 +131,7 @@ + diff --git a/source/Indy.IL2CPU.IL.X86/Ldc_I4.cs b/source/Indy.IL2CPU.IL.X86/Ldc_I4.cs index a822b8578..6ac28710d 100644 --- a/source/Indy.IL2CPU.IL.X86/Ldc_I4.cs +++ b/source/Indy.IL2CPU.IL.X86/Ldc_I4.cs @@ -14,6 +14,7 @@ namespace Indy.IL2CPU.IL.X86 { private FieldDefinition mTokenField; private FieldDefinition mStaticField; private int mCount; + private int mElementSize; protected void SetValue(int aValue) { mValue = aValue; } @@ -55,11 +56,13 @@ namespace Indy.IL2CPU.IL.X86 { MethodReference xMethodRef = xCall.Operand as MethodReference; FieldReference xFieldRef = xStsfld.Operand as FieldReference; FieldReference xFieldContentsRef = xLdtoken.Operand as FieldReference; - if (xFieldRef != null && xMethodRef != null) { + TypeSpecification xFieldElementType = (xFieldRef != null ? xFieldRef.FieldType as TypeSpecification : null); + if (xFieldRef != null && xMethodRef != null && xFieldContentsRef != null && xFieldElementType != null) { MethodDefinition xMethodDef = Engine.GetDefinitionFromMethodReference(xMethodRef); FieldDefinition xFieldDef = Engine.GetDefinitionFromFieldReference(xFieldRef); FieldDefinition xFieldContentsDef = Engine.GetDefinitionFromFieldReference(xFieldContentsRef); if (xFieldDef.IsInitOnly && xMethodDef.ToString() == "System.Void System.Runtime.CompilerServices.RuntimeHelpers::InitializeArray(System.Array,System.RuntimeFieldHandle)") { + mElementSize = ObjectUtilities.GetObjectStorageSize(Engine.GetDefinitionFromTypeReference(xFieldElementType.ElementType)); mTokenField = xFieldContentsDef; mStaticField = xFieldDef; mOptimizedArrayFieldCode = true; @@ -97,6 +100,7 @@ namespace Indy.IL2CPU.IL.X86 { string xTheData = BitConverter.GetBytes(Engine.RegisterTypeRef(mStaticField.FieldType)).Aggregate("", (r, b) => r + b + ","); xTheData += BitConverter.GetBytes(0x80000002).Aggregate("", (r, b) => r + b + ","); xTheData += BitConverter.GetBytes(mCount).Aggregate("", (r, b) => r + b + ","); + xTheData += BitConverter.GetBytes(mElementSize).Aggregate("", (r, b) => r + b + ","); xTheData += mTokenField.InitialValue.Aggregate("", (r, b) => r + b + ","); xTheData = xTheData.TrimEnd(','); Assembler.DataMembers.Add(new DataMember(xDataMemberName, "db", xTheData)); diff --git a/source/Indy.IL2CPU.IL.X86/Newarr.cs b/source/Indy.IL2CPU.IL.X86/Newarr.cs index 4ffc2f117..2278e1a52 100644 --- a/source/Indy.IL2CPU.IL.X86/Newarr.cs +++ b/source/Indy.IL2CPU.IL.X86/Newarr.cs @@ -45,7 +45,7 @@ namespace Indy.IL2CPU.IL.X86 { Assembler.StackSizes.Push(4); Multiply(Assembler); // the total items size is now on the stack - new CPUx86.Pushd("0x" + (ObjectImpl.FieldDataOffset + 4).ToString("X")); + new CPUx86.Pushd("0x" + (ObjectImpl.FieldDataOffset + 8).ToString("X")); Assembler.StackSizes.Push(4); Add(Assembler); // the total array size is now on the stack. @@ -68,6 +68,8 @@ namespace Indy.IL2CPU.IL.X86 { new CPUx86.Move("dword", CPUx86.Registers.AtEAX, "0x" + InstanceTypeEnum.Array.ToString("X")); new CPUx86.Add(CPUx86.Registers.EAX, "4"); new CPUx86.Move("dword", CPUx86.Registers.AtEAX, CPUx86.Registers.EDI); + new CPUx86.Add(CPUx86.Registers.EAX, "4"); + new CPUx86.Move("dword", CPUx86.Registers.AtEAX, "0x" + mElementSize.ToString("X")); new CPUx86.Call(mCtorName); } } diff --git a/source/Indy.IL2CPU/CustomImplementation/System/ObjectImpl.cs b/source/Indy.IL2CPU/CustomImplementation/System/ObjectImpl.cs index 82a53d2a8..b872d614d 100644 --- a/source/Indy.IL2CPU/CustomImplementation/System/ObjectImpl.cs +++ b/source/Indy.IL2CPU/CustomImplementation/System/ObjectImpl.cs @@ -20,6 +20,7 @@ namespace Indy.IL2CPU { /// /// The first 4 bytes are the reference to the type information of the instance, the second 4 bytes /// are the value. For arrays, there are 4 following bytes containing the element count. + /// and 4 bytes containing the element size. /// /// public const int FieldDataOffset = 8; diff --git a/source/Indy.IL2CPU/Engine.cs b/source/Indy.IL2CPU/Engine.cs index f3e10d518..3c53454bf 100644 --- a/source/Indy.IL2CPU/Engine.cs +++ b/source/Indy.IL2CPU/Engine.cs @@ -406,6 +406,9 @@ namespace Indy.IL2CPU { bool xMismatch = false; for (int i = 0; i < xFoundMethod.Parameters.Count; i++) { if (xFoundMethod.Parameters[i].ParameterType.FullName != aRef.Parameters[i].ParameterType.FullName) { + if(xFoundMethod.Parameters[i].ParameterType is GenericParameter && aRef.Parameters[i].ParameterType is GenericParameter) { + continue; + } xMismatch = true; break; } @@ -618,6 +621,7 @@ namespace Indy.IL2CPU { if (xCurrentField.InitialValue.Length > 4) { xTheData = "0,0,0,0,"; xTheData += BitConverter.GetBytes(0x80000002).Aggregate("", (r, b) => r + b + ","); + xTheData += "1,0,0,0,"; } xTheData += BitConverter.GetBytes(xCurrentField.InitialValue.Length).Aggregate("", (r, b) => r + b + ","); xTheData += xCurrentField.InitialValue.Aggregate("", (r, b) => r + b + ",");