diff --git a/source2/IL2CPU/Cosmos.IL2CPU.Plugs/PlugAttribute.cs b/source2/IL2CPU/Cosmos.IL2CPU.Plugs/PlugAttribute.cs index 6989d1b54..ffb5bb2cc 100644 --- a/source2/IL2CPU/Cosmos.IL2CPU.Plugs/PlugAttribute.cs +++ b/source2/IL2CPU/Cosmos.IL2CPU.Plugs/PlugAttribute.cs @@ -3,11 +3,25 @@ namespace Cosmos.IL2CPU.Plugs { [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)] - public sealed class PlugAttribute : Attribute { + public sealed class PlugAttribute : Attribute + { public Type Target; public bool Inheritable = false; public string TargetName; public bool IsMonoOnly = false; public bool IsMicrosoftdotNETOnly = false; + public FrameworkVersion TargetFramework = FrameworkVersion.v4_0; + } + + [Flags] + public enum FrameworkVersion + { + v1_0, + v1_1, + v2_0, + v3_0, + v3_5, + v3_5_Sp1, + v4_0 } } \ No newline at end of file diff --git a/source2/IL2CPU/Cosmos.IL2CPU.X86/IL/Conv_I1.cs b/source2/IL2CPU/Cosmos.IL2CPU.X86/IL/Conv_I1.cs index 02281b38f..50d0ce974 100644 --- a/source2/IL2CPU/Cosmos.IL2CPU.X86/IL/Conv_I1.cs +++ b/source2/IL2CPU/Cosmos.IL2CPU.X86/IL/Conv_I1.cs @@ -3,46 +3,59 @@ using CPUx86 = Cosmos.Compiler.Assembler.X86; namespace Cosmos.IL2CPU.X86.IL { - /// - /// Convert top Stack element to sbyte and extends it to Int32. - /// - [Cosmos.IL2CPU.OpCode( ILOpCode.Code.Conv_I1 )] + /// + /// Convert top Stack element to sbyte and extends it to Int32. + /// + [Cosmos.IL2CPU.OpCode(ILOpCode.Code.Conv_I1)] public class Conv_I1 : ILOp { - public Conv_I1( Cosmos.Compiler.Assembler.Assembler aAsmblr ) - : base( aAsmblr ) + public Conv_I1(Cosmos.Compiler.Assembler.Assembler aAsmblr) + : base(aAsmblr) { } - public override void Execute( MethodInfo aMethod, ILOpCode aOpCode ) + public override void Execute(MethodInfo aMethod, ILOpCode aOpCode) { - var xSource = Assembler.Stack.Pop(); + var xSource = Assembler.Stack.Pop(); if (xSource.IsFloat) { - new CPUx86.SSE.MoveSS { SourceReg = CPUx86.Registers.ESP, DestinationReg = CPUx86.Registers.XMM0, SourceIsIndirect = true }; - new CPUx86.SSE.ConvertSS2SI { SourceReg = CPUx86.Registers.XMM0, DestinationReg = CPUx86.Registers.EAX }; - new CPUx86.Move { DestinationReg = CPUx86.Registers.ESP, SourceReg = CPUx86.Registers.EAX, DestinationIsIndirect = true }; + if (xSource.Size == 4) + { + new CPUx86.SSE.MoveSS { SourceReg = CPUx86.Registers.ESP, DestinationReg = CPUx86.Registers.XMM0, SourceIsIndirect = true }; + new CPUx86.SSE.ConvertSS2SIAndTruncate { SourceReg = CPUx86.Registers.XMM0, DestinationReg = CPUx86.Registers.EAX }; + new CPUx86.Move { DestinationReg = CPUx86.Registers.ESP, SourceReg = CPUx86.Registers.EAX, DestinationIsIndirect = true }; + } + else if (xSource.Size == 8) + { + new CPUx86.SSE.MoveDoubleAndDupplicate { DestinationReg = CPUx86.Registers.XMM0, SourceReg = CPUx86.Registers.ESP, SourceIsIndirect = true }; + new CPUx86.SSE.ConvertSD2SIAndTruncate { DestinationReg = CPUx86.Registers.EAX, SourceReg = CPUx86.Registers.XMM0, }; + new CPUx86.Move { DestinationReg = CPUx86.Registers.ESP, SourceReg = CPUx86.Registers.EAX, DestinationIsIndirect = true }; + } + else + { + throw new Exception("Cosmos.IL2CPU.x86->IL->Conv_I1.cs->Unknown size of floating point value."); + } } - switch( xSource.Size ) + switch (xSource.Size) { case 1: case 2: - throw new Exception("The size {0:D} could not exist, because always is pushed Int32 or Int64!"); - case 4: - new CPUx86.Pop { DestinationReg = CPUx86.Registers.EAX }; - new CPUx86.MoveSignExtend { DestinationReg = CPUx86.Registers.EAX, SourceReg = CPUx86.Registers.AL }; + throw new Exception("The size {0:D} could not exist, because always is pushed Int32 or Int64!"); + case 4: + new CPUx86.Pop { DestinationReg = CPUx86.Registers.EAX }; + new CPUx86.MoveSignExtend { DestinationReg = CPUx86.Registers.EAX, SourceReg = CPUx86.Registers.AL, Size = 8 }; new CPUx86.Push { DestinationReg = CPUx86.Registers.EAX }; - break; + break; case 8: new CPUx86.Pop { DestinationReg = CPUx86.Registers.EAX }; new CPUx86.Pop { DestinationReg = CPUx86.Registers.EBX }; - new CPUx86.MoveSignExtend { DestinationReg = CPUx86.Registers.EAX, SourceReg = CPUx86.Registers.AL }; + new CPUx86.MoveSignExtend { DestinationReg = CPUx86.Registers.EAX, SourceReg = CPUx86.Registers.AL, Size = 8 }; new CPUx86.Push { DestinationReg = CPUx86.Registers.EAX }; break; default: //EmitNotImplementedException( Assembler, GetServiceProvider(), "Conv_I1: SourceSize " + xSource + " not supported!", mCurLabel, mMethodInformation, mCurOffset, mNextLabel ); - throw new NotImplementedException(); + throw new NotImplementedException("Cosmos.IL2CPU.x86->IL->Conv_I1.cs->Unknown size of variable on the top of the stack."); } Assembler.Stack.Push(4, typeof(int)); } diff --git a/source2/IL2CPU/Cosmos.IL2CPU.X86/IL/Conv_I2.cs b/source2/IL2CPU/Cosmos.IL2CPU.X86/IL/Conv_I2.cs index 9ed85368b..810934256 100644 --- a/source2/IL2CPU/Cosmos.IL2CPU.X86/IL/Conv_I2.cs +++ b/source2/IL2CPU/Cosmos.IL2CPU.X86/IL/Conv_I2.cs @@ -3,47 +3,60 @@ using CPUx86 = Cosmos.Compiler.Assembler.X86; namespace Cosmos.IL2CPU.X86.IL { - /// - /// Convert top Stack element to Int16 and extends it to Int32. - /// - [Cosmos.IL2CPU.OpCode( ILOpCode.Code.Conv_I2 )] + /// + /// Convert top Stack element to Int16 and extends it to Int32. + /// + [Cosmos.IL2CPU.OpCode(ILOpCode.Code.Conv_I2)] public class Conv_I2 : ILOp { - public Conv_I2( Cosmos.Compiler.Assembler.Assembler aAsmblr ) - : base( aAsmblr ) + public Conv_I2(Cosmos.Compiler.Assembler.Assembler aAsmblr) + : base(aAsmblr) { } - public override void Execute( MethodInfo aMethod, ILOpCode aOpCode ) + public override void Execute(MethodInfo aMethod, ILOpCode aOpCode) { var xSource = Assembler.Stack.Pop(); if (xSource.IsFloat) { - new CPUx86.SSE.MoveSS { SourceReg = CPUx86.Registers.ESP, DestinationReg = CPUx86.Registers.XMM0, SourceIsIndirect = true }; - new CPUx86.SSE.ConvertSS2SI { SourceReg = CPUx86.Registers.XMM0, DestinationReg = CPUx86.Registers.EAX }; - new CPUx86.Move { DestinationReg = CPUx86.Registers.ESP, SourceReg = CPUx86.Registers.EAX, DestinationIsIndirect = true }; + if (xSource.Size == 4) + { + new CPUx86.SSE.MoveSS { SourceReg = CPUx86.Registers.ESP, DestinationReg = CPUx86.Registers.XMM0, SourceIsIndirect = true }; + new CPUx86.SSE.ConvertSS2SIAndTruncate { SourceReg = CPUx86.Registers.XMM0, DestinationReg = CPUx86.Registers.EAX }; + new CPUx86.Move { DestinationReg = CPUx86.Registers.ESP, SourceReg = CPUx86.Registers.EAX, DestinationIsIndirect = true }; + } + else if (xSource.Size == 8) + { + new CPUx86.SSE.MoveDoubleAndDupplicate { DestinationReg = CPUx86.Registers.XMM0, SourceReg = CPUx86.Registers.ESP, SourceIsIndirect = true }; + new CPUx86.SSE.ConvertSD2SIAndTruncate { DestinationReg = CPUx86.Registers.EAX, SourceReg = CPUx86.Registers.XMM0, }; + new CPUx86.Move { DestinationReg = CPUx86.Registers.ESP, SourceReg = CPUx86.Registers.EAX, DestinationIsIndirect = true }; + } + else + { + throw new Exception("Cosmos.IL2CPU.x86->IL->Conv_I2.cs->Unknown size of floating point value."); + } } - switch( xSource.Size ) + switch (xSource.Size) { case 1: case 2: - throw new Exception("The size {0:D} could not exist, because always is pushed Int32 or Int64!"); - case 4: - new CPUx86.Pop { DestinationReg = CPUx86.Registers.EAX }; - new CPUx86.MoveSignExtend { DestinationReg = CPUx86.Registers.EAX, SourceReg = CPUx86.Registers.AX }; + throw new Exception("Cosmos.IL2CPU.x86->IL->Conv_I2.cs->The size {0:D} could not exist, because always is pushed Int32 or Int64!"); + case 4: + new CPUx86.Pop { DestinationReg = CPUx86.Registers.EAX }; + new CPUx86.MoveSignExtend { DestinationReg = CPUx86.Registers.EAX, SourceReg = CPUx86.Registers.AX, Size = 16 }; new CPUx86.Push { DestinationReg = CPUx86.Registers.EAX }; break; case 8: new CPUx86.Pop { DestinationReg = CPUx86.Registers.EAX }; new CPUx86.Pop { DestinationReg = CPUx86.Registers.EBX }; - new CPUx86.MoveSignExtend { DestinationReg = CPUx86.Registers.EAX, SourceReg = CPUx86.Registers.AX }; + new CPUx86.MoveSignExtend { DestinationReg = CPUx86.Registers.EAX, SourceReg = CPUx86.Registers.AX, Size = 16 }; new CPUx86.Push { DestinationReg = CPUx86.Registers.EAX }; break; default: - throw new NotImplementedException( "SourceSize " + xSource + " not supported!" ); + throw new NotImplementedException("Cosmos.IL2CPU.x86->IL->Conv_I2.cs->SourceSize " + xSource + " not supported!"); } - Assembler.Stack.Push(4, typeof(Int32)); + Assembler.Stack.Push(4, typeof(Int32)); } } } \ No newline at end of file diff --git a/source2/IL2CPU/Cosmos.IL2CPU.X86/IL/Conv_I4.cs b/source2/IL2CPU/Cosmos.IL2CPU.X86/IL/Conv_I4.cs index b2d2ef743..79c96106c 100644 --- a/source2/IL2CPU/Cosmos.IL2CPU.X86/IL/Conv_I4.cs +++ b/source2/IL2CPU/Cosmos.IL2CPU.X86/IL/Conv_I4.cs @@ -29,7 +29,7 @@ namespace Cosmos.IL2CPU.X86.IL if (xSource.IsFloat) { new CPUx86.SSE.MoveSS { DestinationReg = CPUx86.Registers.XMM0, SourceReg = CPUx86.Registers.ESP, SourceIsIndirect = true }; - new CPUx86.SSE.ConvertSS2SI { DestinationReg = CPUx86.Registers.EAX, SourceReg = CPUx86.Registers.XMM0 }; + new CPUx86.SSE.ConvertSS2SIAndTruncate { DestinationReg = CPUx86.Registers.EAX, SourceReg = CPUx86.Registers.XMM0 }; new CPUx86.Move { DestinationReg = CPUx86.Registers.ESP, SourceReg = CPUx86.Registers.EAX, DestinationIsIndirect = true }; } break; @@ -39,7 +39,7 @@ namespace Cosmos.IL2CPU.X86.IL if (xSource.IsFloat) { new CPUx86.SSE.MoveDoubleAndDupplicate { DestinationReg = CPUx86.Registers.XMM0, SourceReg = CPUx86.Registers.ESP, SourceIsIndirect = true }; - new CPUx86.SSE.ConvertSD2SI { DestinationReg = CPUx86.Registers.EAX, SourceReg = CPUx86.Registers.XMM0 }; + new CPUx86.SSE.ConvertSD2SIAndTruncate { DestinationReg = CPUx86.Registers.EAX, SourceReg = CPUx86.Registers.XMM0 }; new CPUx86.Move { DestinationReg = CPUx86.Registers.ESP, SourceReg = CPUx86.Registers.EAX, DestinationIsIndirect = true }; } diff --git a/source2/IL2CPU/Cosmos.IL2CPU.X86/IL/Conv_U1.cs b/source2/IL2CPU/Cosmos.IL2CPU.X86/IL/Conv_U1.cs index fe1d66d28..580579708 100644 --- a/source2/IL2CPU/Cosmos.IL2CPU.X86/IL/Conv_U1.cs +++ b/source2/IL2CPU/Cosmos.IL2CPU.X86/IL/Conv_U1.cs @@ -3,52 +3,65 @@ using CPUx86 = Cosmos.Compiler.Assembler.X86; namespace Cosmos.IL2CPU.X86.IL { - /// - /// Convert top Stack element to UInt8 and extends it to Int32. - /// - [Cosmos.IL2CPU.OpCode( ILOpCode.Code.Conv_U1 )] + /// + /// Convert top Stack element to UInt8(byte) and extends it to Int32. + /// + [Cosmos.IL2CPU.OpCode(ILOpCode.Code.Conv_U1)] public class Conv_U1 : ILOp { - public Conv_U1( Cosmos.Compiler.Assembler.Assembler aAsmblr ) - : base( aAsmblr ) + public Conv_U1(Cosmos.Compiler.Assembler.Assembler aAsmblr) + : base(aAsmblr) { } - public override void Execute( MethodInfo aMethod, ILOpCode aOpCode ) + public override void Execute(MethodInfo aMethod, ILOpCode aOpCode) { - var xSource = Assembler.Stack.Pop(); + var xSource = Assembler.Stack.Pop(); if (xSource.IsFloat) { - new CPUx86.SSE.MoveSS { SourceReg = CPUx86.Registers.ESP, DestinationReg = CPUx86.Registers.XMM0, SourceIsIndirect = true }; - new CPUx86.SSE.ConvertSS2SI { SourceReg = CPUx86.Registers.XMM0, DestinationReg = CPUx86.Registers.EAX }; - new CPUx86.Move { DestinationReg = CPUx86.Registers.ESP, SourceReg = CPUx86.Registers.EAX, DestinationIsIndirect = true }; + if (xSource.Size == 4) + { + new CPUx86.SSE.MoveSS { SourceReg = CPUx86.Registers.ESP, DestinationReg = CPUx86.Registers.XMM0, SourceIsIndirect = true }; + new CPUx86.SSE.ConvertSS2SIAndTruncate { SourceReg = CPUx86.Registers.XMM0, DestinationReg = CPUx86.Registers.EAX }; + new CPUx86.Move { DestinationReg = CPUx86.Registers.ESP, SourceReg = CPUx86.Registers.EAX, DestinationIsIndirect = true }; + } + else if (xSource.Size == 8) + { + new CPUx86.SSE.MoveDoubleAndDupplicate { DestinationReg = CPUx86.Registers.XMM0, SourceReg = CPUx86.Registers.ESP, SourceIsIndirect = true }; + new CPUx86.SSE.ConvertSD2SIAndTruncate { DestinationReg = CPUx86.Registers.EAX, SourceReg = CPUx86.Registers.XMM0, }; + new CPUx86.Move { DestinationReg = CPUx86.Registers.ESP, SourceReg = CPUx86.Registers.EAX, DestinationIsIndirect = true }; + } + else + { + throw new Exception("Cosmos.IL2CPU.x86->IL->Conv_U1.cs->Unknown size of floating point value."); + } } - switch( xSource.Size ) + switch (xSource.Size) { - case 1: + case 1: case 2: - throw new Exception("The size {0:D} could not exist, because always is pushed Int32 or Int64!"); + throw new Exception("Cosmos.IL2CPU.x86->IL->Conv_U1.cs->The size {0:D} could not exist, because always is pushed Int32 or Int64!"); case 4: { - new CPUx86.Pop { DestinationReg = CPUx86.Registers.EAX }; - new CPUx86.MoveZeroExtend { DestinationReg = CPUx86.Registers.EAX, SourceReg = CPUx86.Registers.AL }; - new CPUx86.Push { DestinationReg = CPUx86.Registers.EAX }; - break; + new CPUx86.Pop { DestinationReg = CPUx86.Registers.EAX }; + new CPUx86.MoveZeroExtend { DestinationReg = CPUx86.Registers.EAX, SourceReg = CPUx86.Registers.AL, Size = 8 }; + new CPUx86.Push { DestinationReg = CPUx86.Registers.EAX }; + break; } case 8: { new CPUx86.Pop { DestinationReg = CPUx86.Registers.EAX }; new CPUx86.Pop { DestinationReg = CPUx86.Registers.ECX }; - new CPUx86.MoveZeroExtend { DestinationReg = CPUx86.Registers.EAX, SourceReg = CPUx86.Registers.AL }; + new CPUx86.MoveZeroExtend { DestinationReg = CPUx86.Registers.EAX, SourceReg = CPUx86.Registers.AL, Size = 8 }; new CPUx86.Push { DestinationReg = CPUx86.Registers.EAX }; break; } default: //EmitNotImplementedException( Assembler, GetServiceProvider(), "Conv_I1: SourceSize " + xSource + " not supported", mCurLabel, mMethodInformation, mCurOffset, mNextLabel ); - throw new NotImplementedException(); + throw new NotImplementedException("Cosmos.IL2CPU.x86->IL->Conv_U1.cs->Unknown size of variable on the top of the stack."); } - Assembler.Stack.Push(4, typeof(int)); + Assembler.Stack.Push(4, typeof(int)); } } } \ No newline at end of file diff --git a/source2/IL2CPU/Cosmos.IL2CPU.X86/IL/Conv_U2.cs b/source2/IL2CPU/Cosmos.IL2CPU.X86/IL/Conv_U2.cs index 7901d62a1..b723ec83d 100644 --- a/source2/IL2CPU/Cosmos.IL2CPU.X86/IL/Conv_U2.cs +++ b/source2/IL2CPU/Cosmos.IL2CPU.X86/IL/Conv_U2.cs @@ -19,32 +19,45 @@ namespace Cosmos.IL2CPU.X86.IL var xSource = Assembler.Stack.Pop(); if (xSource.IsFloat) { - new CPUx86.SSE.MoveSS { SourceReg = CPUx86.Registers.ESP, DestinationReg = CPUx86.Registers.XMM0, SourceIsIndirect = true }; - new CPUx86.SSE.ConvertSS2SI { SourceReg = CPUx86.Registers.XMM0, DestinationReg = CPUx86.Registers.EAX }; - new CPUx86.Move { DestinationReg = CPUx86.Registers.ESP, SourceReg = CPUx86.Registers.EAX, DestinationIsIndirect = true }; + if (xSource.Size == 4) + { + new CPUx86.SSE.MoveSS { SourceReg = CPUx86.Registers.ESP, DestinationReg = CPUx86.Registers.XMM0, SourceIsIndirect = true }; + new CPUx86.SSE.ConvertSS2SIAndTruncate { SourceReg = CPUx86.Registers.XMM0, DestinationReg = CPUx86.Registers.EAX }; + new CPUx86.Move { DestinationReg = CPUx86.Registers.ESP, SourceReg = CPUx86.Registers.EAX, DestinationIsIndirect = true }; + } + else if (xSource.Size == 8) + { + new CPUx86.SSE.MoveDoubleAndDupplicate { DestinationReg = CPUx86.Registers.XMM0, SourceReg = CPUx86.Registers.ESP, SourceIsIndirect = true }; + new CPUx86.SSE.ConvertSD2SIAndTruncate { DestinationReg = CPUx86.Registers.EAX, SourceReg = CPUx86.Registers.XMM0, }; + new CPUx86.Move { DestinationReg = CPUx86.Registers.ESP, SourceReg = CPUx86.Registers.EAX, DestinationIsIndirect = true }; + } + else + { + throw new Exception("Cosmos.IL2CPU.x86->IL->Conv_U2.cs->Unknown size of floating point value."); + } } switch( xSource.Size ) { case 1: case 2: - throw new Exception("The size {0:D} could not exist, because always is pushed Int32 or Int64!"); + throw new Exception("Cosmos.IL2CPU.x86->IL->Conv_U2.cs->The size {0:D} could not exist, because always is pushed Int32 or Int64!"); case 4: new CPUx86.Pop { DestinationReg = CPUx86.Registers.EAX }; - new CPUx86.MoveZeroExtend { DestinationReg = CPUx86.Registers.EAX, SourceReg = CPUx86.Registers.AX }; + new CPUx86.MoveZeroExtend { DestinationReg = CPUx86.Registers.EAX, SourceReg = CPUx86.Registers.AX, Size = 16 }; new CPUx86.Push { DestinationReg = CPUx86.Registers.EAX }; break; case 8: { new CPUx86.Pop { DestinationReg = CPUx86.Registers.EAX }; new CPUx86.Pop { DestinationReg = CPUx86.Registers.ECX }; - new CPUx86.MoveZeroExtend { DestinationReg = CPUx86.Registers.EAX, SourceReg = CPUx86.Registers.AX }; + new CPUx86.MoveZeroExtend { DestinationReg = CPUx86.Registers.EAX, SourceReg = CPUx86.Registers.AX, Size = 16 }; new CPUx86.Push { DestinationReg = CPUx86.Registers.EAX }; break; } default: //EmitNotImplementedException( Assembler, GetServiceProvider(), "Conv_U2: SourceSize " + xSource + " not yet supported!", mCurLabel, mMethodInformation, mCurOffset, mNextLabel ); - throw new NotImplementedException(); + throw new NotImplementedException("Cosmos.IL2CPU.x86->IL->Conv_U2.cs->Unknown size of variable on the top of the stack."); } Assembler.Stack.Push(Align(4, 4), typeof(int)); } diff --git a/source2/IL2CPU/Cosmos.IL2CPU.X86/IL/Conv_U4.cs b/source2/IL2CPU/Cosmos.IL2CPU.X86/IL/Conv_U4.cs index 370d5c85c..2ec5f27b2 100644 --- a/source2/IL2CPU/Cosmos.IL2CPU.X86/IL/Conv_U4.cs +++ b/source2/IL2CPU/Cosmos.IL2CPU.X86/IL/Conv_U4.cs @@ -16,15 +16,12 @@ namespace Cosmos.IL2CPU.X86.IL public override void Execute( MethodInfo aMethod, ILOpCode aOpCode ) { - // todo: WARNING: not implemented correctly! var xSource = Assembler.Stack.Pop(); - - switch( xSource.Size ) { case 1: case 2: - throw new Exception("The size {0:D} could not exist, because always is pushed Int32 or Int64!"); + throw new Exception("Cosmos.IL2CPU.x86->IL->Conv_U4.cs->The size {0:D} could not exist, because always is pushed Int32 or Int64!"); case 4: if (xSource.IsFloat) { @@ -36,10 +33,13 @@ namespace Cosmos.IL2CPU.X86.IL case 8: if (xSource.IsFloat) { - throw new Exception("conv.u4"); - //new CPUx86.SSE.MoveSD { DestinationReg = CPUx86.Registers.XMM0, SourceReg = CPUx86.Registers.ESP, SourceIsIndirect = true }; - //new CPUx86.SSE.ConvertSD2SIAndTruncate { DestinationReg = CPUx86.Registers.EAX, SourceReg = CPUx86.Registers.XMM0, }; - //new CPUx86.Move { DestinationReg = CPUx86.Registers.ESP, SourceReg = CPUx86.Registers.EAX, DestinationIsIndirect = true }; + new CPUx86.SSE.MoveDoubleAndDupplicate { DestinationReg = CPUx86.Registers.XMM0, SourceReg = CPUx86.Registers.ESP, SourceIsIndirect = true }; + new CPUx86.SSE.ConvertSD2SIAndTruncate { DestinationReg = CPUx86.Registers.EAX, SourceReg = CPUx86.Registers.XMM0, }; + new CPUx86.Move { DestinationReg = CPUx86.Registers.ESP, SourceReg = CPUx86.Registers.EAX, DestinationIsIndirect = true }; + new CPUx86.Pop { DestinationReg = CPUx86.Registers.EAX }; + new CPUx86.Add { DestinationReg = CPUx86.Registers.ESP, SourceValue = 4 }; + new CPUx86.Push { DestinationReg = CPUx86.Registers.EAX }; + break; } else { @@ -50,7 +50,7 @@ namespace Cosmos.IL2CPU.X86.IL } default: //EmitNotImplementedException( Assembler, GetServiceProvider(), "Conv_U4: SourceSize " + xStackItem.Size + " not supported!", mCurLabel, mMethodInformation, mCurOffset, mNextLabel ); - throw new NotImplementedException(); + throw new NotImplementedException("Cosmos.IL2CPU.x86->IL->Conv_U4.cs->Unknown size of variable on the top of the stack."); } Assembler.Stack.Push(Align(4, 4), typeof(Int32)); } diff --git a/source2/IL2CPU/Cosmos.IL2CPU.X86/IL/Conv_U8.cs b/source2/IL2CPU/Cosmos.IL2CPU.X86/IL/Conv_U8.cs index 49ec764bc..9e104d4ca 100644 --- a/source2/IL2CPU/Cosmos.IL2CPU.X86/IL/Conv_U8.cs +++ b/source2/IL2CPU/Cosmos.IL2CPU.X86/IL/Conv_U8.cs @@ -3,54 +3,57 @@ using CPUx86 = Cosmos.Compiler.Assembler.X86; using Cosmos.Compiler.Assembler.X86; namespace Cosmos.IL2CPU.X86.IL { - /// - /// Convert top Stack element to UInt64 and change its type to Int64. - /// - [Cosmos.IL2CPU.OpCode(ILOpCode.Code.Conv_U8)] - public class Conv_U8: ILOp - { - public Conv_U8(Cosmos.Compiler.Assembler.Assembler aAsmblr):base(aAsmblr) - { - } - - public override void Execute(MethodInfo aMethod, ILOpCode aOpCode) { - var xSource = Assembler.Stack.Pop(); - switch( xSource.Size ) + /// + /// Convert top Stack element to UInt64 and change its type to Int64. + /// + [Cosmos.IL2CPU.OpCode(ILOpCode.Code.Conv_U8)] + public class Conv_U8 : ILOp + { + public Conv_U8(Cosmos.Compiler.Assembler.Assembler aAsmblr) + : base(aAsmblr) { - case 1: - case 2: - throw new Exception("The size {0:D} could not exist, because always is pushed Int32 or Int64!"); - case 4: - { - if (xSource.IsFloat) + } + + public override void Execute(MethodInfo aMethod, ILOpCode aOpCode) + { + var xSource = Assembler.Stack.Pop(); + switch (xSource.Size) + { + case 1: + case 2: + throw new Exception("Cosmos.IL2CPU.x86->IL->Conv_U8.cs->The size {0:D} could not exist, because always is pushed Int32 or Int64!"); + case 4: { - new CPUx86.x87.FloatLoad { DestinationReg = Registers.ESP, Size = 32, DestinationIsIndirect = true }; - new CPUx86.Sub { DestinationReg = Registers.ESP, SourceValue = 4 }; - new CPUx86.x87.IntStoreWithTrunc { DestinationReg = Registers.ESP, Size = 64, DestinationIsIndirect = true }; + if (xSource.IsFloat) + { + new CPUx86.x87.FloatLoad { DestinationReg = Registers.ESP, Size = 32, DestinationIsIndirect = true }; + new CPUx86.Sub { DestinationReg = Registers.ESP, SourceValue = 4 }; + new CPUx86.x87.IntStoreWithTrunc { DestinationReg = Registers.ESP, Size = 64, DestinationIsIndirect = true }; + } + else + { + new CPUx86.Pop { DestinationReg = CPUx86.Registers.EAX }; + new CPUx86.Push { DestinationValue = 0 }; + new CPUx86.Push { DestinationReg = CPUx86.Registers.EAX }; + } + break; } - else + case 8: { - new CPUx86.Pop { DestinationReg = CPUx86.Registers.EAX }; - new CPUx86.Push { DestinationValue = 0 }; - new CPUx86.Push { DestinationReg = CPUx86.Registers.EAX }; + if (xSource.IsFloat) + { + new CPUx86.x87.FloatLoad { DestinationReg = Registers.ESP, Size = 64, DestinationIsIndirect = true }; + new CPUx86.x87.FloatABS(); + new CPUx86.x87.IntStoreWithTrunc { DestinationReg = Registers.ESP, Size = 64, DestinationIsIndirect = true }; + } + //Else it's already an Int64, or UInt64 + break; } - break; - } - case 8: - { - if (xSource.IsFloat) - { - new CPUx86.x87.FloatLoad { DestinationReg = Registers.ESP, Size = 64, DestinationIsIndirect = true }; - new CPUx86.x87.FloatABS(); - new CPUx86.x87.IntStoreAndPop { DestinationReg = Registers.ESP, Size = 64, DestinationIsIndirect = true }; - } - break; - } - default: - //EmitNotImplementedException( Assembler, GetServiceProvider(), "Conv_U8: SourceSize " + xSource + " not supported!", mCurLabel, mMethodInformation, mCurOffset, mNextLabel ); - throw new NotImplementedException(); - } - Assembler.Stack.Push(Align(8, 4), typeof(Int64)); - } - } + default: + //EmitNotImplementedException( Assembler, GetServiceProvider(), "Conv_U8: SourceSize " + xSource + " not supported!", mCurLabel, mMethodInformation, mCurOffset, mNextLabel ); + throw new NotImplementedException("Cosmos.IL2CPU.x86->IL->Conv_U8.cs->Unknown size of variable on the top of the stack."); + } + Assembler.Stack.Push(Align(8, 4), typeof(Int64)); + } + } } \ No newline at end of file