mirror of
https://github.com/danbulant/Cosmos
synced 2026-05-19 20:39:01 +00:00
Changes in Conv*, Ld* and St* opcodes so that values with size < 4 bytes are extended to 4 bytes. Implemented Not and Xor for values with size 8 bytes. Added tests for bitwise operations, arithmetic operations and Conv* opcodes.
53 lines
1.5 KiB
C#
53 lines
1.5 KiB
C#
using Cosmos.IL2CPU.ILOpCodes;
|
|
using XSharp.Compiler;
|
|
using static XSharp.Compiler.XSRegisters;
|
|
|
|
using CPUx86 = Cosmos.Assembler.x86;
|
|
|
|
namespace Cosmos.IL2CPU.X86.IL
|
|
{
|
|
[OpCode(ILOpCode.Code.Ldloc)]
|
|
public class Ldloc : ILOp
|
|
{
|
|
public Ldloc(Assembler.Assembler aAsmblr)
|
|
: base(aAsmblr)
|
|
{
|
|
}
|
|
|
|
public override void Execute(MethodInfo aMethod, ILOpCode aOpCode)
|
|
{
|
|
var xOpVar = (OpVar)aOpCode;
|
|
var xVar = aMethod.MethodBase.GetMethodBody().LocalVariables[xOpVar.Value];
|
|
var xStackCount = (int)GetStackCountForLocal(aMethod, xVar);
|
|
var xEBPOffset = (int)GetEBPOffsetForLocal(aMethod, xOpVar.Value);
|
|
var xSize = SizeOfType(xVar.LocalType);
|
|
|
|
XS.Comment("Local type = " + xVar.LocalType);
|
|
XS.Comment("Local EBP offset = " + xEBPOffset);
|
|
XS.Comment("Local size = " + xSize);
|
|
|
|
switch (xSize)
|
|
{
|
|
case 1:
|
|
case 2:
|
|
if (IsIntegerSigned(xVar.LocalType))
|
|
{
|
|
XS.MoveSignExtend(EAX, EBP, sourceDisplacement: 0 - xEBPOffset, size: (RegisterSize)(xSize * 8));
|
|
}
|
|
else
|
|
{
|
|
XS.MoveZeroExtend(EAX, EBP, sourceDisplacement: 0 - xEBPOffset, size: (RegisterSize)(xSize * 8));
|
|
}
|
|
XS.Push(EAX);
|
|
break;
|
|
default:
|
|
for (int i = 0; i < xStackCount; i++)
|
|
{
|
|
XS.Set(EAX, EBP, sourceDisplacement: 0 - (xEBPOffset + (i * 4)));
|
|
XS.Push(EAX);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|