Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Roblox
GitHub Repository: Roblox/luau
Path: blob/master/CodeGen/include/Luau/UnwindBuilder.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 "Luau/RegisterA64.h"
5
#include "Luau/RegisterX64.h"
6
7
#include <initializer_list>
8
#include <vector>
9
10
#include <stddef.h>
11
#include <stdint.h>
12
13
namespace Luau
14
{
15
namespace CodeGen
16
{
17
18
// This value is used in 'finishFunction' to mark the function that spans to the end of the whole code block
19
inline constexpr uint32_t kFullBlockFunction = ~0u;
20
21
class UnwindBuilder
22
{
23
public:
24
enum Arch
25
{
26
X64,
27
A64
28
};
29
30
virtual ~UnwindBuilder() = default;
31
32
virtual void setBeginOffset(size_t beginOffset) = 0;
33
virtual size_t getBeginOffset() const = 0;
34
35
virtual void startInfo(Arch arch) = 0;
36
virtual void startFunction() = 0;
37
virtual void finishFunction(uint32_t beginOffset, uint32_t endOffset) = 0;
38
virtual void finishInfo() = 0;
39
40
// A64-specific; prologue must look like this:
41
// sub sp, sp, stackSize
42
// store sequence that saves regs to [sp..sp+regs.size*8) in the order specified in regs; regs should start with x29, x30 (fp, lr)
43
// mov x29, sp
44
virtual void prologueA64(uint32_t prologueSize, uint32_t stackSize, std::initializer_list<A64::RegisterA64> regs) = 0;
45
46
// X64-specific; prologue must look like this:
47
// optional, indicated by setupFrame:
48
// push rbp
49
// mov rbp, rsp
50
// push reg in the order specified in regs
51
// sub rsp, stackSize
52
virtual void prologueX64(
53
uint32_t prologueSize,
54
uint32_t stackSize,
55
bool setupFrame,
56
std::initializer_list<X64::RegisterX64> gpr,
57
const std::vector<X64::RegisterX64>& simd
58
) = 0;
59
60
virtual size_t getUnwindInfoSize(size_t blockSize) const = 0;
61
62
// This will place the unwinding data at the target address and might update values of some fields
63
virtual size_t finalize(char* target, size_t offset, void* funcAddress, size_t blockSize) const = 0;
64
};
65
66
} // namespace CodeGen
67
} // namespace Luau
68
69