2018-02-05 00:08:20 +01:00
|
|
|
using ChocolArm64.State;
|
|
|
|
using System.Reflection.Emit;
|
|
|
|
|
|
|
|
namespace ChocolArm64.Translation
|
|
|
|
{
|
|
|
|
struct AILOpCodeStore : IAILEmit
|
|
|
|
{
|
|
|
|
public int Index { get; private set; }
|
|
|
|
|
2018-02-17 22:06:11 +01:00
|
|
|
public AIoType IoType { get; private set; }
|
|
|
|
|
|
|
|
public ARegisterSize RegisterSize { get; private set; }
|
2018-02-05 00:08:20 +01:00
|
|
|
|
2018-02-26 02:14:58 +01:00
|
|
|
public AILOpCodeStore(int Index, AIoType IoType, ARegisterSize RegisterSize = 0)
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
2018-02-17 22:06:11 +01:00
|
|
|
this.Index = Index;
|
2018-02-26 02:14:58 +01:00
|
|
|
this.IoType = IoType;
|
2018-02-17 22:06:11 +01:00
|
|
|
this.RegisterSize = RegisterSize;
|
2018-02-05 00:08:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void Emit(AILEmitter Context)
|
|
|
|
{
|
2018-02-18 05:57:33 +01:00
|
|
|
switch (IoType)
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
2018-02-17 22:06:11 +01:00
|
|
|
case AIoType.Arg: Context.Generator.EmitStarg(Index); break;
|
|
|
|
|
|
|
|
case AIoType.Fields:
|
|
|
|
{
|
|
|
|
long IntOutputs = Context.LocalAlloc.GetIntOutputs(Context.GetILBlock(Index));
|
|
|
|
long VecOutputs = Context.LocalAlloc.GetVecOutputs(Context.GetILBlock(Index));
|
|
|
|
|
|
|
|
StoreLocals(Context, IntOutputs, ARegisterType.Int);
|
|
|
|
StoreLocals(Context, VecOutputs, ARegisterType.Vector);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-02-05 00:08:20 +01:00
|
|
|
case AIoType.Flag: EmitStloc(Context, Index, ARegisterType.Flag); break;
|
|
|
|
case AIoType.Int: EmitStloc(Context, Index, ARegisterType.Int); break;
|
|
|
|
case AIoType.Vector: EmitStloc(Context, Index, ARegisterType.Vector); break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void StoreLocals(AILEmitter Context, long Outputs, ARegisterType BaseType)
|
|
|
|
{
|
|
|
|
for (int Bit = 0; Bit < 64; Bit++)
|
|
|
|
{
|
|
|
|
long Mask = 1L << Bit;
|
|
|
|
|
|
|
|
if ((Outputs & Mask) != 0)
|
|
|
|
{
|
|
|
|
ARegister Reg = AILEmitter.GetRegFromBit(Bit, BaseType);
|
|
|
|
|
2018-02-18 20:28:07 +01:00
|
|
|
Context.Generator.EmitLdarg(ATranslatedSub.StateArgIdx);
|
2018-02-05 00:08:20 +01:00
|
|
|
Context.Generator.EmitLdloc(Context.GetLocalIndex(Reg));
|
|
|
|
|
|
|
|
Context.Generator.Emit(OpCodes.Stfld, Reg.GetField());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-17 22:06:11 +01:00
|
|
|
private void EmitStloc(AILEmitter Context, int Index, ARegisterType RegisterType)
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
2018-02-17 22:06:11 +01:00
|
|
|
ARegister Reg = new ARegister(Index, RegisterType);
|
2018-02-05 00:08:20 +01:00
|
|
|
|
2018-02-17 22:06:11 +01:00
|
|
|
if (RegisterType == ARegisterType.Int &&
|
|
|
|
RegisterSize == ARegisterSize.Int32)
|
|
|
|
{
|
|
|
|
Context.Generator.Emit(OpCodes.Conv_U8);
|
|
|
|
}
|
2018-02-05 00:08:20 +01:00
|
|
|
|
|
|
|
Context.Generator.EmitStloc(Context.GetLocalIndex(Reg));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|