Path: blob/master/CodeGen/include/Luau/NativeProtoExecData.h
2727 views
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details1#pragma once23#include <memory>4#include <stdint.h>56namespace Luau7{8namespace CodeGen9{1011// The NativeProtoExecData is constant metadata associated with a NativeProto.12// We generally refer to the NativeProtoExecData via a pointer to the instruction13// offsets array because this makes the logic in the entry gate simpler.1415class NativeModule;1617struct NativeProtoExecDataHeader18{19// The NativeModule that owns this NativeProto. This is initialized20// when the NativeProto is bound to the NativeModule via assignToModule().21NativeModule* nativeModule = nullptr;2223// We store the native code offset until the code is allocated in executable24// pages, after which point we store the actual address.25const uint8_t* entryOffsetOrAddress = nullptr;2627// The bytecode id of the proto28uint32_t bytecodeId = 0;2930// The number of bytecode instructions in the proto. This is the number of31// elements in the instruction offsets array following this header.32uint32_t bytecodeInstructionCount = 0;3334// The number of extra uin32_t elements of custom data after the bytecode offsets35uint32_t extraDataCount = 0;3637// The size of the native code for this NativeProto, in bytes.38size_t nativeCodeSize = 0;39};4041// Make sure that the instruction offsets array following the header will be42// correctly aligned:43static_assert(sizeof(NativeProtoExecDataHeader) % sizeof(uint32_t) == 0);4445struct NativeProtoExecDataDeleter46{47void operator()(const uint32_t* instructionOffsets) const noexcept;48};4950using NativeProtoExecDataPtr = std::unique_ptr<uint32_t[], NativeProtoExecDataDeleter>;5152[[nodiscard]] NativeProtoExecDataPtr createNativeProtoExecData(uint32_t bytecodeInstructionCount, uint32_t extraDataCount);53void destroyNativeProtoExecData(const uint32_t* instructionOffsets) noexcept;5455[[nodiscard]] NativeProtoExecDataHeader& getNativeProtoExecDataHeader(uint32_t* instructionOffsets) noexcept;56[[nodiscard]] const NativeProtoExecDataHeader& getNativeProtoExecDataHeader(const uint32_t* instructionOffsets) noexcept;5758} // namespace CodeGen59} // namespace Luau606162