using ARMeilleure.CodeGen.Linking; using ARMeilleure.CodeGen.Unwinding; using ARMeilleure.Translation.Cache; using System; using System.Runtime.InteropServices; namespace ARMeilleure.CodeGen { /// /// Represents a compiled function. /// readonly struct CompiledFunction { /// /// Gets the machine code of the . /// public byte[] Code { get; } /// /// Gets the of the . /// public UnwindInfo UnwindInfo { get; } /// /// Gets the of the . /// public RelocInfo RelocInfo { get; } /// /// Initializes a new instance of the struct with the specified machine code, /// unwind info and relocation info. /// /// Machine code /// Unwind info /// Relocation info internal CompiledFunction(byte[] code, UnwindInfo unwindInfo, RelocInfo relocInfo) { Code = code; UnwindInfo = unwindInfo; RelocInfo = relocInfo; } /// /// Maps the onto the and returns a delegate of type /// pointing to the mapped function. /// /// Type of delegate /// A delegate of type pointing to the mapped function public T Map() { return MapWithPointer(out _); } /// /// Maps the onto the and returns a delegate of type /// pointing to the mapped function. /// /// Type of delegate /// Pointer to the function code in memory /// A delegate of type pointing to the mapped function public T MapWithPointer(out IntPtr codePointer) { codePointer = JitCache.Map(this); return Marshal.GetDelegateForFunctionPointer(codePointer); } } }