// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details #include "Luau/NativeProtoExecData.h" #include "Luau/Common.h" #include namespace Luau { namespace CodeGen { [[nodiscard]] static size_t computeNativeExecDataSize(uint32_t bytecodeInstructionCount) noexcept { return sizeof(NativeProtoExecDataHeader) + (bytecodeInstructionCount * sizeof(uint32_t)); } void NativeProtoExecDataDeleter::operator()(const uint32_t* instructionOffsets) const noexcept { destroyNativeProtoExecData(instructionOffsets); } [[nodiscard]] NativeProtoExecDataPtr createNativeProtoExecData(uint32_t bytecodeInstructionCount) { std::unique_ptr bytes = std::make_unique(computeNativeExecDataSize(bytecodeInstructionCount)); new (static_cast(bytes.get())) NativeProtoExecDataHeader{}; return NativeProtoExecDataPtr{reinterpret_cast(bytes.release() + sizeof(NativeProtoExecDataHeader))}; } void destroyNativeProtoExecData(const uint32_t* instructionOffsets) noexcept { const NativeProtoExecDataHeader* header = &getNativeProtoExecDataHeader(instructionOffsets); header->~NativeProtoExecDataHeader(); delete[] reinterpret_cast(header); } [[nodiscard]] NativeProtoExecDataHeader& getNativeProtoExecDataHeader(uint32_t* instructionOffsets) noexcept { return *reinterpret_cast(reinterpret_cast(instructionOffsets) - sizeof(NativeProtoExecDataHeader)); } [[nodiscard]] const NativeProtoExecDataHeader& getNativeProtoExecDataHeader(const uint32_t* instructionOffsets) noexcept { return *reinterpret_cast( reinterpret_cast(instructionOffsets) - sizeof(NativeProtoExecDataHeader) ); } } // namespace CodeGen } // namespace Luau