InstEmitFlowHelper.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using ChocolArm64.Translation;
  2. using System.Reflection.Emit;
  3. namespace ChocolArm64.Instructions
  4. {
  5. static class InstEmitFlowHelper
  6. {
  7. public static void EmitCall(ILEmitterCtx context, long imm)
  8. {
  9. if (context.TryOptEmitSubroutineCall())
  10. {
  11. //Note: the return value of the called method will be placed
  12. //at the Stack, the return value is always a Int64 with the
  13. //return address of the function. We check if the address is
  14. //correct, if it isn't we keep returning until we reach the dispatcher.
  15. context.Emit(OpCodes.Dup);
  16. context.EmitLdc_I8(context.CurrOp.Position + 4);
  17. ILLabel lblContinue = new ILLabel();
  18. context.Emit(OpCodes.Beq_S, lblContinue);
  19. context.Emit(OpCodes.Ret);
  20. context.MarkLabel(lblContinue);
  21. context.Emit(OpCodes.Pop);
  22. context.EmitLoadState();
  23. }
  24. else
  25. {
  26. context.EmitLdc_I8(imm);
  27. context.Emit(OpCodes.Ret);
  28. }
  29. }
  30. }
  31. }