From 1e7883a659bd332879512de5da0d018fa2189f02 Mon Sep 17 00:00:00 2001 From: mmc28a <78873583+mmc28a@users.noreply.github.com> Date: Wed, 29 Jan 2025 17:45:49 +0000 Subject: [PATCH] Remove printf positional argument requirements from disassembler (#125) 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 https://github.com/Linaro/vixl/pull/122 --- src/aarch64/disasm-aarch64.cc | 21 ++++++++++----------- src/aarch64/instructions-aarch64.h | 16 +++++++++++----- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/aarch64/disasm-aarch64.cc b/src/aarch64/disasm-aarch64.cc index 7e1ab465..5bcee747 100644 --- a/src/aarch64/disasm-aarch64.cc +++ b/src/aarch64/disasm-aarch64.cc @@ -2733,10 +2733,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)) { @@ -2831,11 +2831,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)) { @@ -3038,7 +3037,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; @@ -3198,7 +3197,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; diff --git a/src/aarch64/instructions-aarch64.h b/src/aarch64/instructions-aarch64.h index ad0ba582..00aeb3cf 100644 --- a/src/aarch64/instructions-aarch64.h +++ b/src/aarch64/instructions-aarch64.h @@ -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_)); @@ -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; } @@ -893,7 +898,8 @@ class NEONFormatDecoder { string, subst0, subst1, - subst2); + subst2, + subst3); return form_buffer_; } @@ -1131,7 +1137,7 @@ class NEONFormatDecoder { } Instr instrbits_; - const NEONFormatMap* formats_[3]; + const NEONFormatMap* formats_[4]; char form_buffer_[64]; char mne_buffer_[16]; };