Skip to content

Commit

Permalink
Remove printf positional argument requirements from disassembler
Browse files Browse the repository at this point in the history
Positional arguments to printf (eg. %1$s) are not allowed on Windows, so remove
uses of this in the disassembler, replacing them with an extension to the
existing NEONFormatDecoder class.

Patch prompted by Linaro#122
  • Loading branch information
mmc28a committed Jan 24, 2025
1 parent aca39bd commit a331691
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
21 changes: 10 additions & 11 deletions src/aarch64/disasm-aarch64.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2731,10 +2731,10 @@ void Disassembler::VisitNEONExtract(const Instruction *instr) {
void Disassembler::VisitNEONLoadStoreMultiStruct(const Instruction *instr) {
const char *mnemonic = NULL;
const char *form = NULL;
const char *form_1v = "{'Vt.%1$s}, ['Xns]";
const char *form_2v = "{'Vt.%1$s, 'Vt2.%1$s}, ['Xns]";
const char *form_3v = "{'Vt.%1$s, 'Vt2.%1$s, 'Vt3.%1$s}, ['Xns]";
const char *form_4v = "{'Vt.%1$s, 'Vt2.%1$s, 'Vt3.%1$s, 'Vt4.%1$s}, ['Xns]";
const char *form_1v = "{'Vt.%s}, ['Xns]";
const char *form_2v = "{'Vt.%s, 'Vt2.%s}, ['Xns]";
const char *form_3v = "{'Vt.%s, 'Vt2.%s, 'Vt3.%s}, ['Xns]";
const char *form_4v = "{'Vt.%s, 'Vt2.%s, 'Vt3.%s, 'Vt4.%s}, ['Xns]";
NEONFormatDecoder nfd(instr, NEONFormatDecoder::LoadStoreFormatMap());

switch (instr->Mask(NEONLoadStoreMultiStructMask)) {
Expand Down Expand Up @@ -2829,11 +2829,10 @@ void Disassembler::VisitNEONLoadStoreMultiStructPostIndex(
const Instruction *instr) {
const char *mnemonic = NULL;
const char *form = NULL;
const char *form_1v = "{'Vt.%1$s}, ['Xns], 'Xmr1";
const char *form_2v = "{'Vt.%1$s, 'Vt2.%1$s}, ['Xns], 'Xmr2";
const char *form_3v = "{'Vt.%1$s, 'Vt2.%1$s, 'Vt3.%1$s}, ['Xns], 'Xmr3";
const char *form_4v =
"{'Vt.%1$s, 'Vt2.%1$s, 'Vt3.%1$s, 'Vt4.%1$s}, ['Xns], 'Xmr4";
const char *form_1v = "{'Vt.%s}, ['Xns], 'Xmr1";
const char *form_2v = "{'Vt.%s, 'Vt2.%s}, ['Xns], 'Xmr2";
const char *form_3v = "{'Vt.%s, 'Vt2.%s, 'Vt3.%s}, ['Xns], 'Xmr3";
const char *form_4v = "{'Vt.%s, 'Vt2.%s, 'Vt3.%s, 'Vt4.%s}, ['Xns], 'Xmr4";
NEONFormatDecoder nfd(instr, NEONFormatDecoder::LoadStoreFormatMap());

switch (instr->Mask(NEONLoadStoreMultiStructPostIndexMask)) {
Expand Down Expand Up @@ -3036,7 +3035,7 @@ void Disassembler::VisitNEONLoadStoreSingleStruct(const Instruction *instr) {
break;
case NEON_LD4R:
mnemonic = "ld4r";
form = "{'Vt.%1$s, 'Vt2.%1$s, 'Vt3.%1$s, 'Vt4.%1$s}, ['Xns]";
form = "{'Vt.%s, 'Vt2.%s, 'Vt3.%s, 'Vt4.%s}, ['Xns]";
break;
default:
break;
Expand Down Expand Up @@ -3196,7 +3195,7 @@ void Disassembler::VisitNEONLoadStoreSingleStructPostIndex(
break;
case NEON_LD4R_post:
mnemonic = "ld4r";
form = "{'Vt.%1$s, 'Vt2.%1$s, 'Vt3.%1$s, 'Vt4.%1$s}, ['Xns], 'Xmz4";
form = "{'Vt.%s, 'Vt2.%s, 'Vt3.%s, 'Vt4.%s}, ['Xns], 'Xmz4";
break;
default:
break;
Expand Down
16 changes: 11 additions & 5 deletions src/aarch64/instructions-aarch64.h
Original file line number Diff line number Diff line change
Expand Up @@ -856,11 +856,13 @@ class NEONFormatDecoder {
// Set the format mapping for all or individual substitutions.
void SetFormatMaps(const NEONFormatMap* format0,
const NEONFormatMap* format1 = NULL,
const NEONFormatMap* format2 = NULL) {
const NEONFormatMap* format2 = NULL,
const NEONFormatMap* format3 = NULL) {
VIXL_ASSERT(format0 != NULL);
formats_[0] = format0;
formats_[1] = (format1 == NULL) ? formats_[0] : format1;
formats_[2] = (format2 == NULL) ? formats_[1] : format2;
formats_[3] = (format3 == NULL) ? formats_[2] : format3;
}
void SetFormatMap(unsigned index, const NEONFormatMap* format) {
VIXL_ASSERT(index <= ArrayLength(formats_));
Expand All @@ -879,12 +881,15 @@ class NEONFormatDecoder {
const char* Substitute(const char* string,
SubstitutionMode mode0 = kFormat,
SubstitutionMode mode1 = kFormat,
SubstitutionMode mode2 = kFormat) {
SubstitutionMode mode2 = kFormat,
SubstitutionMode mode3 = kFormat) {
const char* subst0 = GetSubstitute(0, mode0);
const char* subst1 = GetSubstitute(1, mode1);
const char* subst2 = GetSubstitute(2, mode2);
const char* subst3 = GetSubstitute(3, mode3);

if ((subst0 == NULL) || (subst1 == NULL) || (subst2 == NULL)) {
if ((subst0 == NULL) || (subst1 == NULL) || (subst2 == NULL) ||
(subst3 == NULL)) {
return NULL;
}

Expand All @@ -893,7 +898,8 @@ class NEONFormatDecoder {
string,
subst0,
subst1,
subst2);
subst2,
subst3);
return form_buffer_;
}

Expand Down Expand Up @@ -1131,7 +1137,7 @@ class NEONFormatDecoder {
}

Instr instrbits_;
const NEONFormatMap* formats_[3];
const NEONFormatMap* formats_[4];
char form_buffer_[64];
char mne_buffer_[16];
};
Expand Down

0 comments on commit a331691

Please sign in to comment.