2018-10-30 18:43:02 -07:00
|
|
|
using ChocolArm64.State;
|
|
|
|
using System.Reflection.Emit;
|
|
|
|
|
|
|
|
namespace ChocolArm64.Translation
|
|
|
|
{
|
2018-12-10 16:58:52 -08:00
|
|
|
struct ILOpCodeStore : IILEmit
|
2018-10-30 18:43:02 -07:00
|
|
|
{
|
2019-02-27 18:03:31 -08:00
|
|
|
public int Index { get; }
|
2018-10-30 18:43:02 -07:00
|
|
|
|
2019-02-27 18:03:31 -08:00
|
|
|
public VarType VarType { get; }
|
2018-10-30 18:43:02 -07:00
|
|
|
|
2019-02-27 18:03:31 -08:00
|
|
|
public RegisterSize RegisterSize { get; }
|
2018-10-30 18:43:02 -07:00
|
|
|
|
2019-02-27 18:03:31 -08:00
|
|
|
public ILOpCodeStore(int index, VarType varType, RegisterSize registerSize = 0)
|
2018-10-30 18:43:02 -07:00
|
|
|
{
|
|
|
|
Index = index;
|
2019-02-27 18:03:31 -08:00
|
|
|
VarType = varType;
|
2018-10-30 18:43:02 -07:00
|
|
|
RegisterSize = registerSize;
|
|
|
|
}
|
|
|
|
|
2018-12-10 16:58:52 -08:00
|
|
|
public void Emit(ILMethodBuilder context)
|
2018-10-30 18:43:02 -07:00
|
|
|
{
|
2019-02-27 18:03:31 -08:00
|
|
|
switch (VarType)
|
2018-10-30 18:43:02 -07:00
|
|
|
{
|
2019-02-27 18:03:31 -08:00
|
|
|
case VarType.Arg: context.Generator.EmitStarg(Index); break;
|
2018-10-30 18:43:02 -07:00
|
|
|
|
2019-02-27 18:03:31 -08:00
|
|
|
case VarType.Flag: EmitStloc(context, Index, RegisterType.Flag); break;
|
|
|
|
case VarType.Int: EmitStloc(context, Index, RegisterType.Int); break;
|
|
|
|
case VarType.Vector: EmitStloc(context, Index, RegisterType.Vector); break;
|
2018-10-30 18:43:02 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-10 16:58:52 -08:00
|
|
|
private void EmitStloc(ILMethodBuilder context, int index, RegisterType registerType)
|
2018-10-30 18:43:02 -07:00
|
|
|
{
|
|
|
|
Register reg = new Register(index, registerType);
|
|
|
|
|
|
|
|
if (registerType == RegisterType.Int &&
|
|
|
|
RegisterSize == RegisterSize.Int32)
|
|
|
|
{
|
|
|
|
context.Generator.Emit(OpCodes.Conv_U8);
|
|
|
|
}
|
|
|
|
|
|
|
|
context.Generator.EmitStloc(context.GetLocalIndex(reg));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|