prelim work on generics

This commit is contained in:
mterwoord_cp 2007-11-23 16:50:43 +00:00
parent a244066330
commit e4b2cfaca3
12 changed files with 29 additions and 97 deletions

View file

@ -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 {
}
}

View file

@ -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);
}
}
}
}
}

View file

@ -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 {
}

View file

@ -54,13 +54,10 @@
<ItemGroup>
<Compile Include="Attributes\InterruptServiceRoutineAttribute.cs" />
<Compile Include="Call.cs" />
<Compile Include="CustomImplementations\System\ByteImplRefs.cs" />
<Compile Include="CustomImplementations\System\Diagnostics\DebugImplRefs.cs" />
<Compile Include="CustomImplementations\System\Diagnostics\DebuggerImpl.cs" />
<Compile Include="CustomImplementations\System\Diagnostics\DebuggerImplRefs.cs" />
<Compile Include="CustomImplementations\System\ConsoleImpl.cs" />
<Compile Include="CustomImplementations\System\Diagnostics\DebugImpl.cs" />
<Compile Include="CustomImplementations\System\ByteImpl.cs" />
<Compile Include="NativeCustomMethodImplementationOp.cs" />
<Compile Include="NativeMainEntryMethodOp.cs" />
<Compile Include="NativeOpCodeMap.cs" />

View file

@ -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);
}
}
}
}
}

View file

@ -49,7 +49,6 @@
</ItemGroup>
<ItemGroup>
<Compile Include="CustomImplementations\System\ConsoleImpl.cs" />
<Compile Include="CustomImplementations\System\ConsoleImplRefs.cs" />
<Compile Include="CustomImplementations\System\EnvironmentImpl.cs" />
<Compile Include="PInvokes.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />

View file

@ -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) {
}
}
}

View file

@ -131,6 +131,7 @@
<Compile Include="Conv_U8.cs" />
<Compile Include="Cpblk.cs" />
<Compile Include="Cpobj.cs" />
<Compile Include="CustomImplementations\System\ArrayImpl.cs" />
<Compile Include="CustomImplementations\System\DelegateImpl.cs" />
<Compile Include="CustomImplementations\System\MulticastDelegateImpl.cs" />
<Compile Include="CustomImplementations\System\MulticastDelegateImplRefs.cs" />

View file

@ -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));

View file

@ -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);
}
}

View file

@ -20,6 +20,7 @@ namespace Indy.IL2CPU {
/// <para>
/// The first 4 bytes are the reference to the type information of the instance, the second 4 bytes
/// are the <see cref="InstanceTypeEnum"/> value. For arrays, there are 4 following bytes containing the element count.
/// and 4 bytes containing the element size.
/// </para>
/// </summary>
public const int FieldDataOffset = 8;

View file

@ -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 + ",");