Made Dup IL working for stack content size greater than 4

This commit is contained in:
AtomOS_cp 2014-06-11 05:38:33 +00:00
parent cc6d1951ce
commit b4e746fcf8

View file

@ -3,24 +3,25 @@ using CPUx86 = Cosmos.Assembler.x86;
namespace Cosmos.IL2CPU.X86.IL
{
[Cosmos.IL2CPU.OpCode( ILOpCode.Code.Dup )]
[Cosmos.IL2CPU.OpCode(ILOpCode.Code.Dup)]
public class Dup : ILOp
{
public Dup( Cosmos.Assembler.Assembler aAsmblr )
: base( aAsmblr )
public Dup(Cosmos.Assembler.Assembler aAsmblr)
: base(aAsmblr)
{
}
public override void Execute( MethodInfo aMethod, ILOpCode aOpCode )
public override void Execute(MethodInfo aMethod, ILOpCode aOpCode)
{
var xStackContent = Assembler.Stack.Peek();
for( int i = 0; i < ( ( xStackContent.Size / 4 ) + ( xStackContent.Size % 4 == 0 ? 0 : 1 ) ); i++ )
var StackSize = (int)((xStackContent.Size / 4) + (xStackContent.Size % 4 == 0 ? 0 : 1));
for (int i = StackSize; i > 0; i--)
{
new CPUx86.Mov { DestinationReg = CPUx86.Registers.EAX, SourceReg = CPUx86.Registers.ESP, SourceDisplacement = i * 4, SourceIsIndirect = true };
new CPUx86.Push { DestinationReg = CPUx86.Registers.EAX };
new CPUx86.Push { DestinationReg = CPUx86.Registers.ESP, DestinationIsIndirect = true, DestinationDisplacement = (int)((StackSize - 1) * 4) };
}
Assembler.Stack.Push(xStackContent.Size, xStackContent.ContentType);
}
}
}
}