-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJitUtils.h
84 lines (71 loc) · 2.92 KB
/
JitUtils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#pragma once
#include <cstdint>
#include <vector>
#include <string>
#include <type_traits>
#include <set>
#ifndef NDEBUG
#define ERROR(newState, ...) \
do \
{ \
printf("[file:%s,function:%s,line:%d]:", __FILE__, __FUNCTION__, __LINE__); \
printf(__VA_ARGS__); \
printf("\n"); \
InitModuleAndPassManager(); \
jitFnDecl.state = newState; \
return jitFnDecl; \
} while (false);
#else
#define ERROR(newState, ...) \
do \
{ \
InitModuleAndPassManager(); \
jitFnDecl.state = newState; \
return jitFnDecl; \
} while (false);
#endif
std::string GenerateUUID();
constexpr uint32_t JIT_TRIGGER_COUNT = 2;
constexpr uint8_t JIT_FUNCTION_MAX_PARAMETER_COUNT = 6;
constexpr const char *GLOBAL_VARIABLE_STR = "m_GlobalVariables";
constexpr const char *SET_GLOBAL_VARIABLE_FN_STR = "function_SetGlobalVariables";
constexpr const char *STACK_STR = "m_ValueStack";
constexpr const char *SET_STACK_FN_STR = "function_SetValueStack";
enum JumpMode
{
IF = 0,
WHILE = 1,
};
enum class JitCompileState
{
SUCCESS,
FAIL,
DEPEND,
};
struct JitFnDecl
{
JitFnDecl() = default;
~JitFnDecl() = default;
uint8_t returnType{0};
std::vector<uint8_t> paramTypes{};
JitCompileState state{JitCompileState::SUCCESS};
};
class TypeSet
{
public:
TypeSet() = default;
~TypeSet() = default;
void Insert(uint8_t type);
void Insert(const TypeSet *other);
bool IsOnly(uint8_t t);
uint8_t GetOnly();
bool IsMultiplyType();
bool IsNone();
size_t Hash();
private:
std::set<uint8_t> m_ValueTypeSet{};
};
struct Value;
size_t HashValueList(Value *start, Value *end);
std::string GenerateFunctionName(const std::string &uuid, size_t returnHash, size_t paramHash);
std::string GenerateLocalVarName(int16_t scopeDepth, int16_t index, int16_t isUpValue);