From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1726) id 38C81385843E; Fri, 8 Jul 2022 12:15:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 38C81385843E Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Andrew Burgess To: bfd-cvs@sourceware.org Subject: [binutils-gdb] libopcodes/s390: add support for disassembler styling X-Act-Checkin: binutils-gdb X-Git-Author: Andrew Burgess X-Git-Refname: refs/heads/master X-Git-Oldrev: 5bbe6ec5b155886cab036f15ec65ca1476c3bee2 X-Git-Newrev: ec54dc915f42fa6f0da9902c333623f71d7aa5a3 Message-Id: <20220708121523.38C81385843E@sourceware.org> Date: Fri, 8 Jul 2022 12:15:23 +0000 (GMT) X-BeenThere: binutils-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 08 Jul 2022 12:15:23 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Dec54dc915f42= fa6f0da9902c333623f71d7aa5a3 commit ec54dc915f42fa6f0da9902c333623f71d7aa5a3 Author: Andrew Burgess Date: Tue Jul 5 14:17:14 2022 +0100 libopcodes/s390: add support for disassembler styling =20 This commit adds disassembler style to the libopcodes s390 disassembler. This conversion was pretty straight forward, I just converted the fprintf_func calls to fprintf_styled_func calls and added an appropriate style. =20 For testing the new styling I just assembled then disassembled the source files in gas/testsuite/gas/s390 and manually checked that the styling looked reasonable. =20 If the user does not request styled output from objdump, then there should be no change in the disassembler output after this commit. Diff: --- opcodes/disassemble.c | 1 + opcodes/s390-dis.c | 87 +++++++++++++++++++++++++++++++++++++++++------= ---- 2 files changed, 72 insertions(+), 16 deletions(-) diff --git a/opcodes/disassemble.c b/opcodes/disassemble.c index 9c0dacaf391..bd37f042b31 100644 --- a/opcodes/disassemble.c +++ b/opcodes/disassemble.c @@ -721,6 +721,7 @@ disassemble_init_for_target (struct disassemble_info * = info) #ifdef ARCH_s390 case bfd_arch_s390: disassemble_init_s390 (info); + info->created_styled_output =3D true; break; #endif #ifdef ARCH_nds32 diff --git a/opcodes/s390-dis.c b/opcodes/s390-dis.c index 03715ed5f0b..df44efb95ab 100644 --- a/opcodes/s390-dis.c +++ b/opcodes/s390-dis.c @@ -186,7 +186,8 @@ s390_print_insn_with_opcode (bfd_vma memaddr, char separator; =20 /* Mnemonic. */ - info->fprintf_func (info->stream, "%s", opcode->name); + info->fprintf_styled_func (info->stream, dis_style_mnemonic, + "%s", opcode->name); =20 /* Operands. */ separator =3D '\t'; @@ -222,24 +223,60 @@ s390_print_insn_with_opcode (bfd_vma memaddr, } =20 if (flags & S390_OPERAND_GPR) - info->fprintf_func (info->stream, "%c%%r%u", separator, val.u); + { + info->fprintf_styled_func (info->stream, dis_style_text, + "%c", separator); + info->fprintf_styled_func (info->stream, dis_style_register, + "%%r%u", val.u); + } else if (flags & S390_OPERAND_FPR) - info->fprintf_func (info->stream, "%c%%f%u", separator, val.u); + { + info->fprintf_styled_func (info->stream, dis_style_text, + "%c", separator); + info->fprintf_styled_func (info->stream, dis_style_register, + "%%f%u", val.u); + } else if (flags & S390_OPERAND_VR) - info->fprintf_func (info->stream, "%c%%v%i", separator, val.u); + { + info->fprintf_styled_func (info->stream, dis_style_text, + "%c", separator); + info->fprintf_styled_func (info->stream, dis_style_register, + "%%v%i", val.u); + } else if (flags & S390_OPERAND_AR) - info->fprintf_func (info->stream, "%c%%a%u", separator, val.u); + { + info->fprintf_styled_func (info->stream, dis_style_text, + "%c", separator); + info->fprintf_styled_func (info->stream, dis_style_register, + "%%a%u", val.u); + } else if (flags & S390_OPERAND_CR) - info->fprintf_func (info->stream, "%c%%c%u", separator, val.u); + { + info->fprintf_styled_func (info->stream, dis_style_text, + "%c", separator); + info->fprintf_styled_func (info->stream, dis_style_register, + "%%c%u", val.u); + } else if (flags & S390_OPERAND_PCREL) { - info->fprintf_func (info->stream, "%c", separator); + info->fprintf_styled_func (info->stream, dis_style_text, + "%c", separator); info->print_address_func (memaddr + val.i + val.i, info); } else if (flags & S390_OPERAND_SIGNED) - info->fprintf_func (info->stream, "%c%i", separator, val.i); + { + enum disassembler_style style; + + info->fprintf_styled_func (info->stream, dis_style_text, + "%c", separator); + style =3D ((flags & S390_OPERAND_DISP) + ? dis_style_address_offset : dis_style_immediate); + info->fprintf_styled_func (info->stream, style, "%i", val.i); + } else { + enum disassembler_style style; + if (flags & S390_OPERAND_OR1) val.u &=3D ~1; if (flags & S390_OPERAND_OR2) @@ -251,14 +288,18 @@ s390_print_insn_with_opcode (bfd_vma memaddr, && val.u =3D=3D 0 && opindex[1] =3D=3D 0) break; - info->fprintf_func (info->stream, "%c%u", separator, val.u); + info->fprintf_styled_func (info->stream, dis_style_text, + "%c", separator); + style =3D ((flags & S390_OPERAND_DISP) + ? dis_style_address_offset : dis_style_immediate); + info->fprintf_styled_func (info->stream, style, "%u", val.u); } =20 if (flags & S390_OPERAND_DISP) separator =3D '('; else if (flags & S390_OPERAND_BASE) { - info->fprintf_func (info->stream, ")"); + info->fprintf_styled_func (info->stream, dis_style_text, ")"); separator =3D ','; } else @@ -361,19 +402,33 @@ print_insn_s390 (bfd_vma memaddr, struct disassemble_= info *info) value =3D (value << 8) + (unsigned int) buffer[1]; value =3D (value << 8) + (unsigned int) buffer[2]; value =3D (value << 8) + (unsigned int) buffer[3]; - info->fprintf_func (info->stream, ".long\t0x%08x", value); + info->fprintf_styled_func (info->stream, dis_style_assembler_directi= ve, + ".long"); + info->fprintf_styled_func (info->stream, dis_style_text, + "\t"); + info->fprintf_styled_func (info->stream, dis_style_immediate, + "0x%08x", value); return 4; case 2: value =3D (unsigned int) buffer[0]; value =3D (value << 8) + (unsigned int) buffer[1]; - info->fprintf_func (info->stream, ".short\t0x%04x", value); + info->fprintf_styled_func (info->stream, dis_style_assembler_directi= ve, + ".short"); + info->fprintf_styled_func (info->stream, dis_style_text, + "\t"); + info->fprintf_styled_func (info->stream, dis_style_immediate, + "0x%04x", value); return 2; default: - info->fprintf_func (info->stream, ".byte\t0x%02x", - (unsigned int) buffer[0]); + info->fprintf_styled_func (info->stream, dis_style_assembler_directi= ve, + ".byte"); + info->fprintf_styled_func (info->stream, dis_style_text, + "\t"); + info->fprintf_styled_func (info->stream, dis_style_immediate, + "0x%02x", (unsigned int) buffer[0]); for (i =3D 1; i < bytes_to_dump; i++) - info->fprintf_func (info->stream, ",0x%02x", - (unsigned int) buffer[i]); + info->fprintf_styled_func (info->stream, dis_style_immediate, + "0x%02x", (unsigned int) buffer[i]); return bytes_to_dump; } return 0;