Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Roblox
GitHub Repository: Roblox/luau
Path: blob/master/CodeGen/include/Luau/BytecodeSummary.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/CodeGenCommon.h"
5
#include "Luau/Bytecode.h"
6
7
#include <string>
8
#include <vector>
9
10
#include <stdint.h>
11
12
struct lua_State;
13
struct Proto;
14
15
namespace Luau
16
{
17
namespace CodeGen
18
{
19
20
class FunctionBytecodeSummary
21
{
22
public:
23
FunctionBytecodeSummary(std::string source, std::string name, const int line, unsigned nestingLimit);
24
25
const std::string& getSource() const
26
{
27
return source;
28
}
29
30
const std::string& getName() const
31
{
32
return name;
33
}
34
35
int getLine() const
36
{
37
return line;
38
}
39
40
const unsigned getNestingLimit() const
41
{
42
return nestingLimit;
43
}
44
45
const unsigned getOpLimit() const
46
{
47
return LOP__COUNT;
48
}
49
50
void incCount(unsigned nesting, uint8_t op)
51
{
52
CODEGEN_ASSERT(nesting <= getNestingLimit());
53
CODEGEN_ASSERT(op < getOpLimit());
54
++counts[nesting][op];
55
}
56
57
unsigned getCount(unsigned nesting, uint8_t op) const
58
{
59
CODEGEN_ASSERT(nesting <= getNestingLimit());
60
CODEGEN_ASSERT(op < getOpLimit());
61
return counts[nesting][op];
62
}
63
64
const std::vector<unsigned>& getCounts(unsigned nesting) const
65
{
66
CODEGEN_ASSERT(nesting <= getNestingLimit());
67
return counts[nesting];
68
}
69
70
static FunctionBytecodeSummary fromProto(Proto* proto, unsigned nestingLimit);
71
72
private:
73
std::string source;
74
std::string name;
75
int line;
76
unsigned nestingLimit;
77
std::vector<std::vector<unsigned>> counts;
78
};
79
80
std::vector<FunctionBytecodeSummary> summarizeBytecode(lua_State* L, int idx, unsigned nestingLimit);
81
82
} // namespace CodeGen
83
} // namespace Luau
84
85