ILOpCodeStore.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using ChocolArm64.State;
  2. using System.Reflection.Emit;
  3. namespace ChocolArm64.Translation
  4. {
  5. struct ILOpCodeStore : IILEmit
  6. {
  7. public int Index { get; private set; }
  8. public IoType IoType { get; private set; }
  9. public RegisterSize RegisterSize { get; private set; }
  10. public ILOpCodeStore(int index, IoType ioType, RegisterSize registerSize = 0)
  11. {
  12. Index = index;
  13. IoType = ioType;
  14. RegisterSize = registerSize;
  15. }
  16. public void Emit(ILMethodBuilder context)
  17. {
  18. switch (IoType)
  19. {
  20. case IoType.Arg: context.Generator.EmitStarg(Index); break;
  21. case IoType.Flag: EmitStloc(context, Index, RegisterType.Flag); break;
  22. case IoType.Int: EmitStloc(context, Index, RegisterType.Int); break;
  23. case IoType.Vector: EmitStloc(context, Index, RegisterType.Vector); break;
  24. }
  25. }
  26. private void EmitStloc(ILMethodBuilder context, int index, RegisterType registerType)
  27. {
  28. Register reg = new Register(index, registerType);
  29. if (registerType == RegisterType.Int &&
  30. RegisterSize == RegisterSize.Int32)
  31. {
  32. context.Generator.Emit(OpCodes.Conv_U8);
  33. }
  34. context.Generator.EmitStloc(context.GetLocalIndex(reg));
  35. }
  36. }
  37. }