format: Drop fd_strplcpy

This commit is contained in:
Alexis Engelke
2022-11-25 14:58:58 +01:00
parent 6facb5f08c
commit 0e0b03f839

View File

@@ -28,15 +28,6 @@ struct FdStr {
#define fd_stre(s) ((struct FdStr) { (s "\0\0\0\0\0\0\0\0\0\0"), sizeof (s)-1 }) #define fd_stre(s) ((struct FdStr) { (s "\0\0\0\0\0\0\0\0\0\0"), sizeof (s)-1 })
static char*
fd_strplcpy(char* restrict dst, const char* src, size_t size) {
while (*src && size > 1)
*dst++ = *src++, size--;
if (size)
*dst = 0;
return dst;
}
static char* static char*
fd_strpcat(char* restrict dst, struct FdStr src) { fd_strpcat(char* restrict dst, struct FdStr src) {
#ifdef __GNUC__ #ifdef __GNUC__
@@ -424,29 +415,27 @@ fd_format_impl(char buf[DECLARE_RESTRICTED_ARRAY_SIZE(128)], const FdInstr* inst
size_t immediate = FD_OP_IMM(instr, i); size_t immediate = FD_OP_IMM(instr, i);
// Some instructions have actually two immediate operands which are // Some instructions have actually two immediate operands which are
// decoded as a single operand. Split them here appropriately. // decoded as a single operand. Split them here appropriately.
size_t splitimm = 0;
const char* splitsep = ", ";
switch (FD_TYPE(instr)) { switch (FD_TYPE(instr)) {
default: default:
goto nosplitimm; goto nosplitimm;
case FDI_SSE_EXTRQ: case FDI_SSE_EXTRQ:
case FDI_SSE_INSERTQ: case FDI_SSE_INSERTQ:
splitimm = immediate & 0xff; buf = fd_strpcatnum(buf, immediate & 0xff);
buf = fd_strpcat(buf, fd_stre(", "));
immediate = (immediate >> 8) & 0xff; immediate = (immediate >> 8) & 0xff;
break; break;
case FDI_ENTER: case FDI_ENTER:
splitimm = immediate & 0xffff; buf = fd_strpcatnum(buf, immediate & 0xffff);
buf = fd_strpcat(buf, fd_stre(", "));
immediate = (immediate >> 16) & 0xff; immediate = (immediate >> 16) & 0xff;
break; break;
case FDI_JMPF: case FDI_JMPF:
case FDI_CALLF: case FDI_CALLF:
splitsep = ":"; buf = fd_strpcatnum(buf, (immediate >> (8 << size)) & 0xffff);
splitimm = (immediate >> (8 << size)) & 0xffff; *buf++ = ':';
// immediate is masked below. // immediate is masked below.
break; break;
} }
buf = fd_strpcatnum(buf, splitimm);
buf = fd_strplcpy(buf, splitsep, 4);
nosplitimm: nosplitimm:
if (op_type == FD_OT_OFF) if (op_type == FD_OT_OFF)