Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Roblox
GitHub Repository: Roblox/luau
Path: blob/master/CodeGen/include/Luau/NativeProtoExecData.h
2727 views
1
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
2
#pragma once
3
4
#include <memory>
5
#include <stdint.h>
6
7
namespace Luau
8
{
9
namespace CodeGen
10
{
11
12
// The NativeProtoExecData is constant metadata associated with a NativeProto.
13
// We generally refer to the NativeProtoExecData via a pointer to the instruction
14
// offsets array because this makes the logic in the entry gate simpler.
15
16
class NativeModule;
17
18
struct NativeProtoExecDataHeader
19
{
20
// The NativeModule that owns this NativeProto. This is initialized
21
// when the NativeProto is bound to the NativeModule via assignToModule().
22
NativeModule* nativeModule = nullptr;
23
24
// We store the native code offset until the code is allocated in executable
25
// pages, after which point we store the actual address.
26
const uint8_t* entryOffsetOrAddress = nullptr;
27
28
// The bytecode id of the proto
29
uint32_t bytecodeId = 0;
30
31
// The number of bytecode instructions in the proto. This is the number of
32
// elements in the instruction offsets array following this header.
33
uint32_t bytecodeInstructionCount = 0;
34
35
// The number of extra uin32_t elements of custom data after the bytecode offsets
36
uint32_t extraDataCount = 0;
37
38
// The size of the native code for this NativeProto, in bytes.
39
size_t nativeCodeSize = 0;
40
};
41
42
// Make sure that the instruction offsets array following the header will be
43
// correctly aligned:
44
static_assert(sizeof(NativeProtoExecDataHeader) % sizeof(uint32_t) == 0);
45
46
struct NativeProtoExecDataDeleter
47
{
48
void operator()(const uint32_t* instructionOffsets) const noexcept;
49
};
50
51
using NativeProtoExecDataPtr = std::unique_ptr<uint32_t[], NativeProtoExecDataDeleter>;
52
53
[[nodiscard]] NativeProtoExecDataPtr createNativeProtoExecData(uint32_t bytecodeInstructionCount, uint32_t extraDataCount);
54
void destroyNativeProtoExecData(const uint32_t* instructionOffsets) noexcept;
55
56
[[nodiscard]] NativeProtoExecDataHeader& getNativeProtoExecDataHeader(uint32_t* instructionOffsets) noexcept;
57
[[nodiscard]] const NativeProtoExecDataHeader& getNativeProtoExecDataHeader(const uint32_t* instructionOffsets) noexcept;
58
59
} // namespace CodeGen
60
} // namespace Luau
61
62