-
Notifications
You must be signed in to change notification settings - Fork 0
/
classify.cpp
129 lines (103 loc) · 1.78 KB
/
classify.cpp
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
126
127
128
129
// assume dp address mode. These are for temporary register lifetime analysis.
#include "Machine.h"
#include "OpCode.h"
#include "common.h"
bool instruction_rmw(Mnemonic m) {
switch(m)
{
case ASL:
case DEC:
case INC:
case LSR:
case ROL:
case ROR:
case TRB:
case TSB:
return true;
default:
return false;
}
}
bool instruction_read(Mnemonic m)
{
switch(m)
{
case ADC:
case AND:
case BIT:
case CMP:
case CPX:
case CPY:
case EOR:
case LDA:
case LDX:
case LDY:
case ORA:
case SBC:
case PEI:
return true;
default:
return instruction_rmw(m);
}
}
bool instruction_write(Mnemonic m) {
switch(m)
{
case STA:
case STX:
case STY:
case STZ:
return true;
default:
return instruction_rmw(m);
}
}
// todo -- database for all instructions/modes -- reads_a/x/y/, writes_a/x/y/s/etc, memory, individual flags
// todo -- STA [dp] is actually a (long) read. Need to take an opcode and check the mode.
#if 0
unsigned classify(Mnemonic m) {
if (instruction_rmw(m)) return reg_rw;
if (instruction_read(m)) return reg_read;
if (instruction_write(m)) return reg_write;
return reg_none;
}
unsigned classify(OpCode op) {
AddressMode mode = op.addressMode();
// [dp] and [dp],y are always long reads, from this perspective.
if (mode == zp_indirect_long || mode == zp_indirect_long_y)
return reg_read_long;
switch (op.mnemonic()) {
case ASL:
case DEC:
case INC:
case LSR:
case ROL:
case ROR:
case TRB:
case TSB:
return reg_rw;
case ADC:
case AND:
case BIT:
case CMP:
case CPX:
case CPY:
case EOR:
case LDA:
case LDX:
case LDY:
case ORA:
case SBC:
case PEI:
return reg_read;
case STA:
case STX:
case STY:
case STZ:
// write.
return reg_write;
default:
return reg_none;
}
}
#endif