opcodes: Switch from std::map to std::array
Optimization.
This commit is contained in:
parent
d0b45f6150
commit
c59a127e86
1 changed files with 9 additions and 12 deletions
|
@ -4,7 +4,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <map>
|
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
@ -44,34 +43,32 @@ constexpr Type NZCV = Type::NZCVFlags;
|
||||||
constexpr Type Cond = Type::Cond;
|
constexpr Type Cond = Type::Cond;
|
||||||
constexpr Type Table = Type::Table;
|
constexpr Type Table = Type::Table;
|
||||||
|
|
||||||
static const std::map<Opcode, Meta> opcode_info {{
|
static const std::array opcode_info {
|
||||||
#define OPCODE(name, type, ...) { Opcode::name, { #name, type, { __VA_ARGS__ } } },
|
#define OPCODE(name, type, ...) Meta{#name, type, {__VA_ARGS__}},
|
||||||
#define A32OPC(name, type, ...) { Opcode::A32##name, { #name, type, { __VA_ARGS__ } } },
|
#define A32OPC(name, type, ...) Meta{#name, type, {__VA_ARGS__}},
|
||||||
#define A64OPC(name, type, ...) { Opcode::A64##name, { #name, type, { __VA_ARGS__ } } },
|
#define A64OPC(name, type, ...) Meta{#name, type, {__VA_ARGS__}},
|
||||||
#include "opcodes.inc"
|
#include "opcodes.inc"
|
||||||
#undef OPCODE
|
#undef OPCODE
|
||||||
#undef A32OPC
|
#undef A32OPC
|
||||||
#undef A64OPC
|
#undef A64OPC
|
||||||
}};
|
};
|
||||||
|
|
||||||
} // namespace OpcodeInfo
|
} // namespace OpcodeInfo
|
||||||
|
|
||||||
Type GetTypeOf(Opcode op) {
|
Type GetTypeOf(Opcode op) {
|
||||||
return OpcodeInfo::opcode_info.at(op).type;
|
return OpcodeInfo::opcode_info.at(static_cast<size_t>(op)).type;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t GetNumArgsOf(Opcode op) {
|
size_t GetNumArgsOf(Opcode op) {
|
||||||
return OpcodeInfo::opcode_info.at(op).arg_types.size();
|
return OpcodeInfo::opcode_info.at(static_cast<size_t>(op)).arg_types.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
Type GetArgTypeOf(Opcode op, size_t arg_index) {
|
Type GetArgTypeOf(Opcode op, size_t arg_index) {
|
||||||
return OpcodeInfo::opcode_info.at(op).arg_types.at(arg_index);
|
return OpcodeInfo::opcode_info.at(static_cast<size_t>(op)).arg_types.at(arg_index);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string GetNameOf(Opcode op) {
|
std::string GetNameOf(Opcode op) {
|
||||||
if (OpcodeInfo::opcode_info.count(op) == 0)
|
return OpcodeInfo::opcode_info.at(static_cast<size_t>(op)).name;
|
||||||
return fmt::format("Unknown Opcode {}", static_cast<Opcode>(op));
|
|
||||||
return OpcodeInfo::opcode_info.at(op).name;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ostream& operator<<(std::ostream& o, Opcode opcode) {
|
std::ostream& operator<<(std::ostream& o, Opcode opcode) {
|
||||||
|
|
Loading…
Reference in a new issue