-
Notifications
You must be signed in to change notification settings - Fork 0
/
classfile.h
125 lines (106 loc) · 2.73 KB
/
classfile.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#ifndef CLASSFILE_H
#define CLASSFILE_H
#include "globals.h"
enum class OpType
{
Store,
Cond,
Inc,
Jump,
IndexedStore,
Return,
Call,
};
struct Operation
{
OpType type;
struct
{
std::optional<std::string> type;
std::optional<int> size;
u4 position;
std::string arr_type;
int index;
std::optional<std::string> value;
std::vector<std::string> populate;
} store;
struct
{
std::string left;
std::string right;
u4 absolute;
std::string op;
} cond;
struct
{
int index;
int constant;
} inc;
struct
{
u4 absolute;
} jump;
struct
{
std::string array;
std::string index;
std::string value;
} istore;
struct
{
std::optional<std::string> value;
} ret;
struct
{
std::string code;
} call;
};
struct Array
{
size_t size;
std::string type;
size_t position;
std::vector<std::string> populate;
};
struct Object
{
std::string type;
std::string ctor;
};
using Value = std::variant<int32_t, int64_t, float, double, std::string, Array, Object>;
class ClassFile
{
public:
ClassFile(std::string filename, std::string projectName, bool partial = false);
bool hasBoard() const;
std::string boardName() const;
void generate(const std::vector<ClassFile> & files, Board board);
std::vector<Instruction> lineAnalyser(Buffer & buffer, const std::string & name, std::vector<std::tuple<u2, u2>> lineNumbers);
std::vector<Instruction> decodeBytecodeLine(Buffer & buffer, const std::string & name, u4 position);
std::string generateCodeFromOperation(Operation operation, u4 start_pc, bool & addOpeningParen);
u2 getLineFromOpcode(u2 opcode);
u2 getOpcodeFromLine(u2 line);
int findLocal(int index);
std::string getStringFromUtf8(int index);
std::vector<FunctionData> functions;
std::vector<FieldData> fields;
ConstantPool constantPool;
std::vector<std::string> callbacksMethods;
std::vector<std::unordered_map<u4, u4>> localsTypes;
std::vector<Instruction> insts;
std::unordered_map<u4, u4> closingBraces;
std::set<u4> skippedGotos;
std::multiset<u4> closingBrackets, elseStmts;
std::vector<Value> stack;
std::string board_name;
std::string fileName;
std::string filePath;
Buffer * fullBuffer = nullptr;
std::vector<std::tuple<u2, u2>> * lines = nullptr;
std::string project_name;
std::vector<std::string> rawCMake;
std::unordered_map<std::string, s4> gbConfig;
static inline std::vector<ClassFile> partialClasses;
std::vector<u1> getFunctionFlags(std::string name);
};
#endif // CLASSFILE_H