diff --git a/source/Cosmos.IL2CPU/IL/Box.cs b/source/Cosmos.IL2CPU/IL/Box.cs index 250dd854a..d21454db5 100644 --- a/source/Cosmos.IL2CPU/IL/Box.cs +++ b/source/Cosmos.IL2CPU/IL/Box.cs @@ -5,6 +5,7 @@ using CPU = Cosmos.Assembler.x86; using Cosmos.Assembler; using Cosmos.IL2CPU.Plugs.System; using XSharp.Compiler; +using static XSharp.Compiler.XSRegisters; namespace Cosmos.IL2CPU.X86.IL { @@ -24,18 +25,18 @@ namespace Cosmos.IL2CPU.X86.IL string xTypeID = GetTypeIDLabel(xType.Value); XS.Push((ObjectImpl.FieldDataOffset + xSize)); XS.Call(LabelName.Get(GCImplementationRefs.AllocNewObjectRef)); - XS.Pop(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EAX)); - XS.Set(XSRegisters.ESI, XSRegisters.EAX, sourceIsIndirect: true); - XS.Set(XSRegisters.EBX, xTypeID, sourceIsIndirect: true); - XS.Set(XSRegisters.ESI, XSRegisters.EBX, destinationIsIndirect: true); - new CPUx86.Mov { DestinationReg = CPUx86.RegistersEnum.ESI, DestinationIsIndirect = true, DestinationDisplacement = 4, SourceValue = (uint)InstanceTypeEnum.BoxedValueType, Size = 32 }; + XS.Pop(OldToNewRegister(CPUx86.RegistersEnum.EAX)); + XS.Set(ESI, EAX, sourceIsIndirect: true); + XS.Set(EBX, xTypeID, sourceIsIndirect: true); + XS.Set(ESI, EBX, destinationIsIndirect: true); + XS.Set(ESI, (uint)InstanceTypeEnum.BoxedValueType, destinationDisplacement: 4, size: RegisterSize.Int32); new Comment(Assembler, "xSize is " + xSize); for (int i = 0; i < (xSize / 4); i++) { - XS.Pop(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EDX)); + XS.Pop(OldToNewRegister(CPUx86.RegistersEnum.EDX)); new CPUx86.Mov { DestinationReg = CPUx86.RegistersEnum.ESI, DestinationIsIndirect = true, DestinationDisplacement = (ObjectImpl.FieldDataOffset + (i * 4)), SourceReg = CPUx86.RegistersEnum.EDX, Size = 32 }; } - XS.Push(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EAX)); + XS.Push(OldToNewRegister(CPUx86.RegistersEnum.EAX)); } } } diff --git a/source/Cosmos.IL2CPU/IL/Callvirt.cs b/source/Cosmos.IL2CPU/IL/Callvirt.cs index a663e5eee..4be7dc62c 100644 --- a/source/Cosmos.IL2CPU/IL/Callvirt.cs +++ b/source/Cosmos.IL2CPU/IL/Callvirt.cs @@ -10,6 +10,7 @@ using System.Reflection; using Cosmos.IL2CPU.Plugs.System; using XSharp.Compiler; +using static XSharp.Compiler.XSRegisters; using SysReflection = System.Reflection; namespace Cosmos.IL2CPU.X86.IL @@ -83,7 +84,7 @@ namespace Cosmos.IL2CPU.X86.IL { if (xExtraStackSize > 0) { - XS.Sub(XSRegisters.OldToNewRegister(CPU.RegistersEnum.ESP), (uint)xExtraStackSize); + XS.Sub(OldToNewRegister(CPU.RegistersEnum.ESP), (uint)xExtraStackSize); } XS.Call(xNormalAddress); } @@ -103,9 +104,9 @@ namespace Cosmos.IL2CPU.X86.IL } else { - XS.Set(XSRegisters.OldToNewRegister(CPU.RegistersEnum.EAX), XSRegisters.OldToNewRegister(CPU.RegistersEnum.ESP), sourceDisplacement: (int)xThisOffset); - XS.Set(XSRegisters.EAX, XSRegisters.EAX, sourceIsIndirect: true); - XS.Push(XSRegisters.EAX, isIndirect: true); + XS.Set(OldToNewRegister(CPU.RegistersEnum.EAX), OldToNewRegister(CPU.RegistersEnum.ESP), sourceDisplacement: (int)xThisOffset); + XS.Set(EAX, EAX, sourceIsIndirect: true); + XS.Push(EAX, isIndirect: true); } XS.Push(aTargetMethodUID); XS.Call(LabelName.Get(VTablesImplRefs.GetMethodAddressForTypeRef)); @@ -126,7 +127,7 @@ namespace Cosmos.IL2CPU.X86.IL // mLabelName + "_AfterAddressCheck", // true, // xEmitCleanup ); - XS.Pop(XSRegisters.OldToNewRegister(CPU.RegistersEnum.ECX)); + XS.Pop(OldToNewRegister(CPU.RegistersEnum.ECX)); XS.Label(xCurrentMethodLabel + ".AfterAddressCheck"); if (xMethodInfo.DeclaringType == typeof(object)) @@ -138,14 +139,14 @@ namespace Cosmos.IL2CPU.X86.IL * $esp + mThisOffset This */ // we need to see if $this is a boxed object, and if so, we need to box it - XS.Set(XSRegisters.OldToNewRegister(CPU.RegistersEnum.EAX), XSRegisters.OldToNewRegister(CPU.RegistersEnum.ESP), sourceDisplacement: (int)xThisOffset); + XS.Set(OldToNewRegister(CPU.RegistersEnum.EAX), OldToNewRegister(CPU.RegistersEnum.ESP), sourceDisplacement: (int)xThisOffset); - //new CPUx86.Compare { DestinationReg = CPUx86.Registers.EAX, DestinationIsIndirect = true, DestinationDisplacement = 4, SourceValue = ( ( uint )InstanceTypeEnum.BoxedValueType ), Size = 32 }; + //XS.Compare(XSRegisters.EAX, ( ( uint )InstanceTypeEnum.BoxedValueType ), destinationDisplacement: 4, size: RegisterSizes.Int32); // EAX contains the handle now, lets dereference it - XS.Set(XSRegisters.EAX, XSRegisters.EAX, sourceIsIndirect: true); + XS.Set(EAX, EAX, sourceIsIndirect: true); - new CPU.Compare { DestinationReg = CPU.RegistersEnum.EAX, DestinationIsIndirect = true, DestinationDisplacement = 4, SourceValue = (int)InstanceTypeEnum.BoxedValueType, Size = 32 }; + XS.Compare(EAX, (int)InstanceTypeEnum.BoxedValueType, destinationDisplacement: 4, size: RegisterSize.Int32); /* * On the stack now: @@ -166,8 +167,8 @@ namespace Cosmos.IL2CPU.X86.IL * EAX contains the type pointer (not the handle!!) */ - XS.Add(XSRegisters.OldToNewRegister(CPU.RegistersEnum.EAX), (uint)ObjectImpl.FieldDataOffset); - XS.Set(XSRegisters.ESP, XSRegisters.EAX, destinationDisplacement: (int)xThisOffset); + XS.Add(OldToNewRegister(CPU.RegistersEnum.EAX), (uint)ObjectImpl.FieldDataOffset); + XS.Set(ESP, EAX, destinationDisplacement: (int)xThisOffset); /* * On the stack now: * $esp Params @@ -179,9 +180,9 @@ namespace Cosmos.IL2CPU.X86.IL XS.Label(xCurrentMethodLabel + ".NotBoxedThis"); if (xExtraStackSize > 0) { - XS.Sub(XSRegisters.OldToNewRegister(CPU.RegistersEnum.ESP), xExtraStackSize); + XS.Sub(OldToNewRegister(CPU.RegistersEnum.ESP), xExtraStackSize); } - XS.Call(XSRegisters.ECX); + XS.Call(ECX); XS.Label(xCurrentMethodLabel + ".AfterNotBoxedThis"); } ILOp.EmitExceptionLogic(Assembler, aMethod, aOp, true, diff --git a/source/Cosmos.IL2CPU/IL/Initobj.cs b/source/Cosmos.IL2CPU/IL/Initobj.cs index 98043cd33..5a8848be7 100644 --- a/source/Cosmos.IL2CPU/IL/Initobj.cs +++ b/source/Cosmos.IL2CPU/IL/Initobj.cs @@ -1,5 +1,6 @@ using System; using XSharp.Compiler; +using static XSharp.Compiler.XSRegisters; using CPUx86 = Cosmos.Assembler.x86; namespace Cosmos.IL2CPU.X86.IL { @@ -19,10 +20,10 @@ namespace Cosmos.IL2CPU.X86.IL Type mType = (( Cosmos.IL2CPU.ILOpCodes.OpType )aOpCode).Value; mObjSize = SizeOfType( mType ); - XS.Pop(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EAX)); + XS.Pop(OldToNewRegister(CPUx86.RegistersEnum.EAX)); for( int i = 0; i < ( mObjSize / 4 ); i++ ) { - new CPUx86.Mov { DestinationReg = CPUx86.RegistersEnum.EAX, DestinationIsIndirect = true, DestinationDisplacement = i * 4, SourceValue = 0, Size = 32 }; + XS.Set(EAX, 0, destinationDisplacement: i * 4, size: RegisterSize.Int32); } switch( mObjSize % 4 ) { @@ -90,7 +91,7 @@ namespace Cosmos.IL2CPU.X86.IL // Assembler.Stack.Pop(); // XS.Pop(XSRegisters.EAX); // for (int i = 0; i < (mObjSize / 4); i++) { - // new CPUx86.Move { DestinationReg = CPUx86.Registers.EAX, DestinationIsIndirect = true, DestinationDisplacement = i * 4, SourceValue = 0, Size=32 }; + // XS.Mov(XSRegisters.EAX, 0, destinationDisplacement: i * 4, size: RegisterSizes.Int32); // } // switch (mObjSize % 4) { // case 1: { diff --git a/source/Cosmos.IL2CPU/IL/Newobj.cs b/source/Cosmos.IL2CPU/IL/Newobj.cs index a3510aa61..592d2c400 100644 --- a/source/Cosmos.IL2CPU/IL/Newobj.cs +++ b/source/Cosmos.IL2CPU/IL/Newobj.cs @@ -7,6 +7,7 @@ using System.Reflection; using Cosmos.IL2CPU.Plugs.System; using XSharp.Compiler; +using static XSharp.Compiler.XSRegisters; using SysReflection = System.Reflection; namespace Cosmos.IL2CPU.X86.IL @@ -86,15 +87,15 @@ namespace Cosmos.IL2CPU.X86.IL XS.Comment("Shift: " + xShift); if (xShift < 0) { - XS.Sub(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.ESP), (uint)Math.Abs(xShift)); + XS.Sub(OldToNewRegister(CPUx86.RegistersEnum.ESP), (uint)Math.Abs(xShift)); } else if (xShift > 0) { - XS.Add(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.ESP), (uint)xShift); + XS.Add(OldToNewRegister(CPUx86.RegistersEnum.ESP), (uint)xShift); } // push struct ptr - XS.Push(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.ESP)); + XS.Push(OldToNewRegister(CPUx86.RegistersEnum.ESP)); // Shift args foreach (var xParam in xParameterList) @@ -131,14 +132,14 @@ namespace Cosmos.IL2CPU.X86.IL && xParams[0].ParameterType == typeof(char[])) { xHasCalcSize = true; - XS.Set(XSRegisters.EAX, XSRegisters.ESP, sourceIsIndirect: true); + XS.Set(EAX, ESP, sourceIsIndirect: true); // EAX contains a memory handle now, lets dereference it to a pointer - XS.Set(XSRegisters.EAX, XSRegisters.EAX, sourceIsIndirect: true); - XS.Set(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EAX), XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EAX), sourceDisplacement: 8); - XS.Set(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EDX), 2); - XS.Multiply(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EDX)); - XS.Push(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EAX)); + XS.Set(EAX, EAX, sourceIsIndirect: true); + XS.Set(OldToNewRegister(CPUx86.RegistersEnum.EAX), OldToNewRegister(CPUx86.RegistersEnum.EAX), sourceDisplacement: 8); + XS.Set(OldToNewRegister(CPUx86.RegistersEnum.EDX), 2); + XS.Multiply(OldToNewRegister(CPUx86.RegistersEnum.EDX)); + XS.Push(OldToNewRegister(CPUx86.RegistersEnum.EAX)); } else if (xParams.Length == 3 && (xParams[0].ParameterType == typeof(char[]) || xParams[0].ParameterType == typeof(char*)) @@ -146,18 +147,18 @@ namespace Cosmos.IL2CPU.X86.IL && xParams[2].ParameterType == typeof(int)) { xHasCalcSize = true; - XS.Set(XSRegisters.EAX, XSRegisters.ESP, sourceIsIndirect: true); - XS.ShiftLeft(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EAX), 1); - XS.Push(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EAX)); + XS.Set(EAX, ESP, sourceIsIndirect: true); + XS.ShiftLeft(OldToNewRegister(CPUx86.RegistersEnum.EAX), 1); + XS.Push(OldToNewRegister(CPUx86.RegistersEnum.EAX)); } else if (xParams.Length == 2 && xParams[0].ParameterType == typeof(char) && xParams[1].ParameterType == typeof(int)) { xHasCalcSize = true; - XS.Set(XSRegisters.EAX, XSRegisters.ESP, sourceIsIndirect: true); - XS.ShiftLeft(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EAX), 1); - XS.Push(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EAX)); + XS.Set(EAX, ESP, sourceIsIndirect: true); + XS.ShiftLeft(OldToNewRegister(CPUx86.RegistersEnum.EAX), 1); + XS.Push(OldToNewRegister(CPUx86.RegistersEnum.EAX)); } else { @@ -171,15 +172,15 @@ namespace Cosmos.IL2CPU.X86.IL XS.Push((uint)(xMemSize + xExtraSize)); if (xHasCalcSize) { - XS.Pop(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EAX)); - XS.Add(XSRegisters.ESP, XSRegisters.EAX, destinationIsIndirect: true); + XS.Pop(OldToNewRegister(CPUx86.RegistersEnum.EAX)); + XS.Add(ESP, EAX, destinationIsIndirect: true); } // todo: probably we want to check for exceptions after calling Alloc XS.Call(LabelName.Get(GCImplementationRefs.AllocNewObjectRef)); XS.Label(".AfterAlloc"); - XS.Push(XSRegisters.ESP, isIndirect: true); - XS.Push(XSRegisters.ESP, isIndirect: true); + XS.Push(ESP, isIndirect: true); + XS.Push(ESP, isIndirect: true); // it's on the stack now 3 times. Once from the Alloc return value, twice from the pushes @@ -196,12 +197,12 @@ namespace Cosmos.IL2CPU.X86.IL // todo: use a cleaner approach here. this class shouldnt assemble the string string strTypeId = GetTypeIDLabel(constructor.DeclaringType); - XS.Pop(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EAX)); - XS.Set(XSRegisters.EAX, XSRegisters.EAX, sourceIsIndirect: true); - XS.Set(XSRegisters.EBX, strTypeId, sourceIsIndirect: true); - XS.Set(XSRegisters.EAX, XSRegisters.EBX, destinationIsIndirect: true); - new CPUx86.Mov { DestinationReg = CPUx86.RegistersEnum.EAX, DestinationIsIndirect = true, DestinationDisplacement = 4, SourceValue = (uint)InstanceTypeEnum.NormalObject, Size = 32 }; - new CPUx86.Mov { DestinationReg = CPUx86.RegistersEnum.EAX, DestinationIsIndirect = true, DestinationDisplacement = 8, SourceValue = (uint)xGCFieldCount, Size = 32 }; + XS.Pop(OldToNewRegister(CPUx86.RegistersEnum.EAX)); + XS.Set(EAX, EAX, sourceIsIndirect: true); + XS.Set(EBX, strTypeId, sourceIsIndirect: true); + XS.Set(EAX, EBX, destinationIsIndirect: true); + XS.Set(EAX, (uint)InstanceTypeEnum.NormalObject, destinationDisplacement: 4, size: RegisterSize.Int32); + XS.Set(EAX, (uint)xGCFieldCount, destinationDisplacement: 8, size: RegisterSize.Int32); uint xSize = (uint)(from item in xParams let xQSize = Align(SizeOfType(item.ParameterType), 4) select (int)xQSize).Take(xParams.Length).Sum(); @@ -221,7 +222,7 @@ namespace Cosmos.IL2CPU.X86.IL if (aMethod != null) { // todo: only happening for real methods now, not for ctor's ? - XS.Test(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.ECX), 2); + XS.Test(OldToNewRegister(CPUx86.RegistersEnum.ECX), 2); string xNoErrorLabel = currentLabel + ".NoError" + LabelName.LabelCount.ToString(); XS.Jump(CPUx86.ConditionalTestEnum.Equal, xNoErrorLabel); @@ -238,7 +239,7 @@ namespace Cosmos.IL2CPU.X86.IL PushAlignedParameterSize(constructor); // an exception occurred, we need to cleanup the stack, and jump to the exit - XS.Add(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.ESP), 4); + XS.Add(OldToNewRegister(CPUx86.RegistersEnum.ESP), 4); //new Comment(aAssembler, "[ Newobj.Execute cleanup start count = " + aAssembler.Stack.Count.ToString() + " ]"); //foreach( var xStackInt in Assembler.Stack ) @@ -250,7 +251,7 @@ namespace Cosmos.IL2CPU.X86.IL Jump_Exception(aMethod); XS.Label(xNoErrorLabel); } - XS.Pop(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EAX)); + XS.Pop(OldToNewRegister(CPUx86.RegistersEnum.EAX)); //for( int i = 1; i < aCtorMethodInfo.Arguments.Length; i++ ) //{ @@ -264,7 +265,7 @@ namespace Cosmos.IL2CPU.X86.IL //} PushAlignedParameterSize(constructor); - XS.Push(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EAX)); + XS.Push(OldToNewRegister(CPUx86.RegistersEnum.EAX)); } } @@ -277,7 +278,7 @@ namespace Cosmos.IL2CPU.X86.IL for (int i = 0; i < xParams.Length; i++) { xSize = SizeOfType(xParams[i].ParameterType); - XS.Add(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.ESP), Align(xSize, 4)); + XS.Add(OldToNewRegister(CPUx86.RegistersEnum.ESP), Align(xSize, 4)); } XS.Comment("[ Newobj.PushAlignedParameterSize end ]"); }