TranslatedFunction.cs 891 B

123456789101112131415161718192021222324252627282930
  1. using ARMeilleure.Common;
  2. using System;
  3. using System.Runtime.InteropServices;
  4. namespace ARMeilleure.Translation
  5. {
  6. class TranslatedFunction
  7. {
  8. private readonly GuestFunction _func; // Ensure that this delegate will not be garbage collected.
  9. public Counter<uint> CallCounter { get; }
  10. public ulong GuestSize { get; }
  11. public bool HighCq { get; }
  12. public IntPtr FuncPtr { get; }
  13. public TranslatedFunction(GuestFunction func, Counter<uint> callCounter, ulong guestSize, bool highCq)
  14. {
  15. _func = func;
  16. CallCounter = callCounter;
  17. GuestSize = guestSize;
  18. HighCq = highCq;
  19. FuncPtr = Marshal.GetFunctionPointerForDelegate(func);
  20. }
  21. public ulong Execute(State.ExecutionContext context)
  22. {
  23. return _func(context.NativeContextPtr);
  24. }
  25. }
  26. }