-
Notifications
You must be signed in to change notification settings - Fork 14
/
regusage.h
121 lines (116 loc) · 5.39 KB
/
regusage.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
enum RegisterAccess {
RA_NONE = 0,
RA_READ = 1 << 0,
RA_WRITE = 1 << 1,
RA_READWRITE = 1 << 2,
};
#pragma(pack(push, 1))
struct regaccess_info {
/* enum RegisterAccess */ unsigned char ra_reg1;
/* enum RegisterAccess */ unsigned char ra_reg2;
/* enum RegisterAccess */ unsigned char ra_mar;
/* enum RegisterAccess */ unsigned char ra_sp;
};
#pragma(pack(pop))
static const struct regaccess_info regaccess_info[] = {
[0] = {RA_NONE, RA_NONE, RA_NONE, RA_NONE},
[SCMD_ADD] = {RA_READWRITE, RA_NONE, RA_NONE, RA_NONE},
[SCMD_SUB] = {RA_READWRITE, RA_NONE, RA_NONE, RA_NONE},
[SCMD_REGTOREG] = {RA_READ, RA_WRITE, RA_NONE, RA_NONE},
[SCMD_WRITELIT] = {RA_NONE, RA_NONE, RA_READ, RA_NONE},
[SCMD_RET] = {RA_NONE, RA_NONE, RA_NONE, RA_READWRITE},
[SCMD_LITTOREG] = {RA_WRITE, RA_NONE, RA_NONE, RA_NONE},
[SCMD_MEMREAD] = {RA_WRITE, RA_NONE, RA_READ, RA_NONE},
[SCMD_MEMWRITE] = {RA_READ, RA_NONE, RA_READ, RA_NONE},
[SCMD_MULREG] = {RA_READWRITE, RA_READ, RA_NONE, RA_NONE},
[SCMD_DIVREG] = {RA_READWRITE, RA_READ, RA_NONE, RA_NONE},
[SCMD_ADDREG] = {RA_READWRITE, RA_READ, RA_NONE, RA_NONE},
[SCMD_SUBREG] = {RA_READWRITE, RA_READ, RA_NONE, RA_NONE},
[SCMD_BITAND] = {RA_READWRITE, RA_READ, RA_NONE, RA_NONE},
[SCMD_BITOR] = {RA_READWRITE, RA_READ, RA_NONE, RA_NONE},
[SCMD_ISEQUAL] = {RA_READWRITE, RA_READ, RA_NONE, RA_NONE},
[SCMD_NOTEQUAL] = {RA_READWRITE, RA_READ, RA_NONE, RA_NONE},
[SCMD_GREATER] = {RA_READWRITE, RA_READ, RA_NONE, RA_NONE},
[SCMD_LESSTHAN] = {RA_READWRITE, RA_READ, RA_NONE, RA_NONE},
[SCMD_GTE] = {RA_READWRITE, RA_READ, RA_NONE, RA_NONE},
[SCMD_LTE] = {RA_READWRITE, RA_READ, RA_NONE, RA_NONE},
[SCMD_AND] = {RA_READWRITE, RA_READ, RA_NONE, RA_NONE}, /*logical*/
[SCMD_OR] = {RA_READWRITE, RA_READ, RA_NONE, RA_NONE},
[SCMD_CALL] = {RA_READ, RA_NONE, RA_NONE, RA_READWRITE},
[SCMD_MEMREADB] = {RA_WRITE, RA_NONE, RA_READ, RA_NONE},
[SCMD_MEMREADW] = {RA_WRITE, RA_NONE, RA_READ, RA_NONE},
[SCMD_MEMWRITEB] = {RA_READ, RA_NONE, RA_READ, RA_NONE},
[SCMD_MEMWRITEW] = {RA_READ, RA_NONE, RA_READ, RA_NONE},
[SCMD_JZ] = {RA_NONE, RA_NONE, RA_NONE, RA_NONE},
[SCMD_PUSHREG] = {RA_READ, RA_NONE, RA_NONE, RA_READWRITE},
[SCMD_POPREG] = {RA_WRITE, RA_NONE, RA_NONE, RA_READWRITE},
[SCMD_JMP] = {RA_NONE, RA_NONE, RA_NONE, RA_NONE},
[SCMD_MUL] = {RA_READWRITE, RA_NONE, RA_NONE, RA_NONE},
[SCMD_CALLEXT] = {RA_READ, RA_NONE, RA_NONE, RA_NONE},
[SCMD_PUSHREAL] = {RA_READ, RA_NONE, RA_NONE, RA_NONE},
[SCMD_SUBREALSTACK] = {RA_READ, RA_NONE, RA_NONE, RA_NONE},
[SCMD_LINENUM] = {RA_NONE, RA_NONE, RA_NONE, RA_NONE},
[SCMD_CALLAS] = {RA_READ, RA_NONE, RA_NONE, RA_NONE},
[SCMD_THISBASE] = {RA_NONE, RA_NONE, RA_NONE, RA_NONE},
[SCMD_NUMFUNCARGS] = {RA_NONE, RA_NONE, RA_NONE, RA_NONE},
[SCMD_MODREG] = {RA_READWRITE, RA_READ, RA_NONE, RA_NONE},
[SCMD_XORREG] = {RA_READWRITE, RA_READ, RA_NONE, RA_NONE},
[SCMD_NOTREG] = {RA_READWRITE, RA_READ, RA_NONE, RA_NONE},
[SCMD_SHIFTLEFT] = {RA_READWRITE, RA_READ, RA_NONE, RA_NONE},
[SCMD_SHIFTRIGHT] = {RA_READWRITE, RA_READ, RA_NONE, RA_NONE},
[SCMD_CALLOBJ] = {RA_READ, RA_NONE, RA_NONE, RA_NONE},
[SCMD_CHECKBOUNDS] = {RA_READ, RA_NONE, RA_NONE, RA_NONE},
[SCMD_MEMWRITEPTR] = {RA_NONE, RA_NONE, RA_NONE, RA_NONE}, //TODO
[SCMD_MEMREADPTR] = {RA_NONE, RA_NONE, RA_NONE, RA_NONE}, //TODO
[SCMD_MEMZEROPTR] = {RA_NONE, RA_NONE, RA_NONE, RA_NONE},
[SCMD_MEMINITPTR] = {RA_NONE, RA_NONE, RA_NONE, RA_NONE}, //TODO
[SCMD_LOADSPOFFS] = {RA_NONE, RA_NONE, RA_WRITE, RA_NONE},
[SCMD_CHECKNULL] = {RA_NONE, RA_NONE, RA_NONE, RA_NONE},
[SCMD_FADD] = {RA_READWRITE, RA_NONE, RA_NONE, RA_NONE},
[SCMD_FSUB] = {RA_READWRITE, RA_NONE, RA_NONE, RA_NONE},
[SCMD_FMULREG] = {RA_READWRITE, RA_READ, RA_NONE, RA_NONE},
[SCMD_FDIVREG] = {RA_READWRITE, RA_READ, RA_NONE, RA_NONE},
[SCMD_FADDREG] = {RA_READWRITE, RA_READ, RA_NONE, RA_NONE},
[SCMD_FSUBREG] = {RA_READWRITE, RA_READ, RA_NONE, RA_NONE},
[SCMD_FGREATER] = {RA_READWRITE, RA_READ, RA_NONE, RA_NONE},
[SCMD_FLESSTHAN] = {RA_READWRITE, RA_READ, RA_NONE, RA_NONE},
[SCMD_FGTE] = {RA_READWRITE, RA_READ, RA_NONE, RA_NONE},
[SCMD_FLTE] = {RA_READWRITE, RA_READ, RA_NONE, RA_NONE},
[SCMD_ZEROMEMORY] = {RA_NONE, RA_NONE, RA_READ, RA_NONE},
[SCMD_CREATESTRING] = {RA_NONE, RA_NONE, RA_NONE, RA_NONE}, //TODO
[SCMD_STRINGSEQUAL] = {RA_READWRITE, RA_READ, RA_NONE, RA_NONE},
[SCMD_STRINGSNOTEQ] = {RA_READWRITE, RA_READ, RA_NONE, RA_NONE},
[SCMD_CHECKNULLREG] = {RA_NONE, RA_NONE, RA_NONE, RA_NONE}, //TODO
[SCMD_LOOPCHECKOFF] = {RA_NONE, RA_NONE, RA_NONE, RA_NONE},
[SCMD_MEMZEROPTRND] = {RA_NONE, RA_NONE, RA_READ, RA_NONE},
[SCMD_JNZ] = {RA_NONE, RA_NONE, RA_NONE, RA_NONE},
[SCMD_DYNAMICBOUNDS] = {RA_NONE, RA_NONE, RA_NONE, RA_NONE}, //TODO
[SCMD_NEWARRAY] = {RA_NONE, RA_NONE, RA_NONE, RA_NONE}, //TODO
};
enum RegisterUsage {
RU_NONE = 0,
RU_READ = 1 << 0,
RU_WRITE = 1 << 1,
RU_WRITE_AFTER_READ = 1 << 2,
};
static enum RegisterUsage get_reg_usage(int regno, enum RegisterUsage old, enum RegisterAccess ra) {
enum RegisterUsage ru = old;
switch(ra) {
case RA_READ:
if(ru == RU_NONE || ru == RU_READ) ru = RU_READ;
else if(ru == RU_WRITE);
else if(ru == RU_WRITE_AFTER_READ);
break;
case RA_WRITE:
if(ru == RU_NONE || ru == RU_WRITE) ru = RU_WRITE;
else if(ru == RU_READ) ru = RU_WRITE_AFTER_READ;
else if(ru == RU_WRITE_AFTER_READ);
break;
case RA_READWRITE:
if(ru == RU_NONE || ru == RU_READ) ru = RU_WRITE_AFTER_READ;
else if(ru == RU_WRITE);
else if(ru == RU_WRITE_AFTER_READ);
break;
}
return ru;
}