2023-11-18 02:15:31 +08:00
|
|
|
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
|
|
|
|
#pragma once
|
|
|
|
|
2024-02-16 09:25:31 +08:00
|
|
|
#include "Luau/CodeGenCommon.h"
|
2023-11-18 02:15:31 +08:00
|
|
|
#include "Luau/Bytecode.h"
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2023-12-02 10:04:44 +08:00
|
|
|
#include <stdint.h>
|
|
|
|
|
2023-11-18 02:15:31 +08:00
|
|
|
struct lua_State;
|
|
|
|
struct Proto;
|
|
|
|
|
|
|
|
namespace Luau
|
|
|
|
{
|
|
|
|
namespace CodeGen
|
|
|
|
{
|
|
|
|
|
|
|
|
class FunctionBytecodeSummary
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
FunctionBytecodeSummary(std::string source, std::string name, const int line, unsigned nestingLimit);
|
|
|
|
|
|
|
|
const std::string& getSource() const
|
|
|
|
{
|
|
|
|
return source;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string& getName() const
|
|
|
|
{
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
int getLine() const
|
|
|
|
{
|
|
|
|
return line;
|
|
|
|
}
|
|
|
|
|
|
|
|
const unsigned getNestingLimit() const
|
|
|
|
{
|
|
|
|
return nestingLimit;
|
|
|
|
}
|
|
|
|
|
|
|
|
const unsigned getOpLimit() const
|
|
|
|
{
|
|
|
|
return LOP__COUNT;
|
|
|
|
}
|
|
|
|
|
|
|
|
void incCount(unsigned nesting, uint8_t op)
|
|
|
|
{
|
2024-02-16 09:25:31 +08:00
|
|
|
CODEGEN_ASSERT(nesting <= getNestingLimit());
|
|
|
|
CODEGEN_ASSERT(op < getOpLimit());
|
2023-11-18 02:15:31 +08:00
|
|
|
++counts[nesting][op];
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned getCount(unsigned nesting, uint8_t op) const
|
|
|
|
{
|
2024-02-16 09:25:31 +08:00
|
|
|
CODEGEN_ASSERT(nesting <= getNestingLimit());
|
|
|
|
CODEGEN_ASSERT(op < getOpLimit());
|
2023-11-18 02:15:31 +08:00
|
|
|
return counts[nesting][op];
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::vector<unsigned>& getCounts(unsigned nesting) const
|
|
|
|
{
|
2024-02-16 09:25:31 +08:00
|
|
|
CODEGEN_ASSERT(nesting <= getNestingLimit());
|
2023-11-18 02:15:31 +08:00
|
|
|
return counts[nesting];
|
|
|
|
}
|
|
|
|
|
|
|
|
static FunctionBytecodeSummary fromProto(Proto* proto, unsigned nestingLimit);
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::string source;
|
|
|
|
std::string name;
|
|
|
|
int line;
|
|
|
|
unsigned nestingLimit;
|
|
|
|
std::vector<std::vector<unsigned>> counts;
|
|
|
|
};
|
|
|
|
|
|
|
|
std::vector<FunctionBytecodeSummary> summarizeBytecode(lua_State* L, int idx, unsigned nestingLimit);
|
|
|
|
|
|
|
|
} // namespace CodeGen
|
|
|
|
} // namespace Luau
|