2018-10-31 02:43:02 +01:00
|
|
|
using ChocolArm64.State;
|
|
|
|
using System.Reflection.Emit;
|
|
|
|
|
|
|
|
namespace ChocolArm64.Translation
|
|
|
|
{
|
2018-12-11 01:58:52 +01:00
|
|
|
struct ILOpCodeStore : IILEmit
|
2018-10-31 02:43:02 +01:00
|
|
|
{
|
2019-02-28 03:03:31 +01:00
|
|
|
public int Index { get; }
|
2018-10-31 02:43:02 +01:00
|
|
|
|
2019-02-28 03:03:31 +01:00
|
|
|
public VarType VarType { get; }
|
2018-10-31 02:43:02 +01:00
|
|
|
|
2019-02-28 03:03:31 +01:00
|
|
|
public RegisterSize RegisterSize { get; }
|
2018-10-31 02:43:02 +01:00
|
|
|
|
2019-02-28 03:03:31 +01:00
|
|
|
public ILOpCodeStore(int index, VarType varType, RegisterSize registerSize = 0)
|
2018-10-31 02:43:02 +01:00
|
|
|
{
|
|
|
|
Index = index;
|
2019-02-28 03:03:31 +01:00
|
|
|
VarType = varType;
|
2018-10-31 02:43:02 +01:00
|
|
|
RegisterSize = registerSize;
|
|
|
|
}
|
|
|
|
|
2018-12-11 01:58:52 +01:00
|
|
|
public void Emit(ILMethodBuilder context)
|
2018-10-31 02:43:02 +01:00
|
|
|
{
|
2019-02-28 03:03:31 +01:00
|
|
|
switch (VarType)
|
2018-10-31 02:43:02 +01:00
|
|
|
{
|
2019-02-28 03:03:31 +01:00
|
|
|
case VarType.Arg: context.Generator.EmitStarg(Index); break;
|
2018-10-31 02:43:02 +01:00
|
|
|
|
2019-02-28 03:03:31 +01: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-31 02:43:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-11 01:58:52 +01:00
|
|
|
private void EmitStloc(ILMethodBuilder context, int index, RegisterType registerType)
|
2018-10-31 02:43:02 +01: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));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|