Cosmos/source/Cosmos.IL2CPU/IL/Stloc.cs
2017-01-31 11:22:59 -06:00

36 lines
1 KiB
C#

using Cosmos.Debug.Symbols;
using Cosmos.IL2CPU.Extensions;
using Cosmos.IL2CPU.ILOpCodes;
using XSharp.Compiler;
using static XSharp.Compiler.XSRegisters;
namespace Cosmos.IL2CPU.X86.IL
{
[OpCode(ILOpCode.Code.Stloc)]
public class Stloc : ILOp
{
public Stloc(Assembler.Assembler aAsmblr)
: base(aAsmblr)
{
}
public override void Execute(_MethodInfo aMethod, ILOpCode aOpCode)
{
var xOpVar = (OpVar) aOpCode;
var xVar = DebugSymbolReader.GetLocalVariableInfos(aMethod.MethodBase)[xOpVar.Value];
var xStackCount = (int) GetStackCountForLocal(aMethod, xVar);
var xEBPOffset = (int) GetEBPOffsetForLocal(aMethod, xOpVar.Value);
var xSize = SizeOfType(xVar);
XS.Comment("Local type = " + xVar);
XS.Comment("Local EBP offset = " + xEBPOffset);
XS.Comment("Local size = " + xSize);
for (int i = xStackCount - 1; i >= 0; i--)
{
XS.Pop(EAX);
XS.Set(EBP, EAX, destinationDisplacement: 0 - (xEBPOffset + (i*4)));
}
}
}
}