dynarmic/src/frontend/ir/opcodes.cpp

79 lines
1.9 KiB
C++
Raw Normal View History

2016-08-12 18:17:31 +01:00
/* This file is part of the dynarmic project.
* Copyright (c) 2016 MerryMage
2020-04-23 15:25:11 +01:00
* SPDX-License-Identifier: 0BSD
2016-08-12 18:17:31 +01:00
*/
2016-08-17 13:29:05 +01:00
#include <array>
2018-01-27 23:42:30 +00:00
#include <ostream>
#include <string>
2016-08-12 18:17:31 +01:00
#include <vector>
2018-01-27 23:42:30 +00:00
#include <fmt/format.h>
#include <fmt/ostream.h>
2016-08-12 18:17:31 +01:00
#include "frontend/ir/opcodes.h"
#include "frontend/ir/type.h"
2016-08-12 18:17:31 +01:00
namespace Dynarmic::IR {
2016-08-12 18:17:31 +01:00
// Opcode information
namespace OpcodeInfo {
struct Meta {
const char* name;
Type type;
std::vector<Type> arg_types;
};
constexpr Type Void = Type::Void;
constexpr Type A32Reg = Type::A32Reg;
constexpr Type A32ExtReg = Type::A32ExtReg;
constexpr Type A64Reg = Type::A64Reg;
constexpr Type A64Vec = Type::A64Vec;
constexpr Type Opaque = Type::Opaque;
constexpr Type U1 = Type::U1;
constexpr Type U8 = Type::U8;
constexpr Type U16 = Type::U16;
constexpr Type U32 = Type::U32;
constexpr Type U64 = Type::U64;
constexpr Type U128 = Type::U128;
constexpr Type CoprocInfo = Type::CoprocInfo;
constexpr Type NZCV = Type::NZCVFlags;
constexpr Type Cond = Type::Cond;
constexpr Type Table = Type::Table;
static const std::array opcode_info {
#define OPCODE(name, type, ...) Meta{#name, type, {__VA_ARGS__}},
#define A32OPC(name, type, ...) Meta{#name, type, {__VA_ARGS__}},
#define A64OPC(name, type, ...) Meta{#name, type, {__VA_ARGS__}},
2016-08-12 18:17:31 +01:00
#include "opcodes.inc"
#undef OPCODE
2018-01-01 16:19:43 +00:00
#undef A32OPC
2018-01-07 00:11:57 +00:00
#undef A64OPC
};
2016-08-12 18:17:31 +01:00
} // namespace OpcodeInfo
Type GetTypeOf(Opcode op) {
return OpcodeInfo::opcode_info.at(static_cast<size_t>(op)).type;
2016-08-12 18:17:31 +01:00
}
size_t GetNumArgsOf(Opcode op) {
return OpcodeInfo::opcode_info.at(static_cast<size_t>(op)).arg_types.size();
2016-08-12 18:17:31 +01:00
}
Type GetArgTypeOf(Opcode op, size_t arg_index) {
return OpcodeInfo::opcode_info.at(static_cast<size_t>(op)).arg_types.at(arg_index);
2016-08-12 18:17:31 +01:00
}
2018-01-27 23:42:30 +00:00
std::string GetNameOf(Opcode op) {
return OpcodeInfo::opcode_info.at(static_cast<size_t>(op)).name;
2016-08-12 18:17:31 +01:00
}
2018-01-27 23:42:30 +00:00
std::ostream& operator<<(std::ostream& o, Opcode opcode) {
return o << GetNameOf(opcode);
}
} // namespace Dynarmic::IR