ppu_iname: refactor to use actual strings

This commit is contained in:
Nekotekina 2020-03-26 15:26:49 +03:00
parent 8d1a9dce91
commit fa29c5aa94
3 changed files with 3 additions and 32 deletions

View File

@ -36,19 +36,6 @@ void fmt_class_string<bs_t<ppu_attr>>::format(std::string& out, u64 arg)
format_bitset(out, arg, "[", ",", "]", &fmt_class_string<ppu_attr>::format); format_bitset(out, arg, "[", ",", "]", &fmt_class_string<ppu_attr>::format);
} }
template <>
void fmt_class_string<ppu_iname::type>::format(std::string& out, u64 arg)
{
// Decode instruction name from the enum value
for (u32 i = 0; i < 10; i++)
{
if (u64 value = (arg >> (54 - i * 6)) & 0x3f)
{
out += static_cast<char>(value + 0x20);
}
}
}
void ppu_module::validate(u32 reloc) void ppu_module::validate(u32 reloc)
{ {
// Load custom PRX configuration if available // Load custom PRX configuration if available

View File

@ -554,18 +554,9 @@ struct ppu_itype
} }
}; };
// Encode instruction name: 6 bits per character (0x20..0x5f), max 10
static constexpr u64 ppu_iname_encode(const char* ptr, u64 value = 0)
{
return *ptr == '\0' ? value : ppu_iname_encode(ptr + 1, (*ptr - 0x20) | (value << 6));
}
struct ppu_iname struct ppu_iname
{ {
#define NAME(x) x = ppu_iname_encode(#x), #define NAME(x) static constexpr const char& x = *#x;
enum type : u64
{
NAME(UNK) NAME(UNK)
NAME(MFVSCR) NAME(MFVSCR)
NAME(MTVSCR) NAME(MTVSCR)
@ -946,15 +937,7 @@ struct ppu_iname
NAME(FCTID) NAME(FCTID)
NAME(FCTIDZ) NAME(FCTIDZ)
NAME(FCFID) NAME(FCFID)
};
#undef NAME #undef NAME
// Enable address-of operator for ppu_decoder<>
friend constexpr type operator &(type value)
{
return value;
}
}; };
// PPU Analyser Context // PPU Analyser Context

View File

@ -10,6 +10,7 @@
using namespace llvm; using namespace llvm;
constexpr ppu_decoder<PPUTranslator> s_ppu_decoder; constexpr ppu_decoder<PPUTranslator> s_ppu_decoder;
constexpr ppu_decoder<ppu_iname> s_ppu_iname;
PPUTranslator::PPUTranslator(LLVMContext& context, Module* module, const ppu_module& info, ExecutionEngine& engine) PPUTranslator::PPUTranslator(LLVMContext& context, Module* module, const ppu_module& info, ExecutionEngine& engine)
: cpu_translator(module, false) : cpu_translator(module, false)
@ -200,7 +201,7 @@ Function* PPUTranslator::Translate(const ppu_function& info)
if (m_rel) if (m_rel)
{ {
// This is very bad. m_rel is normally set to nullptr after a relocation is handled (so it wasn't) // This is very bad. m_rel is normally set to nullptr after a relocation is handled (so it wasn't)
ppu_log.error("LLVM: [0x%x] Unsupported relocation(%u) in '%s' (opcode=0x%x). Please report.", rel_found->first, m_rel->type, m_info.name, op); ppu_log.error("LLVM: [0x%x] Unsupported relocation(%u) in '%s' (opcode=0x%x '%s'). Please report.", rel_found->first, m_rel->type, m_info.name, op, s_ppu_iname.decode(op));
return nullptr; return nullptr;
} }
} }