Common/GekkoDisassembler: Use std::string_view where applicable
Avoids the use of the null pointer to represent an empty string. Instead, we can simply pass an empty string_view instance. Using std::string_view enforces this invariant at the API level.
This commit is contained in:
parent
d8c3f09c9f
commit
188234b4cd
|
@ -515,7 +515,7 @@ void GekkoDisassembler::cmpi(u32 in, int uimm)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GekkoDisassembler::addi(u32 in, const std::string& ext)
|
void GekkoDisassembler::addi(u32 in, std::string_view ext)
|
||||||
{
|
{
|
||||||
if ((in & 0x08000000) && !PPCGETA(in))
|
if ((in & 0x08000000) && !PPCGETA(in))
|
||||||
{
|
{
|
||||||
|
@ -539,7 +539,7 @@ void GekkoDisassembler::addi(u32 in, const std::string& ext)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build a branch instr. and return number of chars written to operand.
|
// Build a branch instr. and return number of chars written to operand.
|
||||||
size_t GekkoDisassembler::branch(u32 in, const char* bname, int aform, int bdisp)
|
size_t GekkoDisassembler::branch(u32 in, std::string_view bname, int aform, int bdisp)
|
||||||
{
|
{
|
||||||
int bo = (int)PPCGETD(in);
|
int bo = (int)PPCGETD(in);
|
||||||
int bi = (int)PPCGETA(in);
|
int bi = (int)PPCGETA(in);
|
||||||
|
@ -639,7 +639,7 @@ void GekkoDisassembler::mcrf(u32 in, char c)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GekkoDisassembler::crop(u32 in, const char* n1, const char* n2)
|
void GekkoDisassembler::crop(u32 in, std::string_view n1, std::string_view n2)
|
||||||
{
|
{
|
||||||
int crd = (int)PPCGETD(in);
|
int crd = (int)PPCGETD(in);
|
||||||
int cra = (int)PPCGETA(in);
|
int cra = (int)PPCGETA(in);
|
||||||
|
@ -647,8 +647,8 @@ void GekkoDisassembler::crop(u32 in, const char* n1, const char* n2)
|
||||||
|
|
||||||
if ((in & 1) == 0)
|
if ((in & 1) == 0)
|
||||||
{
|
{
|
||||||
m_opcode = fmt::format("cr{}", (cra == crb && n2) ? n2 : n1);
|
m_opcode = fmt::format("cr{}", (cra == crb && !n2.empty()) ? n2 : n1);
|
||||||
if (cra == crb && n2)
|
if (cra == crb && !n2.empty())
|
||||||
m_operands = fmt::format("{}, {}", crd, cra);
|
m_operands = fmt::format("{}, {}", crd, cra);
|
||||||
else
|
else
|
||||||
m_operands = fmt::format("{}, {}, {}", crd, cra, crb);
|
m_operands = fmt::format("{}, {}, {}", crd, cra, crb);
|
||||||
|
@ -659,7 +659,7 @@ void GekkoDisassembler::crop(u32 in, const char* n1, const char* n2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GekkoDisassembler::nooper(u32 in, const char* name, unsigned char dmode)
|
void GekkoDisassembler::nooper(u32 in, std::string_view name, unsigned char dmode)
|
||||||
{
|
{
|
||||||
if (in & (PPCDMASK | PPCAMASK | PPCBMASK | 1))
|
if (in & (PPCDMASK | PPCAMASK | PPCBMASK | 1))
|
||||||
{
|
{
|
||||||
|
@ -672,7 +672,7 @@ void GekkoDisassembler::nooper(u32 in, const char* name, unsigned char dmode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GekkoDisassembler::rlw(u32 in, const char* name, int i)
|
void GekkoDisassembler::rlw(u32 in, std::string_view name, int i)
|
||||||
{
|
{
|
||||||
int s = (int)PPCGETD(in);
|
int s = (int)PPCGETD(in);
|
||||||
int a = (int)PPCGETA(in);
|
int a = (int)PPCGETA(in);
|
||||||
|
@ -685,13 +685,13 @@ void GekkoDisassembler::rlw(u32 in, const char* name, int i)
|
||||||
bsh, mb, me, HelperRotateMask(bsh, mb, me));
|
bsh, mb, me, HelperRotateMask(bsh, mb, me));
|
||||||
}
|
}
|
||||||
|
|
||||||
void GekkoDisassembler::ori(u32 in, const char* name)
|
void GekkoDisassembler::ori(u32 in, std::string_view name)
|
||||||
{
|
{
|
||||||
m_opcode = name;
|
m_opcode = name;
|
||||||
m_operands = imm(in, 1, 1, true);
|
m_operands = imm(in, 1, 1, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GekkoDisassembler::rld(u32 in, const char* name, int i)
|
void GekkoDisassembler::rld(u32 in, std::string_view name, int i)
|
||||||
{
|
{
|
||||||
int s = (int)PPCGETD(in);
|
int s = (int)PPCGETD(in);
|
||||||
int a = (int)PPCGETA(in);
|
int a = (int)PPCGETA(in);
|
||||||
|
@ -760,8 +760,8 @@ void GekkoDisassembler::trap(u32 in, unsigned char dmode)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Standard instruction: xxxx rD,rA,rB
|
// Standard instruction: xxxx rD,rA,rB
|
||||||
void GekkoDisassembler::dab(u32 in, const char* name, int mask, int smode, int chkoe, int chkrc,
|
void GekkoDisassembler::dab(u32 in, std::string_view name, int mask, int smode, int chkoe,
|
||||||
unsigned char dmode)
|
int chkrc, unsigned char dmode)
|
||||||
{
|
{
|
||||||
if (chkrc >= 0 && ((in & 1) != (unsigned int)chkrc))
|
if (chkrc >= 0 && ((in & 1) != (unsigned int)chkrc))
|
||||||
{
|
{
|
||||||
|
@ -782,7 +782,7 @@ void GekkoDisassembler::dab(u32 in, const char* name, int mask, int smode, int c
|
||||||
}
|
}
|
||||||
|
|
||||||
// Last operand is no register: xxxx rD,rA,NB
|
// Last operand is no register: xxxx rD,rA,NB
|
||||||
void GekkoDisassembler::rrn(u32 in, const char* name, int smode, int chkoe, int chkrc,
|
void GekkoDisassembler::rrn(u32 in, std::string_view name, int smode, int chkoe, int chkrc,
|
||||||
unsigned char dmode)
|
unsigned char dmode)
|
||||||
{
|
{
|
||||||
if (chkrc >= 0 && ((in & 1) != (unsigned int)chkrc))
|
if (chkrc >= 0 && ((in & 1) != (unsigned int)chkrc))
|
||||||
|
@ -943,7 +943,7 @@ void GekkoDisassembler::sradi(u32 in)
|
||||||
m_operands = fmt::format("{}, {}, {}", regnames[a], regnames[s], bsh);
|
m_operands = fmt::format("{}, {}, {}", regnames[a], regnames[s], bsh);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GekkoDisassembler::ldst(u32 in, const char* name, char reg, unsigned char dmode)
|
void GekkoDisassembler::ldst(u32 in, std::string_view name, char reg, unsigned char dmode)
|
||||||
{
|
{
|
||||||
int s = (int)PPCGETD(in);
|
int s = (int)PPCGETD(in);
|
||||||
int a = (int)PPCGETA(in);
|
int a = (int)PPCGETA(in);
|
||||||
|
@ -968,7 +968,7 @@ void GekkoDisassembler::ldst(u32 in, const char* name, char reg, unsigned char d
|
||||||
}
|
}
|
||||||
|
|
||||||
// Standard floating point instruction: xxxx fD,fA,fC,fB
|
// Standard floating point instruction: xxxx fD,fA,fC,fB
|
||||||
void GekkoDisassembler::fdabc(u32 in, const char* name, int mask, unsigned char dmode)
|
void GekkoDisassembler::fdabc(u32 in, std::string_view name, int mask, unsigned char dmode)
|
||||||
{
|
{
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
|
@ -1005,7 +1005,7 @@ void GekkoDisassembler::fmr(u32 in)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Indexed float instruction: xxxx fD,rA,rB
|
// Indexed float instruction: xxxx fD,rA,rB
|
||||||
void GekkoDisassembler::fdab(u32 in, const char* name, int mask)
|
void GekkoDisassembler::fdab(u32 in, std::string_view name, int mask)
|
||||||
{
|
{
|
||||||
m_opcode = name;
|
m_opcode = name;
|
||||||
m_operands = fd_ra_rb(in, mask);
|
m_operands = fd_ra_rb(in, mask);
|
||||||
|
@ -1390,7 +1390,7 @@ u32* GekkoDisassembler::DoDisassembly(bool big_endian)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 129:
|
case 129:
|
||||||
crop(in, "andc", nullptr); // crandc
|
crop(in, "andc", {}); // crandc
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 150:
|
case 150:
|
||||||
|
@ -1402,11 +1402,11 @@ u32* GekkoDisassembler::DoDisassembly(bool big_endian)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 225:
|
case 225:
|
||||||
crop(in, "nand", nullptr); // crnand
|
crop(in, "nand", {}); // crnand
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 257:
|
case 257:
|
||||||
crop(in, "and", nullptr); // crand
|
crop(in, "and", {}); // crand
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 289:
|
case 289:
|
||||||
|
@ -1414,7 +1414,7 @@ u32* GekkoDisassembler::DoDisassembly(bool big_endian)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 417:
|
case 417:
|
||||||
crop(in, "orc", nullptr); // crorc
|
crop(in, "orc", {}); // crorc
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 449:
|
case 449:
|
||||||
|
|
|
@ -34,11 +34,10 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <cstdint>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
#include "Common/CommonTypes.h"
|
#include "Common/CommonTypes.h"
|
||||||
#include "Common/StringUtil.h"
|
|
||||||
|
|
||||||
namespace Common
|
namespace Common
|
||||||
{
|
{
|
||||||
|
@ -62,30 +61,31 @@ private:
|
||||||
|
|
||||||
static void trapi(u32 in, unsigned char dmode);
|
static void trapi(u32 in, unsigned char dmode);
|
||||||
static void cmpi(u32 in, int uimm);
|
static void cmpi(u32 in, int uimm);
|
||||||
static void addi(u32 in, const std::string& ext);
|
static void addi(u32 in, std::string_view ext);
|
||||||
static size_t branch(u32 in, const char* bname, int aform, int bdisp);
|
static size_t branch(u32 in, std::string_view bname, int aform, int bdisp);
|
||||||
static void bc(u32 in);
|
static void bc(u32 in);
|
||||||
static void bli(u32 in);
|
static void bli(u32 in);
|
||||||
static void mcrf(u32 in, char c);
|
static void mcrf(u32 in, char c);
|
||||||
static void crop(u32 in, const char* n1, const char* n2);
|
static void crop(u32 in, std::string_view n1, std::string_view n2);
|
||||||
static void nooper(u32 in, const char* name, unsigned char dmode);
|
static void nooper(u32 in, std::string_view name, unsigned char dmode);
|
||||||
static void rlw(u32 in, const char* name, int i);
|
static void rlw(u32 in, std::string_view name, int i);
|
||||||
static void ori(u32 in, const char* name);
|
static void ori(u32 in, std::string_view name);
|
||||||
static void rld(u32 in, const char* name, int i);
|
static void rld(u32 in, std::string_view name, int i);
|
||||||
static void cmp(u32 in);
|
static void cmp(u32 in);
|
||||||
static void trap(u32 in, unsigned char dmode);
|
static void trap(u32 in, unsigned char dmode);
|
||||||
static void dab(u32 in, const char* name, int mask, int smode, int chkoe, int chkrc,
|
static void dab(u32 in, std::string_view name, int mask, int smode, int chkoe, int chkrc,
|
||||||
|
unsigned char dmode);
|
||||||
|
static void rrn(u32 in, std::string_view name, int smode, int chkoe, int chkrc,
|
||||||
unsigned char dmode);
|
unsigned char dmode);
|
||||||
static void rrn(u32 in, const char* name, int smode, int chkoe, int chkrc, unsigned char dmode);
|
|
||||||
static void mtcr(u32 in);
|
static void mtcr(u32 in);
|
||||||
static void msr(u32 in, int smode);
|
static void msr(u32 in, int smode);
|
||||||
static void mspr(u32 in, int smode);
|
static void mspr(u32 in, int smode);
|
||||||
static void mtb(u32 in);
|
static void mtb(u32 in);
|
||||||
static void sradi(u32 in);
|
static void sradi(u32 in);
|
||||||
static void ldst(u32 in, const char* name, char reg, unsigned char dmode);
|
static void ldst(u32 in, std::string_view name, char reg, unsigned char dmode);
|
||||||
static void fdabc(u32 in, const char* name, int mask, unsigned char dmode);
|
static void fdabc(u32 in, std::string_view name, int mask, unsigned char dmode);
|
||||||
static void fmr(u32 in);
|
static void fmr(u32 in);
|
||||||
static void fdab(u32 in, const char* name, int mask);
|
static void fdab(u32 in, std::string_view name, int mask);
|
||||||
static void fcmp(u32 in, char c);
|
static void fcmp(u32 in, char c);
|
||||||
static void mtfsb(u32 in, int n);
|
static void mtfsb(u32 in, int n);
|
||||||
static void ps(u32 inst);
|
static void ps(u32 inst);
|
||||||
|
|
Loading…
Reference in New Issue