luau/CodeGen/include/Luau/UnwindBuilderWin.h

57 lines
1.3 KiB
C
Raw Normal View History

2022-09-16 06:13:58 +08:00
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
#pragma once
#include "Luau/RegisterX64.h"
#include "UnwindBuilder.h"
#include <vector>
namespace Luau
{
namespace CodeGen
{
// This struct matches the layout of UNWIND_CODE from ehdata.h
struct UnwindCodeWin
{
uint8_t offset;
uint8_t opcode : 4;
uint8_t opinfo : 4;
};
class UnwindBuilderWin : public UnwindBuilder
{
public:
2022-10-07 07:55:58 +08:00
void setBeginOffset(size_t beginOffset) override;
size_t getBeginOffset() const override;
2022-09-16 06:13:58 +08:00
void start() override;
2023-03-03 21:45:38 +08:00
void spill(int espOffset, X64::RegisterX64 reg) override;
void save(X64::RegisterX64 reg) override;
2022-09-16 06:13:58 +08:00
void allocStack(int size) override;
2023-03-03 21:45:38 +08:00
void setupFrameReg(X64::RegisterX64 reg, int espOffset) override;
2022-09-16 06:13:58 +08:00
void finish() override;
size_t getSize() const override;
void finalize(char* target, void* funcAddress, size_t funcSize) const override;
private:
2022-10-07 07:55:58 +08:00
size_t beginOffset = 0;
2022-09-16 06:13:58 +08:00
// Windows unwind codes are written in reverse, so we have to collect them all first
std::vector<UnwindCodeWin> unwindCodes;
uint8_t prologSize = 0;
2023-03-03 21:45:38 +08:00
X64::RegisterX64 frameReg = X64::rax; // rax means that frame register is not used
2022-09-16 06:13:58 +08:00
uint8_t frameRegOffset = 0;
uint32_t stackOffset = 0;
size_t infoSize = 0;
};
} // namespace CodeGen
} // namespace Luau