luau/CodeGen/include/Luau/BytecodeSummary.h

82 lines
1.7 KiB
C
Raw Normal View History

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
#include "Luau/Common.h"
#include "Luau/Bytecode.h"
#include <string>
#include <vector>
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)
{
LUAU_ASSERT(nesting <= getNestingLimit());
LUAU_ASSERT(op < getOpLimit());
++counts[nesting][op];
}
unsigned getCount(unsigned nesting, uint8_t op) const
{
LUAU_ASSERT(nesting <= getNestingLimit());
LUAU_ASSERT(op < getOpLimit());
return counts[nesting][op];
}
const std::vector<unsigned>& getCounts(unsigned nesting) const
{
LUAU_ASSERT(nesting <= getNestingLimit());
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