-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinst.hpp
69 lines (56 loc) · 1.37 KB
/
inst.hpp
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
/*
* Copyright (c) 2020 Romain Dolbeau <[email protected]>
* MIT License
* See the LICENSE file at the top level of this software distribution for details.
*/
#ifndef __INST_HPP__
#define __INST_HPP__
#include <string>
#include <set>
class instruction {
public:
const std::string name;
const std::string opname;
const std::string key;
const std::string group;
std::set<std::string> extensions;
public:
instruction(std::string n,
std::string o,
std::string k,
std::string g
) : name(n), opname(o), key(k), group(g) {
}
void addExt(std::string e) {
extensions.insert(e);
}
bool operator ==(const instruction &b) const {
return name.compare(b.name) == 0;
}
bool match(const std::string toadd) const {
if (toadd.compare(name) == 0)
return true;
for (const std::string extension : extensions)
if (toadd.compare(extension) == 0)
return true;
return false;
}
bool isWord(void) const {
return name[name.length()-1] == 'W';
}
bool isImm(void) const {
int indice = name.length()-1;
if (isWord())
indice --;
while ((indice > 0) && (name[indice] >= '0') && (name[indice] <= '9'))
indice --;
return name[indice] == 'I';
}
std::string ctrlName() const {
return "CTRL_" + group + "_" + opname;
}
std::string keyName() const {
return name + "_KEY";
}
};
#endif // __INST_HPP__