CompiledFunction.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using ARMeilleure.CodeGen.Linking;
  2. using ARMeilleure.CodeGen.Unwinding;
  3. using ARMeilleure.Translation.Cache;
  4. using System;
  5. using System.Runtime.InteropServices;
  6. namespace ARMeilleure.CodeGen
  7. {
  8. /// <summary>
  9. /// Represents a compiled function.
  10. /// </summary>
  11. readonly struct CompiledFunction
  12. {
  13. /// <summary>
  14. /// Gets the machine code of the <see cref="CompiledFunction"/>.
  15. /// </summary>
  16. public byte[] Code { get; }
  17. /// <summary>
  18. /// Gets the <see cref="Unwinding.UnwindInfo"/> of the <see cref="CompiledFunction"/>.
  19. /// </summary>
  20. public UnwindInfo UnwindInfo { get; }
  21. /// <summary>
  22. /// Gets the <see cref="Linking.RelocInfo"/> of the <see cref="CompiledFunction"/>.
  23. /// </summary>
  24. public RelocInfo RelocInfo { get; }
  25. /// <summary>
  26. /// Initializes a new instance of the <see cref="CompiledFunction"/> struct with the specified machine code,
  27. /// unwind info and relocation info.
  28. /// </summary>
  29. /// <param name="code">Machine code</param>
  30. /// <param name="unwindInfo">Unwind info</param>
  31. /// <param name="relocInfo">Relocation info</param>
  32. internal CompiledFunction(byte[] code, UnwindInfo unwindInfo, RelocInfo relocInfo)
  33. {
  34. Code = code;
  35. UnwindInfo = unwindInfo;
  36. RelocInfo = relocInfo;
  37. }
  38. /// <summary>
  39. /// Maps the <see cref="CompiledFunction"/> onto the <see cref="JitCache"/> and returns a delegate of type
  40. /// <typeparamref name="T"/> pointing to the mapped function.
  41. /// </summary>
  42. /// <typeparam name="T">Type of delegate</typeparam>
  43. /// <returns>A delegate of type <typeparamref name="T"/> pointing to the mapped function</returns>
  44. public T Map<T>()
  45. {
  46. IntPtr codePtr = JitCache.Map(this);
  47. return Marshal.GetDelegateForFunctionPointer<T>(codePtr);
  48. }
  49. }
  50. }