Some more fixes to several stuff

This commit is contained in:
mterwoord_cp 2007-11-24 15:19:05 +00:00
parent 815426c76c
commit d7f1db40dc
12 changed files with 60 additions and 59 deletions

View file

@ -7,13 +7,14 @@ using Mono.Cecil;
namespace Indy.IL2CPU.Assembler { namespace Indy.IL2CPU.Assembler {
public class DataMember { public class DataMember {
public const string IllegalIdentifierChars = "&.,+$<>{}-`\'/\\ ()[]*!";
public static string GetStaticFieldName(FieldDefinition aField) { public static string GetStaticFieldName(FieldDefinition aField) {
return FilterStringForIncorrectChars("static_field__" + aField.DeclaringType.FullName + "_" + aField.Name); return FilterStringForIncorrectChars("static_field__" + aField.DeclaringType.FullName + "_" + aField.Name);
} }
public static string FilterStringForIncorrectChars(string aName) { public static string FilterStringForIncorrectChars(string aName) {
string xTempResult = aName; string xTempResult = aName;
foreach (char c in new char[] { '&', '.', ',', '+', '$', '<', '>', '{', '}', '-', '`', '\'', '/', '\\', ' ', '(', ')', '[', ']', '*' }) { foreach (char c in IllegalIdentifierChars) {
xTempResult = xTempResult.Replace(c, '_'); xTempResult = xTempResult.Replace(c, '_');
} }
return xTempResult; return xTempResult;

View file

@ -62,12 +62,7 @@ namespace Indy.IL2CPU.Assembler {
xSB.Append("_"); xSB.Append("_");
} }
xSB.Append("__"); xSB.Append("__");
string xResult = xSB.ToString().Replace('.', '_').Replace('+', '_').Replace('*', '_').Replace('[', '_').Replace(']', '_').Replace('&', '_'); string xResult = DataMember.FilterStringForIncorrectChars(xSB.ToString());
if (xResult.StartsWith(".")) {
xResult = "." + DataMember.FilterStringForIncorrectChars(xResult.Substring(1));
} else {
xResult = DataMember.FilterStringForIncorrectChars(xResult);
}
if (xResult.Length > 245) { if (xResult.Length > 245) {
xResult = mHash.ComputeHash(Encoding.Default.GetBytes(xResult)).Aggregate("_", (r, x) => r + x.ToString("X2")); xResult = mHash.ComputeHash(Encoding.Default.GetBytes(xResult)).Aggregate("_", (r, x) => r + x.ToString("X2"));
} }

View file

@ -19,7 +19,9 @@ namespace Indy.IL2CPU.IL.X86 {
string BaseLabel = CurInstructionLabel + "__"; string BaseLabel = CurInstructionLabel + "__";
string LabelTrue = BaseLabel + "True"; string LabelTrue = BaseLabel + "True";
string LabelFalse = BaseLabel + "False"; string LabelFalse = BaseLabel + "False";
new CPUx86.Pop(CPUx86.Registers.ECX);
new CPUx86.Pop(CPUx86.Registers.EAX); new CPUx86.Pop(CPUx86.Registers.EAX);
new CPUx86.Pushd(CPUx86.Registers.ECX);
new CPUx86.Compare(CPUx86.Registers.EAX, CPUx86.Registers.AtESP); new CPUx86.Compare(CPUx86.Registers.EAX, CPUx86.Registers.AtESP);
new CPUx86.JumpIfLess(LabelTrue); new CPUx86.JumpIfLess(LabelTrue);
new CPUx86.JumpAlways(LabelFalse); new CPUx86.JumpAlways(LabelFalse);

View file

@ -22,10 +22,14 @@ namespace Indy.IL2CPU.IL.X86 {
if (xMethod == null) { if (xMethod == null) {
throw new Exception("Unable to determine Method!"); throw new Exception("Unable to determine Method!");
} }
if(xMethod.ToString() == "!0 System.Collections.Generic.List`1<System.Int32>::get_Item(System.Int32)") {
System.Diagnostics.Debugger.Break();
}
MethodDefinition xMethodDef = Engine.GetDefinitionFromMethodReference(xMethod); MethodDefinition xMethodDef = Engine.GetDefinitionFromMethodReference(xMethod);
mMethodDescription = CPU.Label.GenerateLabelName(xMethodDef); mMethodDescription = CPU.Label.GenerateLabelName(xMethodDef);
if (xMethodDef.IsStatic || !xMethodDef.IsVirtual) { if (xMethodDef.IsStatic || !xMethodDef.IsVirtual) {
mNormalAddress = CPU.Label.GenerateLabelName(xMethod); Engine.QueueMethod(xMethodDef);
mNormalAddress = CPU.Label.GenerateLabelName(xMethodDef);
mHasReturn = !xMethod.ReturnType.ReturnType.FullName.StartsWith("System.Void"); mHasReturn = !xMethod.ReturnType.ReturnType.FullName.StartsWith("System.Void");
return; return;
} }

View file

@ -8,7 +8,9 @@ namespace Indy.IL2CPU.IL.X86 {
[OpCode(Code.Ldfld)] [OpCode(Code.Ldfld)]
public class Ldfld: Op { public class Ldfld: Op {
private readonly TypeInformation.Field mField; private readonly TypeInformation.Field mField;
public Ldfld(TypeInformation.Field aField):base(null, null) { private readonly TypeInformation mType;
public Ldfld(TypeInformation.Field aField)
: base(null, null) {
mField = aField; mField = aField;
} }
public Ldfld(Mono.Cecil.Cil.Instruction aInstruction, MethodInformation aMethodInfo) public Ldfld(Mono.Cecil.Cil.Instruction aInstruction, MethodInformation aMethodInfo)
@ -23,12 +25,12 @@ namespace Indy.IL2CPU.IL.X86 {
xField = Engine.GetDefinitionFromFieldReference(xFieldRef); xField = Engine.GetDefinitionFromFieldReference(xFieldRef);
} }
string xFieldId = xField.ToString(); string xFieldId = xField.ToString();
int xStorageSize; mType = Engine.GetTypeInfo(Engine.GetDefinitionFromTypeReference(xField.DeclaringType));
mField = Engine.GetTypeFieldInfo(Engine.GetDefinitionFromTypeReference(xField.DeclaringType), out xStorageSize)[xFieldId]; mField = mType.Fields[xFieldId];
} }
public override void DoAssemble() { public override void DoAssemble() {
Ldfld(Assembler, mField); Ldfld(Assembler, mType, mField);
} }
} }
} }

View file

@ -7,7 +7,9 @@ using CPUx86 = Indy.IL2CPU.Assembler.X86;
namespace Indy.IL2CPU.IL.X86 { namespace Indy.IL2CPU.IL.X86 {
[OpCode(Code.Ldflda)] [OpCode(Code.Ldflda)]
public class Ldflda: Op { public class Ldflda: Op {
private readonly string mRelativeAddress; private TypeInformation mType;
private TypeInformation.Field mField;
public Ldflda(Mono.Cecil.Cil.Instruction aInstruction, MethodInformation aMethodInfo) public Ldflda(Mono.Cecil.Cil.Instruction aInstruction, MethodInformation aMethodInfo)
: base(aInstruction, aMethodInfo) { : base(aInstruction, aMethodInfo) {
FieldDefinition xField = aInstruction.Operand as FieldDefinition; FieldDefinition xField = aInstruction.Operand as FieldDefinition;
@ -20,21 +22,13 @@ namespace Indy.IL2CPU.IL.X86 {
xField = Engine.GetDefinitionFromFieldReference(xFieldRef); xField = Engine.GetDefinitionFromFieldReference(xFieldRef);
} }
string xFieldId = xField.ToString(); string xFieldId = xField.ToString();
TypeInformation.Field xTheField;
int xStorageSize; int xStorageSize;
xTheField = Engine.GetTypeFieldInfo(Engine.GetDefinitionFromTypeReference(xField.DeclaringType), out xStorageSize)[xFieldId]; mType = Engine.GetTypeInfo(Engine.GetDefinitionFromTypeReference(xField.DeclaringType));
mRelativeAddress = xTheField.RelativeAddress; mField = mType.Fields[xFieldId];
}
public Ldflda(string aRelativeAddress):base(null, null) {
mRelativeAddress = aRelativeAddress;
} }
public override void DoAssemble() { public override void DoAssemble() {
new CPUx86.Pop(CPUx86.Registers.EAX); Ldflda(Assembler, mType, mField);
new CPUx86.Add(CPUx86.Registers.EAX, mRelativeAddress.Trim().Substring(1));
new CPUx86.Pushd(CPUx86.Registers.EAX);
Assembler.StackSizes.Push(4);
} }
} }
} }

View file

@ -28,9 +28,9 @@ namespace Indy.IL2CPU.IL.X86 {
} }
} }
public static void Ldflda(Assembler.Assembler aAssembler, TypeInformation.Field aField) { public static void Ldflda(Assembler.Assembler aAssembler, TypeInformation aType, TypeInformation.Field aField) {
int aExtraOffset = 0; int aExtraOffset = 0;
if (aField.NeedsGC && !aAssembler.InMetalMode) { if (aType.NeedsGC && !aAssembler.InMetalMode) {
aExtraOffset = 12; aExtraOffset = 12;
} }
new Popd(CPUx86.Registers.EAX); new Popd(CPUx86.Registers.EAX);
@ -47,14 +47,14 @@ namespace Indy.IL2CPU.IL.X86 {
new Pushd("eax"); new Pushd("eax");
} }
public static void Ldfld(Assembler.Assembler aAssembler, TypeInformation.Field aField) { public static void Ldfld(Assembler.Assembler aAssembler, TypeInformation aType, TypeInformation.Field aField) {
Ldfld(aAssembler, aField, true); Ldfld(aAssembler, aType, aField, true);
} }
public static void Ldfld(Assembler.Assembler aAssembler, TypeInformation.Field aField, bool aAddGCCode) { public static void Ldfld(Assembler.Assembler aAssembler, TypeInformation aType, TypeInformation.Field aField, bool aAddGCCode) {
aAssembler.StackSizes.Pop(); aAssembler.StackSizes.Pop();
int aExtraOffset = 0; int aExtraOffset = 0;
if (aField.NeedsGC && !aAssembler.InMetalMode) { if (aType.NeedsGC && !aAssembler.InMetalMode) {
aExtraOffset = 12; aExtraOffset = 12;
} }
new CPUx86.Pop("ecx"); new CPUx86.Pop("ecx");
@ -112,17 +112,17 @@ namespace Indy.IL2CPU.IL.X86 {
aAssembler.StackSizes.Push(aField.Size); aAssembler.StackSizes.Push(aField.Size);
} }
public static void Stfld(Assembler.Assembler aAssembler, TypeInformation.Field aField) { public static void Stfld(Assembler.Assembler aAssembler, TypeInformation aType, TypeInformation.Field aField) {
aAssembler.StackSizes.Pop(); aAssembler.StackSizes.Pop();
int xRoundedSize = aField.Size; int xRoundedSize = aField.Size;
if (xRoundedSize % 4 != 0) { if (xRoundedSize % 4 != 0) {
xRoundedSize += 4 - (xRoundedSize % 4); xRoundedSize += 4 - (xRoundedSize % 4);
} }
int aExtraOffset = 0; int aExtraOffset = 0;
if (aField.NeedsGC && !aAssembler.InMetalMode) { if (aType.NeedsGC && !aAssembler.InMetalMode) {
aExtraOffset = 12; aExtraOffset = 12;
new CPUx86.Pushd("[esp + 4]"); new CPUx86.Pushd("[esp + 4]");
Ldfld(aAssembler, aField, false); Ldfld(aAssembler, aType, aField, false);
Engine.QueueMethod(GCImplementationRefs.DecRefCountRef); Engine.QueueMethod(GCImplementationRefs.DecRefCountRef);
new CPUx86.Call(Label.GenerateLabelName(GCImplementationRefs.DecRefCountRef)); new CPUx86.Call(Label.GenerateLabelName(GCImplementationRefs.DecRefCountRef));
} }

View file

@ -10,6 +10,7 @@ namespace Indy.IL2CPU.IL.X86 {
[OpCode(Code.Stfld)] [OpCode(Code.Stfld)]
public class Stfld: Op { public class Stfld: Op {
private readonly TypeInformation.Field mField; private readonly TypeInformation.Field mField;
private readonly TypeInformation mType;
public Stfld(Instruction aInstruction, MethodInformation aMethodInfo) public Stfld(Instruction aInstruction, MethodInformation aMethodInfo)
: base(aInstruction, aMethodInfo) { : base(aInstruction, aMethodInfo) {
if (aInstruction == null) { if (aInstruction == null) {
@ -28,16 +29,12 @@ namespace Indy.IL2CPU.IL.X86 {
xField = Engine.GetDefinitionFromFieldReference(xFieldRef); xField = Engine.GetDefinitionFromFieldReference(xFieldRef);
} }
string xFieldId = xField.ToString(); string xFieldId = xField.ToString();
int xStorageSize; mType = Engine.GetTypeInfo(Engine.GetDefinitionFromTypeReference(xField.DeclaringType));
SortedList<String, TypeInformation.Field> xFieldInfo = Engine.GetTypeFieldInfo(Engine.GetDefinitionFromTypeReference(xField.DeclaringType), out xStorageSize); mField = mType.Fields[xFieldId];
if (!xFieldInfo.ContainsKey(xFieldId)) {
throw new Exception("Field not found!");
}
mField = xFieldInfo[xFieldId];
} }
public override void DoAssemble() { public override void DoAssemble() {
Stfld(Assembler, mField); Stfld(Assembler, mType, mField);
} }
} }
} }

View file

@ -16,8 +16,8 @@ namespace Indy.IL2CPU.IL.X86 {
Op.Ldarg(Assembler, MethodInfo.Arguments[aIndex]); Op.Ldarg(Assembler, MethodInfo.Arguments[aIndex]);
} }
protected override void Ldflda(TypeInformation.Field aField) { protected override void Ldflda(TypeInformation aType, TypeInformation.Field aField) {
Op.Ldflda(Assembler, aField); Op.Ldflda(Assembler, aType, aField);
} }
protected override void CallProxiedMethod() { protected override void CallProxiedMethod() {

View file

@ -16,7 +16,7 @@ namespace Indy.IL2CPU.IL {
public MethodDefinition ProxiedMethod; public MethodDefinition ProxiedMethod;
protected abstract void Ldarg(int aIndex); protected abstract void Ldarg(int aIndex);
protected abstract void Ldflda(TypeInformation.Field aField); protected abstract void Ldflda(TypeInformation aType, TypeInformation.Field aField);
protected abstract void CallProxiedMethod(); protected abstract void CallProxiedMethod();
protected abstract void Ldloc(int index); protected abstract void Ldloc(int index);
@ -37,7 +37,7 @@ namespace Indy.IL2CPU.IL {
} }
if (xFieldName != null) { if (xFieldName != null) {
Ldarg(0); Ldarg(0);
Ldflda(MethodInfo.TypeInfo.Fields[xFieldName]); Ldflda(MethodInfo.TypeInfo, MethodInfo.TypeInfo.Fields[xFieldName]);
} else { } else {
Ldarg(curIndex++); Ldarg(curIndex++);
} }

View file

@ -36,10 +36,12 @@ namespace Indy.IL2CPU.IL {
public readonly SortedList<string, Field> Fields; public readonly SortedList<string, Field> Fields;
public readonly int StorageSize; public readonly int StorageSize;
public readonly TypeDefinition TypeDef; public readonly TypeDefinition TypeDef;
public TypeInformation(int aStorageSize, SortedList<string, Field> aFields, TypeDefinition aTypeDef) { public readonly bool NeedsGC;
public TypeInformation(int aStorageSize, SortedList<string, Field> aFields, TypeDefinition aTypeDef, bool aNeedsGC) {
Fields = aFields; Fields = aFields;
StorageSize = aStorageSize; StorageSize = aStorageSize;
TypeDef = aTypeDef; TypeDef = aTypeDef;
NeedsGC = aNeedsGC;
} }
} }
} }

View file

@ -398,8 +398,10 @@ namespace Indy.IL2CPU {
continue; continue;
} }
if (xFoundMethod.ReturnType.ReturnType.FullName != aRef.ReturnType.ReturnType.FullName) { if (xFoundMethod.ReturnType.ReturnType.FullName != aRef.ReturnType.ReturnType.FullName) {
if (!(xFoundMethod.ReturnType.ReturnType is GenericParameter && aRef.ReturnType.ReturnType is GenericParameter)) {
continue; continue;
} }
}
if (xFoundMethod.Parameters.Count != aRef.Parameters.Count) { if (xFoundMethod.Parameters.Count != aRef.Parameters.Count) {
continue; continue;
} }
@ -681,18 +683,10 @@ namespace Indy.IL2CPU {
continue; continue;
} }
string xMethodName = Label.GenerateLabelName(xCurrentMethod); string xMethodName = Label.GenerateLabelName(xCurrentMethod);
foreach (CustomAttribute xAttrib in xCurrentMethod.CustomAttributes) {
if (xAttrib.Constructor.DeclaringType.FullName == typeof(MethodAliasAttribute).FullName) {
//xMethodName = (string)xAttrib.Fields["Name"];
break;
}
}
TypeInformation xTypeInfo = null; TypeInformation xTypeInfo = null;
{ {
if (!xCurrentMethod.IsStatic) { if (!xCurrentMethod.IsStatic) {
int xObjectStorageSize; xTypeInfo = GetTypeInfo(Engine.GetDefinitionFromTypeReference(xCurrentMethod.DeclaringType));
SortedList<string, TypeInformation.Field> xTypeFields = GetTypeFieldInfo(xCurrentMethod, out xObjectStorageSize);
xTypeInfo = new TypeInformation(xObjectStorageSize, xTypeFields, GetDefinitionFromTypeReference(xCurrentMethod.DeclaringType));
} }
} }
MethodInformation xMethodInfo = GetMethodInfo(xCurrentMethod, xCurrentMethod, xMethodName, xTypeInfo); MethodInformation xMethodInfo = GetMethodInfo(xCurrentMethod, xCurrentMethod, xMethodName, xTypeInfo);
@ -796,6 +790,14 @@ namespace Indy.IL2CPU {
} }
} }
public static TypeInformation GetTypeInfo(TypeDefinition aType) {
TypeInformation xTypeInfo;
int xObjectStorageSize;
SortedList<string, TypeInformation.Field> xTypeFields = GetTypeFieldInfo(aType, out xObjectStorageSize);
xTypeInfo = new TypeInformation(xObjectStorageSize, xTypeFields, aType, !aType.IsValueType);
return xTypeInfo;
}
public static MethodInformation GetMethodInfo(MethodDefinition aCurrentMethodForArguments, MethodDefinition aCurrentMethodForLocals, string aMethodName, TypeInformation aTypeInfo) { public static MethodInformation GetMethodInfo(MethodDefinition aCurrentMethodForArguments, MethodDefinition aCurrentMethodForLocals, string aMethodName, TypeInformation aTypeInfo) {
MethodInformation xMethodInfo; MethodInformation xMethodInfo;
{ {
@ -874,7 +876,6 @@ namespace Indy.IL2CPU {
private static void GetTypeFieldInfoImpl(SortedList<string, TypeInformation.Field> aTypeFields, TypeDefinition aType, ref int aObjectStorageSize, bool aGCObjects) { private static void GetTypeFieldInfoImpl(SortedList<string, TypeInformation.Field> aTypeFields, TypeDefinition aType, ref int aObjectStorageSize, bool aGCObjects) {
TypeDefinition xActualType = aType; TypeDefinition xActualType = aType;
aObjectStorageSize = 0;
do { do {
foreach (FieldDefinition xField in aType.Fields) { foreach (FieldDefinition xField in aType.Fields) {
if (xField.IsStatic) { if (xField.IsStatic) {
@ -883,6 +884,9 @@ namespace Indy.IL2CPU {
if (xField.HasConstant) { if (xField.HasConstant) {
Console.WriteLine("Field is constant: " + xField.GetFullName()); Console.WriteLine("Field is constant: " + xField.GetFullName());
} }
if (xField.DeclaringType.FullName.StartsWith("System.Collections.Generic") && aGCObjects) {
//System.Diagnostics.Debugger.Break();
}
if (xField.FieldType.IsValueType && aGCObjects) { if (xField.FieldType.IsValueType && aGCObjects) {
continue; continue;
} }